Skip to content

Commit

Permalink
Refactor hierarchy model classes and update file whitelist
Browse files Browse the repository at this point in the history
Refactored hierarchy model classes in Gml.Web.Panel including new FileNode and FolderNode classes. Enhanced functionality to handle file whitelist including adding and removing files. Simplified README.md instructions for Gml Web API setup, included changes in Docker usage instructions. Updated other related files and methods as per the changes.
  • Loading branch information
GamerVII-NET committed Jan 9, 2024
1 parent ebcf71e commit ffec1f9
Show file tree
Hide file tree
Showing 15 changed files with 213 additions and 111 deletions.
72 changes: 18 additions & 54 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,60 +1,24 @@
1. First, download the image:
```
docker pull ghcr.io/gamervii-net/gml-web-api:master
```
# Setup and Configuration of the Gml Web APi

2. Check that the image has been downloaded:
```
docker images
```
### Step 1: Cloning the Repository
Run the following command in your terminal:
```
git clone --recursive https://github.com/GamerVII-NET/gml-web-api.git
```

3. Configure the image:
```
docker exec -it CONTAINER_ID bash
```
### Step 2: Navigating into the project directory
Run the following command in your terminal:
```
cd gml-web-api
```

4. Run the service:
```
docker run -p 5000:8080 ghcr.io/gamervii-net/gml-web-api:master
```
### Step 3: Running the Project Using Docker
Run the following command in your terminal:
```
docker-compose up
```

5. Confirm that the server is running:
```
info: Microsoft.Hosting.Lifetime[14]
Now listening on: http://[::]:8080
...
```
After executing the command, Docker will download the necessary images and start the project. Once the project is running, you can open it in a browser using the returned address.

6. Enter the Docker OS, replacing CONTAINER_ID in the command:
```
docker exec -it CONTAINER_ID bash
```

