@page "/Settings/Archives" @using LANCommander.Server.Settings @using Microsoft.Extensions.Options @inject StorageLocationService StorageLocationService @inject IOptions Settings @inject SettingsProvider SettingsProvider @inject IMessageService MessageService @inject ILogger Logger @attribute [Authorize(Roles = RoleService.AdministratorRoleName)]
@code { ICollection StorageLocations; string RootPath = Path.GetPathRoot(Directory.GetCurrentDirectory()); protected override async Task OnInitializedAsync() { StorageLocations = await StorageLocationService.GetAsync(l => l.Type == SDK.Enums.StorageLocationType.Archive); } async Task Save() { try { SettingsProvider.Update(s => { s.Server.Archives = Settings.Value.Server.Archives; }); foreach (var storageLocation in StorageLocations) { if (!StorageLocations.Any(l => l.Default)) storageLocation.Default = true; if (storageLocation.Id != Guid.Empty) await StorageLocationService.UpdateAsync(storageLocation); else await StorageLocationService.AddAsync(storageLocation); } MessageService.Success("Settings saved!"); } catch (Exception ex) { MessageService.Error("An unknown error occurred."); Logger.LogError(ex, "An unknown error occurred."); } } void OnPathSelected(StorageLocation storageLocation, 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; } async Task AddStorageLocation() { StorageLocations.Add(new StorageLocation()); StateHasChanged(); } async Task RemoveStorageLocation(StorageLocation storageLocation) { StorageLocations.Remove(storageLocation); } }