LANCommander/LANCommander.Server/UI/Pages/Settings/General.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

91 lines
3.2 KiB
Text

@page "/Settings"
@page "/Settings/General"
@using LANCommander.Server.Settings
@using LANCommander.Server.Settings.Enums
@using Microsoft.Extensions.Options
@inject IGDBService IGDBService
@inject IOptions<Settings> Settings
@inject SettingsProvider<Settings> SettingsProvider
@inject IMessageService MessageService
@inject ILogger<General> Logger
@attribute [Authorize(Roles = RoleService.AdministratorRoleName)]
<PageHeader Title="General" />
<PageContent>
<Form Model="Settings.Value" Layout="@FormLayout.Vertical">
<FormItem Label="Database Provider">
<Select @bind-Value="context.Server.Database.Provider" TItem="DatabaseProvider" TItemValue="DatabaseProvider" DataSource="Enum.GetValues<DatabaseProvider>()">
<LabelTemplate Context="Value">@Value.GetDisplayName()</LabelTemplate>
<ItemTemplate Context="Value">@Value.GetDisplayName()</ItemTemplate>
</Select>
</FormItem>
<FormItem Label="Database Connection String">
<InputPassword @bind-Value="context.Server.Database.ConnectionString" />
</FormItem>
<FormItem Label="Port">
<AntDesign.InputNumber @bind-Value="context.Server.Http.Port" />
</FormItem>
<Divider Text="IGDB Credentials" />
<Text Type="@TextElementType.Secondary">In order to use IGDB metadata, you need a Twitch developer account. <a href="https://api-docs.igdb.com/#account-creation" target="_blank">Click here</a> for more details.</Text>
<FormItem Label="Client ID">
<Input @bind-Value="context.Server.IGDB.ClientId" />
</FormItem>
<FormItem Label="Client Secret">
<InputPassword @bind-Value="context.Server.IGDB.ClientSecret" />
</FormItem>
<Divider Text="SSL" />
<FormItem Label="Use SSL">
<Switch @bind-Checked="context.Server.Http.UseSSL" />
</FormItem>
<FormItem Label="SSL Port">
<AntDesign.InputNumber @bind-Value="context.Server.Http.SSLPort" Disabled="!context.Server.Http.UseSSL" />
</FormItem>
<FormItem Label="Certificate Path">
<FilePicker Root="@RootPath" @bind-Value="context.Server.Http.CertificatePath" Disabled="!context.Server.Http.UseSSL" />
</FormItem>
<FormItem Label="Certificate Password">
<InputPassword @bind-Value="context.Server.Http.CertificatePassword" Disabled="!context.Server.Http.UseSSL" />
</FormItem>
<FormItem>
<Button OnClick="Save" Type="@ButtonType.Primary">Save</Button>
</FormItem>
</Form>
</PageContent>
@code {
string RootPath = Path.GetPathRoot(Directory.GetCurrentDirectory());
void Save()
{
try
{
SettingsProvider.Update(s =>
{
s.Server.Database = Settings.Value.Server.Database;
s.Server.Http = Settings.Value.Server.Http;
s.Server.IGDB = Settings.Value.Server.IGDB;
});
IGDBService.Authenticate();
MessageService.Success("Settings saved!");
}
catch (Exception ex)
{
MessageService.Error("An unknown error occurred.");
Logger.LogError(ex, "An unknown error occurred.");
}
}
}