Add tool for finding and updating missing archives for games

dhcp-server
Pat Hartl 2023-08-28 18:25:06 -05:00
parent 15ac48caab
commit b59b0eca0e
3 changed files with 120 additions and 1 deletions

View File

@ -8,7 +8,7 @@
<MenuItem RouterLink="/Settings/General">General</MenuItem>
<MenuItem RouterLink="/Settings/Users">Users</MenuItem>
<MenuItem RouterLink="/Settings/Authentication">Authentication</MenuItem>
<MenuItem RouterLink="/Settings/Tools">Tools</MenuItem>
<MenuItem RouterLink="/Settings/Tools" RouterMatch="@NavLinkMatch.Prefix">Tools</MenuItem>
</Menu>
</Sider>

View File

@ -0,0 +1,113 @@
@page "/Settings/Tools/MissingArchives"
@using LANCommander.Models;
@using LANCommander.Pages.Games.Components;
@layout SettingsLayout
@inject IMessageService MessageService
@inject ArchiveService ArchiveService
@attribute [Authorize(Roles = "Administrator")]
<PageHeader Title="Missing Archives" />
<div style="padding: 0 24px;">
<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>
<Table TItem="Archive" DataSource="@Archives" Loading="@Loading">
<PropertyColumn Property="a => a.Version" Sortable />
<PropertyColumn Property="a => a.Game.Title" />
<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="DirectionVHType.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="OnArchiveUploaded" />
</div>
@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.Get())
{
var archivePath = ArchiveService.GetArchiveFileLocation(archive);
var exists = await ArchiveService.Exists(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 = ArchiveService.GetArchiveFileLocation(archive);
if (await ArchiveService.Exists(archive.Id))
File.Delete(archiveFilePath);
System.IO.File.Create(archiveFilePath).Close();
await Uploader.Open(archive);
}
async Task OnArchiveUploaded(Archive archive)
{
try
{
await ArchiveService.Update(archive);
await LoadData();
}
catch (Exception ex)
{
await MessageService.Error("Archive could not be updated.");
}
}
async Task Delete(Archive archive)
{
try
{
await ArchiveService.Delete(archive);
await LoadData();
await MessageService.Success("Archive deleted!");
}
catch (Exception ex)
{
await MessageService.Error("Archive could not be deleted.");
}
}
}

View File

@ -21,6 +21,12 @@
Some file sizes are cached in the database. Click the button below to scan through all files and recalculate their size.
</p>
<Button Type="@ButtonType.Primary" OnClick="RecalculateFileSizes" Loading="RecalculatingFileSizes">Recalculate</Button>
<Divider />
<h3>Missing Archives</h3>
<p>List and fix all archives that are missing their backing files.</p>
<a href="/Settings/Tools/MissingArchives" class="ant-btn ant-btn-primary">View Missing Archives</a>
</div>