Updated to latest moonlight and mooncore version. Done refactoring to async scheme and other changes. Recreated database migrations and cleaned models
This commit is contained in:
@@ -1,9 +1,7 @@
|
||||
using System.IdentityModel.Tokens.Jwt;
|
||||
using System.Security.Claims;
|
||||
using System.Text;
|
||||
using Microsoft.IdentityModel.Tokens;
|
||||
using MoonCore.Attributes;
|
||||
using MoonCore.Extended.Helpers;
|
||||
using MoonCore.Helpers;
|
||||
using MoonlightServers.ApiServer.Database.Entities;
|
||||
using MoonlightServers.DaemonShared.DaemonSide.Http.Responses.Statistics;
|
||||
@@ -41,7 +39,7 @@ public class NodeService
|
||||
return jwtSecurityTokenHandler.WriteToken(securityToken);
|
||||
}
|
||||
|
||||
public async Task<SystemStatusResponse> GetSystemStatus(Node node)
|
||||
public async Task<SystemStatusResponse> GetSystemStatusAsync(Node node)
|
||||
{
|
||||
using var apiClient = CreateApiClient(node);
|
||||
return await apiClient.GetJson<SystemStatusResponse>("api/system/status");
|
||||
@@ -49,13 +47,13 @@ public class NodeService
|
||||
|
||||
#region Statistics
|
||||
|
||||
public async Task<StatisticsResponse> GetStatistics(Node node)
|
||||
public async Task<StatisticsResponse> GetStatisticsAsync(Node node)
|
||||
{
|
||||
using var apiClient = CreateApiClient(node);
|
||||
return await apiClient.GetJson<StatisticsResponse>("api/statistics");
|
||||
}
|
||||
|
||||
public async Task<StatisticsDockerResponse> GetDockerStatistics(Node node)
|
||||
public async Task<StatisticsDockerResponse> GetDockerStatisticsAsync(Node node)
|
||||
{
|
||||
using var apiClient = CreateApiClient(node);
|
||||
return await apiClient.GetJson<StatisticsDockerResponse>("api/statistics/docker");
|
||||
|
||||
@@ -19,7 +19,7 @@ public class ServerAuthorizeService
|
||||
AuthorizationFilters = authorizationFilters.ToArray();
|
||||
}
|
||||
|
||||
public async Task<ServerAuthorizationResult> Authorize(
|
||||
public async Task<ServerAuthorizationResult> AuthorizeAsync(
|
||||
ClaimsPrincipal user,
|
||||
Server server,
|
||||
string permissionIdentifier,
|
||||
@@ -28,7 +28,7 @@ public class ServerAuthorizeService
|
||||
{
|
||||
foreach (var authorizationFilter in AuthorizationFilters)
|
||||
{
|
||||
var result = await authorizationFilter.Process(
|
||||
var result = await authorizationFilter.ProcessAsync(
|
||||
user,
|
||||
server,
|
||||
permissionIdentifier,
|
||||
|
||||
@@ -24,54 +24,54 @@ public class ServerFileSystemService
|
||||
ServerRepository = serverRepository;
|
||||
}
|
||||
|
||||
public async Task<ServerFileSystemResponse[]> List(Server server, string path)
|
||||
public async Task<ServerFileSystemResponse[]> ListAsync(Server server, string path)
|
||||
{
|
||||
using var apiClient = await GetApiClient(server);
|
||||
using var apiClient = await GetApiClientAsync(server);
|
||||
|
||||
return await apiClient.GetJson<ServerFileSystemResponse[]>(
|
||||
$"api/servers/{server.Id}/files/list?path={path}"
|
||||
);
|
||||
}
|
||||
|
||||
public async Task Move(Server server, string oldPath, string newPath)
|
||||
public async Task MoveAsync(Server server, string oldPath, string newPath)
|
||||
{
|
||||
using var apiClient = await GetApiClient(server);
|
||||
using var apiClient = await GetApiClientAsync(server);
|
||||
|
||||
await apiClient.Post(
|
||||
$"api/servers/{server.Id}/files/move?oldPath={oldPath}&newPath={newPath}"
|
||||
);
|
||||
}
|
||||
|
||||
public async Task Delete(Server server, string path)
|
||||
public async Task DeleteAsync(Server server, string path)
|
||||
{
|
||||
using var apiClient = await GetApiClient(server);
|
||||
using var apiClient = await GetApiClientAsync(server);
|
||||
|
||||
await apiClient.Delete(
|
||||
$"api/servers/{server.Id}/files/delete?path={path}"
|
||||
);
|
||||
}
|
||||
|
||||
public async Task Mkdir(Server server, string path)
|
||||
public async Task MkdirAsync(Server server, string path)
|
||||
{
|
||||
using var apiClient = await GetApiClient(server);
|
||||
using var apiClient = await GetApiClientAsync(server);
|
||||
|
||||
await apiClient.Post(
|
||||
$"api/servers/{server.Id}/files/mkdir?path={path}"
|
||||
);
|
||||
}
|
||||
|
||||
public async Task Touch(Server server, string path)
|
||||
public async Task TouchAsync(Server server, string path)
|
||||
{
|
||||
using var apiClient = await GetApiClient(server);
|
||||
using var apiClient = await GetApiClientAsync(server);
|
||||
|
||||
await apiClient.Post(
|
||||
$"api/servers/{server.Id}/files/touch?path={path}"
|
||||
);
|
||||
}
|
||||
|
||||
public async Task Compress(Server server, CompressType type, string[] items, string destination)
|
||||
public async Task CompressAsync(Server server, CompressType type, string[] items, string destination)
|
||||
{
|
||||
using var apiClient = await GetApiClient(server);
|
||||
using var apiClient = await GetApiClientAsync(server);
|
||||
|
||||
await apiClient.Post(
|
||||
$"api/servers/{server.Id}/files/compress",
|
||||
@@ -84,9 +84,9 @@ public class ServerFileSystemService
|
||||
);
|
||||
}
|
||||
|
||||
public async Task Decompress(Server server, CompressType type, string path, string destination)
|
||||
public async Task DecompressAsync(Server server, CompressType type, string path, string destination)
|
||||
{
|
||||
using var apiClient = await GetApiClient(server);
|
||||
using var apiClient = await GetApiClientAsync(server);
|
||||
|
||||
await apiClient.Post(
|
||||
$"api/servers/{server.Id}/files/decompress",
|
||||
@@ -101,7 +101,7 @@ public class ServerFileSystemService
|
||||
|
||||
#region Helpers
|
||||
|
||||
private async Task<HttpApiClient> GetApiClient(Server server)
|
||||
private async Task<HttpApiClient> GetApiClientAsync(Server server)
|
||||
{
|
||||
var serverWithNode = server;
|
||||
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
using System.Text.Json;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using MoonCore.Attributes;
|
||||
using MoonCore.Exceptions;
|
||||
@@ -25,11 +24,11 @@ public class ServerService
|
||||
|
||||
#region Power Actions
|
||||
|
||||
public async Task Start(Server server)
|
||||
public async Task StartAsync(Server server)
|
||||
{
|
||||
try
|
||||
{
|
||||
using var apiClient = await GetApiClient(server);
|
||||
using var apiClient = await GetApiClientAsync(server);
|
||||
await apiClient.Post($"api/servers/{server.Id}/start");
|
||||
}
|
||||
catch (HttpRequestException e)
|
||||
@@ -38,11 +37,11 @@ public class ServerService
|
||||
}
|
||||
}
|
||||
|
||||
public async Task Stop(Server server)
|
||||
public async Task StopAsync(Server server)
|
||||
{
|
||||
try
|
||||
{
|
||||
using var apiClient = await GetApiClient(server);
|
||||
using var apiClient = await GetApiClientAsync(server);
|
||||
await apiClient.Post($"api/servers/{server.Id}/stop");
|
||||
}
|
||||
catch (HttpRequestException e)
|
||||
@@ -51,11 +50,11 @@ public class ServerService
|
||||
}
|
||||
}
|
||||
|
||||
public async Task Kill(Server server)
|
||||
public async Task KillAsync(Server server)
|
||||
{
|
||||
try
|
||||
{
|
||||
using var apiClient = await GetApiClient(server);
|
||||
using var apiClient = await GetApiClientAsync(server);
|
||||
await apiClient.Post($"api/servers/{server.Id}/kill");
|
||||
}
|
||||
catch (HttpRequestException e)
|
||||
@@ -66,11 +65,11 @@ public class ServerService
|
||||
|
||||
#endregion
|
||||
|
||||
public async Task Install(Server server)
|
||||
public async Task InstallAsync(Server server)
|
||||
{
|
||||
try
|
||||
{
|
||||
using var apiClient = await GetApiClient(server);
|
||||
using var apiClient = await GetApiClientAsync(server);
|
||||
await apiClient.Post($"api/servers/{server.Id}/install");
|
||||
}
|
||||
catch (HttpRequestException e)
|
||||
@@ -79,11 +78,11 @@ public class ServerService
|
||||
}
|
||||
}
|
||||
|
||||
public async Task Sync(Server server)
|
||||
public async Task SyncAsync(Server server)
|
||||
{
|
||||
try
|
||||
{
|
||||
using var apiClient = await GetApiClient(server);
|
||||
using var apiClient = await GetApiClientAsync(server);
|
||||
await apiClient.Post($"api/servers/{server.Id}/sync");
|
||||
}
|
||||
catch (HttpRequestException e)
|
||||
@@ -92,11 +91,11 @@ public class ServerService
|
||||
}
|
||||
}
|
||||
|
||||
public async Task SyncDelete(Server server)
|
||||
public async Task SyncDeleteAsync(Server server)
|
||||
{
|
||||
try
|
||||
{
|
||||
using var apiClient = await GetApiClient(server);
|
||||
using var apiClient = await GetApiClientAsync(server);
|
||||
await apiClient.Delete($"api/servers/{server.Id}");
|
||||
}
|
||||
catch (HttpRequestException e)
|
||||
@@ -105,11 +104,11 @@ public class ServerService
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<ServerStatusResponse> GetStatus(Server server)
|
||||
public async Task<ServerStatusResponse> GetStatusAsync(Server server)
|
||||
{
|
||||
try
|
||||
{
|
||||
using var apiClient = await GetApiClient(server);
|
||||
using var apiClient = await GetApiClientAsync(server);
|
||||
return await apiClient.GetJson<ServerStatusResponse>($"api/servers/{server.Id}/status");
|
||||
}
|
||||
catch (HttpRequestException e)
|
||||
@@ -118,11 +117,11 @@ public class ServerService
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<ServerLogsResponse> GetLogs(Server server)
|
||||
public async Task<ServerLogsResponse> GetLogsAsync(Server server)
|
||||
{
|
||||
try
|
||||
{
|
||||
using var apiClient = await GetApiClient(server);
|
||||
using var apiClient = await GetApiClientAsync(server);
|
||||
return await apiClient.GetJson<ServerLogsResponse>($"api/servers/{server.Id}/logs");
|
||||
}
|
||||
catch (HttpRequestException e)
|
||||
@@ -131,11 +130,11 @@ public class ServerService
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<ServerStatsResponse> GetStats(Server server)
|
||||
public async Task<ServerStatsResponse> GetStatsAsync(Server server)
|
||||
{
|
||||
try
|
||||
{
|
||||
using var apiClient = await GetApiClient(server);
|
||||
using var apiClient = await GetApiClientAsync(server);
|
||||
return await apiClient.GetJson<ServerStatsResponse>($"api/servers/{server.Id}/stats");
|
||||
}
|
||||
catch (HttpRequestException)
|
||||
@@ -144,11 +143,11 @@ public class ServerService
|
||||
}
|
||||
}
|
||||
|
||||
public async Task RunCommand(Server server, string command)
|
||||
public async Task RunCommandAsync(Server server, string command)
|
||||
{
|
||||
try
|
||||
{
|
||||
using var apiClient = await GetApiClient(server);
|
||||
using var apiClient = await GetApiClientAsync(server);
|
||||
|
||||
await apiClient.Post(
|
||||
$"api/servers/{server.Id}/command",
|
||||
@@ -174,7 +173,7 @@ public class ServerService
|
||||
return PermissionHelper.HasPermission(user.Permissions, "admin.servers.get");
|
||||
}
|
||||
|
||||
private async Task<HttpApiClient> GetApiClient(Server server)
|
||||
private async Task<HttpApiClient> GetApiClientAsync(Server server)
|
||||
{
|
||||
var serverWithNode = server;
|
||||
|
||||
|
||||
@@ -23,7 +23,7 @@ public class StarImportExportService
|
||||
Logger = logger;
|
||||
}
|
||||
|
||||
public async Task<string> Export(int id)
|
||||
public async Task<string> ExportAsync(int id)
|
||||
{
|
||||
var star = StarRepository
|
||||
.Get()
|
||||
@@ -78,20 +78,20 @@ public class StarImportExportService
|
||||
return json;
|
||||
}
|
||||
|
||||
public async Task<Star> Import(string json)
|
||||
public async Task<Star> ImportAsync(string json)
|
||||
{
|
||||
// Determine which importer to use based on simple patterns
|
||||
if (json.Contains("RequiredAllocations"))
|
||||
return await ImportStar(json);
|
||||
return await ImportStarAsync(json);
|
||||
else if (json.Contains("AllocationsNeeded"))
|
||||
return await ImportImage(json);
|
||||
return await ImportImageAsync(json);
|
||||
else if (json.Contains("_comment"))
|
||||
return await ImportEgg(json);
|
||||
return await ImportEggAsync(json);
|
||||
else
|
||||
throw new HttpApiException("Unable to determine the format of the imported star/image/egg", 400);
|
||||
}
|
||||
|
||||
public async Task<Star> ImportStar(string json)
|
||||
public async Task<Star> ImportStarAsync(string json)
|
||||
{
|
||||
try
|
||||
{
|
||||
@@ -138,7 +138,7 @@ public class StarImportExportService
|
||||
}).ToList()
|
||||
};
|
||||
|
||||
var finalStar = await StarRepository.Add(star);
|
||||
var finalStar = await StarRepository.AddAsync(star);
|
||||
|
||||
return finalStar;
|
||||
}
|
||||
@@ -149,7 +149,7 @@ public class StarImportExportService
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<Star> ImportImage(string json)
|
||||
public async Task<Star> ImportImageAsync(string json)
|
||||
{
|
||||
try
|
||||
{
|
||||
@@ -235,7 +235,7 @@ public class StarImportExportService
|
||||
|
||||
#endregion
|
||||
|
||||
var finalStar = await StarRepository.Add(star);
|
||||
var finalStar = await StarRepository.AddAsync(star);
|
||||
|
||||
return finalStar;
|
||||
}
|
||||
@@ -246,7 +246,7 @@ public class StarImportExportService
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<Star> ImportEgg(string json)
|
||||
public async Task<Star> ImportEggAsync(string json)
|
||||
{
|
||||
// Create result
|
||||
var star = new Star();
|
||||
@@ -403,7 +403,7 @@ public class StarImportExportService
|
||||
star.AllowDockerImageChange = true;
|
||||
|
||||
// Finally save it to the db
|
||||
var finalStar = await StarRepository.Add(star);
|
||||
var finalStar = await StarRepository.AddAsync(star);
|
||||
|
||||
return finalStar;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user