Added simple archive browser

dashboard
Pat Hartl 2023-01-28 21:18:36 -06:00
parent d1bfe39984
commit 64ba162975
5 changed files with 150 additions and 0 deletions

View File

@ -0,0 +1,98 @@
@using ByteSizeLib;
@using LANCommander.Services;
@using System.IO.Compression;
@inject ArchiveService ArchiveService;
<div class="card-body">
<div class="row">
<div class="col">
<input @bind="CurrentPath" class="form-control" disabled />
</div>
</div>
</div>
<div class="table-responsive">
<table class="table table-vcenter table-striped table-hover card-table" id="ArchiveBrowser">
<thead>
<tr>
<th>Name</th>
<th>Size</th>
<th>Modified</th>
</tr>
</thead>
<tbody>
@if (CurrentPath != "")
{
<tr @ondblclick="GoUpLevel">
<td colspan="3">..</td>
</tr>
}
@foreach (var entry in CurrentPathEntries.OrderBy(e => !e.FullName.EndsWith('/')).ThenBy(e => e.FullName))
{
@if (entry.FullName.EndsWith('/'))
{
<tr @ondblclick="() => GoToPath(entry.FullName)">
<td>@entry.FullName.Remove(0, CurrentPath.Length)</td>
<td></td>
<td>@entry.LastWriteTime</td>
</tr>
}
else
{
<tr>
<td>@entry.Name</td>
<td>@ByteSize.FromBytes(entry.Length)</td>
<td>@entry.LastWriteTime</td>
</tr>
}
}
</tbody>
</table>
</div>
<style>
#ArchiveBrowser tr {
cursor: pointer;
}
</style>
@code {
[Parameter] public Guid ArchiveId { get; set; }
private IEnumerable<ZipArchiveEntry> Entries { get; set; }
private IEnumerable<ZipArchiveEntry> CurrentPathEntries { get; set; }
private string CurrentPath { get; set; }
protected override async Task OnInitializedAsync()
{
Entries = await ArchiveService.GetContents(ArchiveId);
GoToRoot();
}
private void GoToRoot()
{
CurrentPath = "";
CurrentPathEntries = Entries.Where(e => e.FullName.TrimEnd('/').Split('/').Length == 1);
}
private void GoUpLevel()
{
var parts = CurrentPath.TrimEnd('/').Split('/');
if (parts.Length == 1)
GoToRoot();
else
{
GoToPath(String.Join('/', parts.Take(parts.Length - 1)) + "/");
}
}
private void GoToPath(string path)
{
CurrentPath = path;
CurrentPathEntries = Entries.Where(e => e.FullName.StartsWith(CurrentPath) && e.FullName != CurrentPath && e.FullName.Remove(0, path.Length).TrimEnd('/').Split('/').Length == 1);
}
}

View File

@ -92,6 +92,13 @@ namespace LANCommander.Controllers
return RedirectToAction("Edit", "Games", new { id = gameId });
}
public async Task<IActionResult> Browse(Guid id)
{
var archive = await ArchiveService.Get(id);
return View(archive);
}
public async Task<IActionResult> Validate(Guid id, Archive archive)
{
var path = $"Upload/{id}".ToPath();

View File

@ -77,5 +77,17 @@ namespace LANCommander.Services
}
}
}
public async Task<IEnumerable<ZipArchiveEntry>> GetContents(Guid archiveId)
{
var archive = await Get(archiveId);
var upload = $"Upload/{archive.ObjectKey}".ToPath();
using (ZipArchive zip = ZipFile.OpenRead(upload))
{
return zip.Entries;
}
}
}
}

View File

@ -0,0 +1,32 @@
@using LANCommander.Components;
@model LANCommander.Data.Models.Archive
@{
ViewData["Title"] = "Browse Archive";
}
<div class="container-xl">
<!-- Page title -->
<div class="page-header d-print-none">
<div class="row align-items-center">
<div class="col">
<div class="page-pretitle">@Model.Game.Title</div>
<h2 class="page-title">
Browse Archive
</h2>
</div>
</div>
</div>
</div>
<div class="page-body">
<div class="container-xl">
<div class="row row-cards">
<div class="col-12">
<div class="card">
<component type="typeof(ArchiveBrowser)" render-mode="Server" param-ArchiveId="Model.Id" />
</div>
</div>
</div>
</div>
</div>

View File

@ -205,6 +205,7 @@
<td>
<div class="btn-list flex-nowrap justify-content-end">
<a asp-action="Download" asp-controller="Archives" asp-route-id="@archive.Id" class="btn">Download</a>
<a asp-action="Browse" asp-controller="Archives" asp-route-id="@archive.Id" class="btn">Browse</a>
<a asp-action="Delete" asp-controller="Archives" asp-route-id="@archive.Id" class="btn btn-danger">Delete</a>
</div>
</td>