7. Install the necessary components:
```
apt-get update && apt-get install wget unzip curl nano -y
```
8. Change the project name:
```
nano /app/appsettings.json
```
Press CTRL+X, then Y, and Enter.
9. Restart the Docker container:
```
docker restart CONTAINER_ID
```
# Installing the client from an external file
1. Create a profile.
2. Enter the Docker OS, replacing CONTAINER_ID in the command:
```
docker exec -it CONTAINER_ID bash
cd /root/PROJECT_NAME/clients/
wget LINK_TO_ZIP_FILE
unzip Client.zip
rm -Rf Client.zip
```
Please note that you should have Docker installed and running on your computer to execute this command.
14 changes: 6 additions & 8 deletions gml-web-api.sln
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "common", "common", "{A2E6D9
.editorconfig = .editorconfig
.gitignore = .gitignore
docker-compose.yml = docker-compose.yml
Dockerfile = Dockerfile
.dockerignore = .dockerignore
EndProjectSection
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GmlCore", "src\gml-core\src\GmlCore\GmlCore.csproj", "{9F0244C3-F499-4572-964D-ED30F0E4AC03}"
Expand All @@ -36,7 +34,7 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Gml.Web.Client", "src\Gml.W
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Gml.Client", "src\Gml.Client\src\Gml.Client\Gml.Client.csproj", "{10627438-8319-4083-A98E-6ABE228FBAC5}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GmlAdminPanel", "src\Gml.Web.Panel\GmlAdminPanel.csproj", "{2BF3C6A4-3B5B-4AFC-A604-57077A385AAE}"
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GmlAdminPanel", "src\Gml.Web.Panel\GmlAdminPanel.csproj", "{D6AF584D-D3FD-4CE3-B20C-FB86BD5C7BD4}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand Down Expand Up @@ -80,10 +78,10 @@ Global
{10627438-8319-4083-A98E-6ABE228FBAC5}.Debug|Any CPU.Build.0 = Debug|Any CPU
{10627438-8319-4083-A98E-6ABE228FBAC5}.Release|Any CPU.ActiveCfg = Release|Any CPU
{10627438-8319-4083-A98E-6ABE228FBAC5}.Release|Any CPU.Build.0 = Release|Any CPU
{2BF3C6A4-3B5B-4AFC-A604-57077A385AAE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{2BF3C6A4-3B5B-4AFC-A604-57077A385AAE}.Debug|Any CPU.Build.0 = Debug|Any CPU
{2BF3C6A4-3B5B-4AFC-A604-57077A385AAE}.Release|Any CPU.ActiveCfg = Release|Any CPU
{2BF3C6A4-3B5B-4AFC-A604-57077A385AAE}.Release|Any CPU.Build.0 = Release|Any CPU
{D6AF584D-D3FD-4CE3-B20C-FB86BD5C7BD4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{D6AF584D-D3FD-4CE3-B20C-FB86BD5C7BD4}.Debug|Any CPU.Build.0 = Debug|Any CPU
{D6AF584D-D3FD-4CE3-B20C-FB86BD5C7BD4}.Release|Any CPU.ActiveCfg = Release|Any CPU
{D6AF584D-D3FD-4CE3-B20C-FB86BD5C7BD4}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{58DD61F0-C4D8-4506-A643-3FFE2CC5B112} = {173407F0-6602-48A5-BF49-E288C6043FE3}
Expand All @@ -95,6 +93,6 @@ Global
{57F38D02-0B98-445D-AAC5-71147EF38F41} = {173407F0-6602-48A5-BF49-E288C6043FE3}
{8F2797AD-ECB7-4C5E-AE54-733EEB8B5D8E} = {173407F0-6602-48A5-BF49-E288C6043FE3}
{10627438-8319-4083-A98E-6ABE228FBAC5} = {173407F0-6602-48A5-BF49-E288C6043FE3}
{2BF3C6A4-3B5B-4AFC-A604-57077A385AAE} = {173407F0-6602-48A5-BF49-E288C6043FE3}
{D6AF584D-D3FD-4CE3-B20C-FB86BD5C7BD4} = {173407F0-6602-48A5-BF49-E288C6043FE3}
EndGlobalSection
EndGlobal
4 changes: 2 additions & 2 deletions src/Gml.Common/Gml.Common/SystemHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@

namespace Gml.Common
{
public class SystemHelper
public static class SystemHelper
{
public static string CalculateFileHash(string filePath, HashAlgorithm algorithm)
{
using var fileStream = File.OpenRead(filePath);
var hashBytes = algorithm.ComputeHash(fileStream);

return BitConverter.ToString(hashBytes).Replace("-", "").ToLower();
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/Gml.Web.Panel/Components/Layout/MainLayout.razor
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
<RadzenPanelMenu>
<RadzenPanelMenuItem Text="Home" Path="" Icon="home" />
<RadzenPanelMenuItem Text="Profiles">
<RadzenPanelMenuItem Text="Profiles" Path="profiles-list" Icon="reorder" Expanded="true" />
<RadzenPanelMenuItem Text="List" Path="profiles-list" Icon="reorder" Expanded="true" />
<RadzenPanelMenuItem Text="New profile" Path="profile-add" Icon="add_box" />
</RadzenPanelMenuItem>
</RadzenPanelMenu>
Expand Down
83 changes: 56 additions & 27 deletions src/Gml.Web.Panel/Components/Pages/ProfilesList.razor
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
@page "/profiles-list"
@using GmlAdminPanel.Models.Hierarchy

<PageTitle>ProfilesList</PageTitle>
<RadzenRow>
Expand All @@ -25,17 +26,29 @@
@if (SelectedProfiles?.Any() == true)
{
<RadzenCard>
<RadzenStack Orientation="Orientation.Horizontal" AlignItems="Radzen.AlignItems.Center" Gap="5">
<RadzenRow>
<RadzenColumn>
<RadzenStack Orientation="Orientation.Horizontal" AlignItems="Radzen.AlignItems.Center" Gap="5">

<RadzenStack Visible="ProfileInfo == null">

<RadzenStack Visible="ProfileInfo == null">
<div class="spinner-border spinner-border-sm" role="status">
<span class="visually-hidden">Загрузка...</span>
</div>
</RadzenStack>
<RadzenText Text="Profile"/>

<div class="spinner-border spinner-border-sm" role="status">
<span class="visually-hidden">Загрузка...</span>
</div>
</RadzenStack>
<RadzenText Text="Profile"/>
</RadzenStack>

</RadzenStack>
</RadzenColumn>
<RadzenColumn>
<RadzenStack Orientation="Orientation.Horizontal"
JustifyContent="JustifyContent.End"
AlignItems="AlignItems.End">
<RadzenButton Icon="refresh" Click="LoadAdditionalData" Size="ButtonSize.ExtraSmall" ButtonStyle="ButtonStyle.Dark"/>
</RadzenStack>
</RadzenColumn>
</RadzenRow>
<RadzenText Text="@SelectedProfiles[0].Name" TextStyle="Radzen.Blazor.TextStyle.DisplayH6" Style="margin-top: 8px"/>

<RadzenRow Style="margin-top: 10px" Visible="!(ProfileInfo == null)">
Expand Down Expand Up @@ -74,8 +87,6 @@
<RadzenButton Style="width: 100%;" Text="Remove profile" Click="@RemoveSelectedProfile" ButtonStyle="Radzen.ButtonStyle.Danger" Visible="(IsRemoving == false)" Icon="delete"/>
</RadzenColumn>
</RadzenRow>
<RadzenRow>
</RadzenRow>

</RadzenCard>
}
Expand All @@ -95,27 +106,45 @@

</RadzenStack>

<RadzenRow class="mt-3">
<RadzenRow class="mt-3" Visible="!(ProfileInfo == null)">
<RadzenColumn>
@* <RadzenDataGrid TItem="Models.GmlApi.File" *@
@* Data="@ProfileInfo?.Files" Visible="!(ProfileInfo == null)" *@
@* AllowPaging="true" *@
@* AllowFiltering="true" *@
@* PageSize="10"> *@
@* <Columns> *@
@* <RadzenDataGridColumn TItem="Models.GmlApi.File" Property="Directory" Title="Downloading files"/> *@
@* <RadzenDataGridColumn TItem="Models.GmlApi.File" Property="Size" Title="Size"/> *@
@* </Columns> *@
@* </RadzenDataGrid> *@

<RadzenTree Data=@entries Expand=@LoadFiles Style="width: 100%; height: 300px">
<RadzenTreeLevel Text=@GetTextForNode Template=@FileOrFolderTemplate/>
</RadzenTree>
<RadzenDataGrid @ref="grid"
AllowFiltering="true"
AllowSorting="true"
AllowColumnResize="true"
Data="@Directories"
TItem="GmlAdminPanel.Models.Hierarchy.Node"
RowRender="@RowRender"
LoadChildData="@LoadChildData"
RowCollapse="@(args => grid.ColumnsCollection.ToList().ForEach(c => c.ClearFilters()))">
<Columns>
<RadzenDataGridColumn TItem="GmlAdminPanel.Models.Hierarchy.Node" Property="Name" Title="File"/>
<RadzenDataGridColumn TItem="GmlAdminPanel.Models.Hierarchy.Node" Title="Action" Frozen="true" Sortable="false" Filterable="false" Width="300px">
<Template Context="file">
<RadzenButton ButtonStyle="ButtonStyle.Light"
Visible="(file is FileNode fileNode && string.IsNullOrEmpty(fileNode.CurrentFile.Hash) == false && ProfileInfo.WhiteListFiles.All(c => c.Name != file.Name))"
Click="@(eventArgs => AddFileToWhiteList((file as FileNode)?.CurrentFile))"
Size="ButtonSize.Small"
Text="Add to whitelist">
</RadzenButton>
</Template>
</RadzenDataGridColumn>
</Columns>
</RadzenDataGrid>
</RadzenColumn>
<RadzenColumn>
<RadzenDataGrid TItem="string" Data="@ProfileInfo?.WhiteListFiles" Visible="!(ProfileInfo == null)">
<RadzenDataGrid TItem="GmlAdminPanel.Models.GmlApi.File" Data="@ProfileInfo?.WhiteListFiles">
<Columns>
<RadzenDataGridColumn TItem="string" Property="." Title="Not check files"/>
<RadzenDataGridColumn TItem="GmlAdminPanel.Models.GmlApi.File" Property="Name" Title="Not check files"/>
<RadzenDataGridColumn TItem="GmlAdminPanel.Models.GmlApi.File" Title="Action" Frozen="true" Sortable="false" Filterable="false" Width="300px">
<Template Context="file">
<RadzenButton ButtonStyle="ButtonStyle.Danger"
Click="@(eventArgs => RemoveFileFromWhiteList(file))"
Size="ButtonSize.Small"
Text="Remove from whitelist">
</RadzenButton>
</Template>
</RadzenDataGridColumn>
</Columns>
</RadzenDataGrid>
<RadzenText Text="Files in this list will not be forcibly updated on the client side" class="mt-3" TextStyle="Radzen.Blazor.TextStyle.Caption"/>
Expand Down
2 changes: 1 addition & 1 deletion src/Gml.Web.Panel/Components/Pages/ProfilesList.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -285,4 +285,4 @@ public class FileDataItem
public bool IsDirectory { get; set; }
public List<FileItem> Children { get; set; } = new List<FileItem>();
}
}
}
8 changes: 8 additions & 0 deletions src/Gml.Web.Panel/Models/GmlApi/FileWhiteListDto.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
namespace GmlAdminPanel.Models.GmlApi;


public class FileWhiteListDto
{
public string ClientName { get; set; }
public string FileHash { get; set; }
}
2 changes: 1 addition & 1 deletion src/Gml.Web.Panel/Models/GmlApi/GetProfileInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,6 @@ public partial class GetProfileInfo
public IEnumerable<File> Files { get; set; }

[JsonPropertyName("whiteListFiles")]
public IEnumerable<string> WhiteListFiles { get; set; }
public IEnumerable<File> WhiteListFiles { get; set; }
}
}
2 changes: 1 addition & 1 deletion src/Gml.Web.Panel/Models/GmlApi/ProfileCreateInfoDto.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ public class ProfileCreateInfoDto
public string ClientName { get; set; }
public int SizeX { get; set; }
public int SizeY { get; set; }
public string? GameAddress { get; set; }
public string GameAddress { get; set; }
public int GamePort { get; set; }
public bool IsFullScreen { get; set; }
public int RamSize { get; set; }
Expand Down
35 changes: 23 additions & 12 deletions src/Gml.Web.Panel/Models/Hierarchy/Files.cs
Original file line number Diff line number Diff line change
@@ -1,22 +1,33 @@
namespace Gml.AdminPanel.Models.Hierarchy;

