Implemented statistics. Refactored storage abstractions. Added config options for docker and local storage. Added server service and server updating.

This commit is contained in:
2026-03-02 15:51:05 +00:00
parent 52dbd13fb5
commit 2d1b48b0d4
27 changed files with 493 additions and 147 deletions

View File

@@ -1,3 +1,4 @@
using MoonlightServers.Daemon.Configuration;
using MoonlightServers.Daemon.ServerSystem.Abstractions;
namespace MoonlightServers.Daemon.ServerSystem.Implementations.Local;
@@ -8,5 +9,7 @@ public static class Extensions
{
services.AddSingleton<IRuntimeStorageService, LocalRuntimeStorageService>();
services.AddSingleton<IInstallStorageService, LocalInstallStorageService>();
services.AddOptions<LocalStorageOptions>().BindConfiguration("Moonlight:LocalStorage");
}
}

View File

@@ -4,12 +4,12 @@ namespace MoonlightServers.Daemon.ServerSystem.Implementations.Local;
public class LocalInstallStorage : IInstallStorage
{
public string HostPath { get; }
public string BindPath { get; }
public LocalInstallStorage(string hostPath)
public LocalInstallStorage(string bindPath)
{
HostPath = hostPath;
BindPath = bindPath;
}
public Task<string> GetHostPathAsync() => Task.FromResult(HostPath);
public Task<string> GetBindPathAsync() => Task.FromResult(BindPath);
}

View File

@@ -1,3 +1,5 @@
using Microsoft.Extensions.Options;
using MoonlightServers.Daemon.Configuration;
using MoonlightServers.Daemon.Models;
using MoonlightServers.Daemon.ServerSystem.Abstractions;
@@ -5,11 +7,16 @@ namespace MoonlightServers.Daemon.ServerSystem.Implementations.Local;
public class LocalInstallStorageService : IInstallStorageService
{
private const string HostPathTemplate = "./mldaemon/install/{0}";
private readonly IOptions<LocalStorageOptions> Options;
public LocalInstallStorageService(IOptions<LocalStorageOptions> options)
{
Options = options;
}
public Task<IInstallStorage?> FindAsync(string id)
{
var path = string.Format(HostPathTemplate, id);
var path = Path.Combine(Options.Value.InstallPath, id);
if (!Directory.Exists(path))
return Task.FromResult<IInstallStorage?>(null);
@@ -19,7 +26,7 @@ public class LocalInstallStorageService : IInstallStorageService
public Task<IInstallStorage> CreateAsync(string id, RuntimeConfiguration runtimeConfiguration, InstallConfiguration installConfiguration)
{
var path = string.Format(HostPathTemplate, id);
var path = Path.Combine(Options.Value.InstallPath, id);
Directory.CreateDirectory(path);
@@ -35,8 +42,8 @@ public class LocalInstallStorageService : IInstallStorageService
);
}
if(Directory.Exists(localInstallStorage.HostPath))
Directory.Delete(localInstallStorage.HostPath, true);
if(Directory.Exists(localInstallStorage.BindPath))
Directory.Delete(localInstallStorage.BindPath, true);
return Task.CompletedTask;
}

View File

@@ -4,12 +4,12 @@ namespace MoonlightServers.Daemon.ServerSystem.Implementations.Local;
public class LocalRuntimeStorage : IRuntimeStorage
{
public string HostPath { get; }
public string BindPath { get; }
public LocalRuntimeStorage(string hostPath)
public LocalRuntimeStorage(string bindPath)
{
HostPath = hostPath;
BindPath = bindPath;
}
public Task<string> GetHostPathAsync() => Task.FromResult(HostPath);
public Task<string> GetBindPathAsync() => Task.FromResult(BindPath);
}

View File

@@ -1,3 +1,5 @@
using Microsoft.Extensions.Options;
using MoonlightServers.Daemon.Configuration;
using MoonlightServers.Daemon.Models;
using MoonlightServers.Daemon.ServerSystem.Abstractions;
@@ -5,11 +7,16 @@ namespace MoonlightServers.Daemon.ServerSystem.Implementations.Local;
public class LocalRuntimeStorageService : IRuntimeStorageService
{
private const string HostPathTemplate = "./mldaemon/runtime/{0}";
private readonly IOptions<LocalStorageOptions> Options;
public LocalRuntimeStorageService(IOptions<LocalStorageOptions> options)
{
Options = options;
}
public Task<IRuntimeStorage?> FindAsync(string id)
{
var path = string.Format(HostPathTemplate, id);
var path = Path.Combine(Options.Value.RuntimePath, id);
if (!Directory.Exists(path))
return Task.FromResult<IRuntimeStorage?>(null);
@@ -19,7 +26,7 @@ public class LocalRuntimeStorageService : IRuntimeStorageService
public Task<IRuntimeStorage> CreateAsync(string id, RuntimeConfiguration configuration)
{
var path = string.Format(HostPathTemplate, id);
var path = Path.Combine(Options.Value.RuntimePath, id);
Directory.CreateDirectory(path);
@@ -38,8 +45,8 @@ public class LocalRuntimeStorageService : IRuntimeStorageService
);
}
if(Directory.Exists(localRuntimeStorage.HostPath))
Directory.Delete(localRuntimeStorage.HostPath, true);
if(Directory.Exists(localRuntimeStorage.BindPath))
Directory.Delete(localRuntimeStorage.BindPath, true);
return Task.CompletedTask;
}