LANCommander/LANCommander.Server/UI/Pages/Settings/Media.razor
2025-02-24 19:52:45 -06:00

84 lines
2.8 KiB
Text

@page "/Settings/Media"
@using LANCommander.SDK.Enums
@inject StorageLocationService StorageLocationService
@inject IMessageService MessageService
@inject ILogger<Media> Logger
@attribute [Authorize(Roles = RoleService.AdministratorRoleName)]
<PageHeader Title="Media" />
<PageContent>
<Form Model="Settings" Layout="@FormLayout.Vertical">
<FormItem Label="Storage Path">
<FilePicker Root="@RootPath" EntrySelectable="x => x is FileManagerDirectory" @bind-Value="@StorageLocation.Path" OkText="Select Path" Title="Choose Path" OnSelected="OnPathSelected" />
</FormItem>
<FormItem Label="Max Size (MB)">
<AntDesign.InputNumber @bind-Value="context.Media.MaxSize" Min="1" DefaultValue="25" />
</FormItem>
<Divider Text="SteamGridDB Credentials" />
<Text Type="@TextElementType.Secondary">In order to automatically search SteamGridDB for media, you need an API key. <a href="https://www.steamgriddb.com/profile/preferences/api" target="_blank">Click here</a> to get your key.</Text>
<FormItem Label="API Key">
<InputPassword @bind-Value="context.Media.SteamGridDbApiKey" />
</FormItem>
<FormItem>
<Button OnClick="Save" Type="@ButtonType.Primary">Save</Button>
</FormItem>
</Form>
</PageContent>
@code {
Settings Settings = SettingService.GetSettings();
string RootPath = Path.GetPathRoot(Directory.GetCurrentDirectory());
StorageLocation StorageLocation = new();
protected override async Task OnInitializedAsync()
{
StorageLocation = await StorageLocationService.FirstOrDefaultAsync(l => l.Default && l.Type == SDK.Enums.StorageLocationType.Media);
if (StorageLocation == null)
{
StorageLocation = new StorageLocation
{
Default = true,
Path = "Media",
Type = StorageLocationType.Media
};
StorageLocation = await StorageLocationService.AddAsync(StorageLocation);
}
}
async Task Save()
{
try
{
SettingService.SaveSettings(Settings);
await StorageLocationService.UpdateAsync(StorageLocation);
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);
StorageLocation.Path = path;
}
}