public class File
public class FileNode : Node
{
public string Name { get; set; }
public string Directory { get; set; }
public long Size { get; set; }
public string Hash { get; set; }
public GmlApi.File CurrentFile { get; set; }
}

public class Folder
public class FolderNode : Node
{
public string Name { get; set; }
public List<Folder> Subfolders { get; set; }
public List<File> Files { get; set; }

}

public class Root
public class Node
{
public List<File> Files { get; set; }
public List<Folder> Folders { get; set; }
public string Name { get; set; }
public string Directory { get; set; }
public long Size { get; set; }
public string Hash { get; set; }
public Node Parent { get; set; }
public List<FileNode> Files { get; set; }
public List<FolderNode> Folders { get; set; }

public string GetHierarchyPath(Node node)
{
if (node == null)
return string.Empty;

if (node.Parent == null)
return node.Directory;

return string.Concat(GetHierarchyPath(node.Parent), "\\", node.Directory);
}
}
38 changes: 38 additions & 0 deletions src/Gml.Web.Panel/Services/GmlApiService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
using Gml.AdminPanel.Models;
using Gml.AdminPanel.Models.GmlApi;
using Newtonsoft.Json;
using File = GmlAdminPanel.Models.GmlApi.File;

namespace Gml.AdminPanel
{
Expand Down Expand Up @@ -181,7 +182,44 @@ public async Task RemoveProfile(RemoveProfileDto removeProfileDto)
var response = await httpClient.SendAsync(request);

response.EnsureSuccessStatusCode();
}



