98 lines
3 KiB
Text
98 lines
3 KiB
Text
@page "/Settings/Tools/MissingArchives"
|
|
@inject ArchiveService ArchiveService
|
|
@inject IMessageService MessageService
|
|
@inject ILogger<MissingArchives> Logger
|
|
@attribute [Authorize(Roles = RoleService.AdministratorRoleName)]
|
|
|
|
<PageHeader Title="Missing Archives" />
|
|
|
|
<PageContent>
|
|
<p>
|
|
These archives are missing their backing file in the "Upload" directory of your server. This may result in broken downloads for clients. To fix, either upload a new file or delete the offending archive.
|
|
</p>
|
|
</PageContent>
|
|
|
|
<Table TItem="Archive" DataSource="@Archives" Loading="@Loading" Responsive>
|
|
<PropertyColumn Property="a => a.Version" Sortable />
|
|
<PropertyColumn Property="a => a.Game.Title" Title="Game" />
|
|
<PropertyColumn Property="a => a.CreatedOn" Format="MM/dd/yyyy hh:mm tt" Sortable />
|
|
<PropertyColumn Property="a => a.CreatedBy" Sortable>
|
|
@context.CreatedBy?.UserName
|
|
</PropertyColumn>
|
|
<ActionColumn Title="" Style="text-align: right">
|
|
<Space Direction="SpaceDirection.Horizontal">
|
|
<SpaceItem>
|
|
<Button OnClick="() => Upload(context)" Icon="@IconType.Outline.Upload" Type="@ButtonType.Text" />
|
|
</SpaceItem>
|
|
<SpaceItem>
|
|
<Popconfirm OnConfirm="() => Delete(context)" Title="Are you sure you want to delete this archive?">
|
|
<Button Icon="@IconType.Outline.Close" Type="@ButtonType.Text" Danger />
|
|
</Popconfirm>
|
|
</SpaceItem>
|
|
</Space>
|
|
</ActionColumn>
|
|
</Table>
|
|
|
|
<ArchiveUploader @ref="Uploader" OnArchiveUploaded="LoadData" />
|
|
|
|
|
|
@code {
|
|
ICollection<Archive> Archives;
|
|
bool Loading = true;
|
|
|
|
ArchiveUploader Uploader;
|
|
|
|
protected override async Task OnInitializedAsync()
|
|
{
|
|
await LoadData();
|
|
}
|
|
|
|
async Task LoadData()
|
|
{
|
|
Loading = true;
|
|
|
|
Archives = new List<Archive>();
|
|
|
|
foreach (var archive in await ArchiveService.GetAsync())
|
|
{
|
|
var archivePath = await ArchiveService.GetArchiveFileLocationAsync(archive);
|
|
var exists = await ArchiveService.FileExistsAsync(archive.Id);
|
|
|
|
if (!exists)
|
|
Archives.Add(archive);
|
|
else if (new FileInfo(archivePath).Length == 0)
|
|
Archives.Add(archive);
|
|
}
|
|
|
|
Loading = false;
|
|
}
|
|
|
|
async Task Upload(Archive archive)
|
|
{
|
|
var archiveFilePath = await ArchiveService.GetArchiveFileLocationAsync(archive);
|
|
|
|
if (await ArchiveService.FileExistsAsync(archive.Id))
|
|
File.Delete(archiveFilePath);
|
|
|
|
File.Create(archiveFilePath).Close();
|
|
|
|
await Uploader.Open(archive.Id);
|
|
}
|
|
|
|
async Task Delete(Archive archive)
|
|
{
|
|
try
|
|
{
|
|
await ArchiveService.DeleteAsync(archive);
|
|
|
|
await LoadData();
|
|
|
|
await MessageService.SuccessAsync("Archive deleted!");
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
MessageService.Error("Archive could not be deleted.");
|
|
Logger.LogError(ex, "Archive could not be deleted.");
|
|
}
|
|
}
|
|
}
|