2023-11-03 01:49:43 -05:00
@page "/Settings/Media"
2025-02-12 21:15:25 -06:00
@using LANCommander.SDK.Enums
2025-02-01 02:21:34 -06:00
@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
2024-10-16 02:06:02 -05:00
@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">
2024-10-11 01:09:12 -05:00
<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 {
2024-11-22 02:04:04 -06:00
Settings Settings = SettingService.GetSettings();
2023-11-03 01:49:43 -05:00
string RootPath = Path.GetPathRoot(Directory.GetCurrentDirectory());
2025-02-12 21:15:25 -06:00
StorageLocation StorageLocation = new();
2024-10-11 01:09:12 -05:00
2023-11-03 01:49:43 -05:00
protected override async Task OnInitializedAsync()
{
2025-02-01 02:21:34 -06:00
StorageLocation = await StorageLocationService.FirstOrDefaultAsync(l => l.Default && l.Type == SDK.Enums.StorageLocationType.Media);
2025-02-12 21:15:25 -06:00
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
}
2025-02-24 19:52:45 -06:00
async Task Save()
2023-11-03 01:49:43 -05:00
{
try
{
SettingService.SaveSettings(Settings);
2025-02-24 19:52:45 -06:00
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);
2024-10-11 01:09:12 -05:00
StorageLocation.Path = path;
2023-11-03 01:49:43 -05:00
}
}