public async Task<IEnumerable<File>> AddWhiteList(FileWhiteListDto fileWhiteListDto)
{
var uri = new Uri(httpClient.BaseAddress, $"api/file/whitelist");

var request = new HttpRequestMessage(HttpMethod.Post, uri);
request.Content = new StringContent(JsonConvert.SerializeObject(fileWhiteListDto), Encoding.UTF8, "application/json");

await AuthorizeRequest(request);

var response = await httpClient.SendAsync(request);

response.EnsureSuccessStatusCode();

var content = await response.Content.ReadAsStringAsync();

return JsonConvert.DeserializeObject<List<File>>(content);
}

public async Task<IEnumerable<File>> RemoveWhiteList(FileWhiteListDto fileWhiteListDto)
{
var uri = new Uri(httpClient.BaseAddress, $"api/file/whitelist");

var request = new HttpRequestMessage(HttpMethod.Delete, uri);
request.Content = new StringContent(JsonConvert.SerializeObject(fileWhiteListDto), Encoding.UTF8, "application/json");

await AuthorizeRequest(request);

var response = await httpClient.SendAsync(request);

response.EnsureSuccessStatusCode();

var content = await response.Content.ReadAsStringAsync();

return JsonConvert.DeserializeObject<List<File>>(content);
}


Expand Down
Loading

0 comments on commit ffec1f9

Please sign in to comment.