LANCommander/LANCommander.Server/UI/Pages/Settings/Media.razor

85 lines
2.8 KiB
Text
Raw Permalink Normal View History

2023-11-03 01:49:43 -05:00
@page "/Settings/Media"
@using LANCommander.SDK.Enums
@inject StorageLocationService StorageLocationService
2023-11-03 01:49:43 -05:00
@inject IMessageService MessageService
2024-07-07 16:33:46 -05:00
@inject ILogger<Media> Logger
@attribute [Authorize(Roles = RoleService.AdministratorRoleName)]
2023-11-03 01:49:43 -05:00
<PageHeader Title="Media" />
2025-02-04 19:32:33 -06:00
<PageContent>
2023-11-03 01:49:43 -05:00
<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" />
2023-11-03 01:49:43 -05:00
</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>
2025-02-04 19:32:33 -06:00
</PageContent>
2023-11-03 01:49:43 -05:00
@code {
Settings Settings = SettingService.GetSettings();
2023-11-03 01:49:43 -05:00
string RootPath = Path.GetPathRoot(Directory.GetCurrentDirectory());
StorageLocation StorageLocation = new();
2023-11-03 01:49:43 -05:00
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);
}
2023-11-03 01:49:43 -05:00
}
async Task Save()
2023-11-03 01:49:43 -05:00
{
try
{
SettingService.SaveSettings(Settings);
await StorageLocationService.UpdateAsync(StorageLocation);
2023-11-03 01:49:43 -05:00
MessageService.Success("Settings saved!");
}
2024-07-07 16:33:46 -05:00
catch (Exception ex)
2023-11-03 01:49:43 -05:00
{
MessageService.Error("An unknown error occurred.");
2024-07-07 16:33:46 -05:00
Logger.LogError(ex, "An unknown error occurred.");
2023-11-03 01:49:43 -05:00
}
}
2024-11-22 02:05:44 -06:00
void OnPathSelected(string path)
2023-11-03 01:49:43 -05:00
{
var appPath = Directory.GetCurrentDirectory();
if (path != null && path.StartsWith(appPath))
path = path.Substring(appPath.Length).TrimStart(Path.DirectorySeparatorChar).TrimEnd(Path.DirectorySeparatorChar);
StorageLocation.Path = path;
2023-11-03 01:49:43 -05:00
}
}