115 lines
4.3 KiB
Text
115 lines
4.3 KiB
Text
@page "/Settings/Archives"
|
|
@using LANCommander.Server.Settings
|
|
@using Microsoft.Extensions.Options
|
|
@inject StorageLocationService StorageLocationService
|
|
@inject IOptions<Settings> Settings
|
|
@inject SettingsProvider<Settings> SettingsProvider
|
|
@inject IMessageService MessageService
|
|
@inject ILogger<Archives> Logger
|
|
@attribute [Authorize(Roles = RoleService.AdministratorRoleName)]
|
|
|
|
<PageHeader Title="Archives" />
|
|
|
|
<PageContent>
|
|
<Form Model="Settings.Value" Layout="@FormLayout.Vertical">
|
|
<FormItem Label="Allow Insecure Downloads">
|
|
<Switch @bind-Checked="context.Server.Archives.AllowInsecureDownloads" />
|
|
</FormItem>
|
|
|
|
<FormItem Label="Max Upload Chunk Size (MB)">
|
|
<AntDesign.InputNumber @bind-Value="context.Server.Archives.MaxChunkSize" Min="1" DefaultValue="50" />
|
|
</FormItem>
|
|
|
|
<FormItem Label="Storage Paths">
|
|
<Flex Vertical Gap="FlexGap.Large">
|
|
<Table TItem="Data.Models.StorageLocation" DataSource="@StorageLocations" HidePagination="true" Responsive Context="storageLocation">
|
|
<PropertyColumn Property="l => l.Path">
|
|
<FilePicker @bind-Value="storageLocation.Path" AllowDirectories="true" Title="Select Storage Location" Root="@RootPath" OnSelected="(path) => OnPathSelected(storageLocation, path)"/>
|
|
</PropertyColumn>
|
|
<PropertyColumn Property="l => l.Default" Title="Default" Align="ColumnAlign.Right">
|
|
<Checkbox @bind-Checked="storageLocation.Default"/>
|
|
</PropertyColumn>
|
|
<ActionColumn>
|
|
<Space Style="display: flex; justify-content: end">
|
|
<SpaceItem>
|
|
<Popconfirm OnConfirm="() => RemoveStorageLocation(storageLocation)" Title="Are you sure you want to remove this storage location?">
|
|
<Button Icon="@IconType.Outline.Close" Type="@ButtonType.Text" Danger/>
|
|
</Popconfirm>
|
|
</SpaceItem>
|
|
</Space>
|
|
</ActionColumn>
|
|
</Table>
|
|
|
|
<Flex Justify="FlexJustify.End">
|
|
<Button OnClick="AddStorageLocation" Type="@ButtonType.Primary">Add Path</Button>
|
|
</Flex>
|
|
</Flex>
|
|
</FormItem>
|
|
|
|
<FormItem>
|
|
<Button OnClick="Save" Type="@ButtonType.Primary">Save</Button>
|
|
</FormItem>
|
|
</Form>
|
|
</PageContent>
|
|
|
|
@code {
|
|
ICollection<StorageLocation> 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);
|
|
}
|
|
}
|