LANCommander/LANCommander.Server/UI/Pages/Settings/UserSaves.razor
Pat Hartl add770b227 Refactor Settings
Settings for the server are now combined with the settings from the SDK. This introduces a large breaking change and a migration should be created. This refactor utilizes .NET Configuration and the Options pattern. This will allow for the overriding of any setting using envionment variables. It also means that Settings.yml can be used to override any .NET configuration. A SettingsProvider implementation was created, and any updating of settings was changed from SettingsService.SaveSettings() to SettingsProvider.Update(s => { ... })
2025-11-16 12:31:25 -06:00

73 lines
2.4 KiB
Text

@page "/Settings/UserSaves"
@using LANCommander.SDK.Enums
@using LANCommander.Server.Settings
@using Microsoft.Extensions.Options
@inject StorageLocationService StorageLocationService
@inject IMessageService MessageService
@inject ILogger<UserSaves> Logger
@inject IOptions<Settings> Settings
@inject SettingsProvider<Settings> SettingsProvider
@attribute [Authorize(Roles = RoleService.AdministratorRoleName)]
<PageHeader Title="User Saves" />
<PageContent>
<Form Model="Settings.Value" Layout="@FormLayout.Vertical">
<FormItem Label="Storage Path">
<FilePicker Root="@RootPath" EntrySelectable="x => x is FileManagerDirectory" @bind-Value="@SaveStorageLocation.Path" OkText="Select Path" Title="Choose Path" OnSelected="OnPathSelected" />
</FormItem>
<FormItem Label="Max Size (MB)">
<AntDesign.InputNumber @bind-Value="context.Server.UserSaves.MaxSize" Min="1" DefaultValue="25" />
</FormItem>
<FormItem Label="Maximum Number of Saves">
<AntDesign.InputNumber @bind-Value="context.Server.UserSaves.MaxSaves" Min="0" DefaultValue="0" />
</FormItem>
<FormItem>
<Button OnClick="Save" Type="@ButtonType.Primary">Save</Button>
</FormItem>
</Form>
</PageContent>
@code {
string RootPath = Path.GetPathRoot(Directory.GetCurrentDirectory());
StorageLocation SaveStorageLocation = new();
protected override async Task OnInitializedAsync()
{
SaveStorageLocation = await StorageLocationService.FirstOrDefaultAsync(l => l.Default && l.Type == StorageLocationType.Save);
}
async Task Save()
{
try
{
SettingsProvider.Update(s =>
{
s.Server.UserSaves = Settings.Value.Server.UserSaves;
});
await StorageLocationService.UpdateAsync(SaveStorageLocation);
MessageService.Success("Settings saved!");
}
catch (Exception ex)
{
MessageService.Error("An unknown error occurred.");
Logger.LogError(ex, "An unknown error occurred.");
}
}
void OnPathSelected(string path)
{
var appPath = Directory.GetCurrentDirectory();
if (path != null && path.StartsWith(appPath))
path = path.Substring(appPath.Length).TrimStart(Path.DirectorySeparatorChar).TrimEnd(Path.DirectorySeparatorChar);
SaveStorageLocation.Path = path;
}
}