From 64ba162975c62dde161042eea3d26199447456e1 Mon Sep 17 00:00:00 2001 From: Pat Hartl Date: Sat, 28 Jan 2023 21:18:36 -0600 Subject: [PATCH] Added simple archive browser --- LANCommander/Components/ArchiveBrowser.razor | 98 +++++++++++++++++++ .../Controllers/ArchivesController.cs | 7 ++ LANCommander/Services/ArchiveService.cs | 12 +++ LANCommander/Views/Archives/Browse.cshtml | 32 ++++++ LANCommander/Views/Games/Edit.cshtml | 1 + 5 files changed, 150 insertions(+) create mode 100644 LANCommander/Components/ArchiveBrowser.razor create mode 100644 LANCommander/Views/Archives/Browse.cshtml diff --git a/LANCommander/Components/ArchiveBrowser.razor b/LANCommander/Components/ArchiveBrowser.razor new file mode 100644 index 0000000..9f923a1 --- /dev/null +++ b/LANCommander/Components/ArchiveBrowser.razor @@ -0,0 +1,98 @@ +@using ByteSizeLib; +@using LANCommander.Services; +@using System.IO.Compression; +@inject ArchiveService ArchiveService; + +
+
+
+ +
+
+
+ +
+ + + + + + + + + + @if (CurrentPath != "") + { + + + + } + + @foreach (var entry in CurrentPathEntries.OrderBy(e => !e.FullName.EndsWith('/')).ThenBy(e => e.FullName)) + { + @if (entry.FullName.EndsWith('/')) + { + + + + + + } + else + { + + + + + + } + } + +
NameSizeModified
..
@entry.FullName.Remove(0, CurrentPath.Length)@entry.LastWriteTime
@entry.Name@ByteSize.FromBytes(entry.Length)@entry.LastWriteTime
+
+ + + + +@code { + [Parameter] public Guid ArchiveId { get; set; } + + private IEnumerable Entries { get; set; } + private IEnumerable 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); + } +} diff --git a/LANCommander/Controllers/ArchivesController.cs b/LANCommander/Controllers/ArchivesController.cs index 36c45d0..f81e94d 100644 --- a/LANCommander/Controllers/ArchivesController.cs +++ b/LANCommander/Controllers/ArchivesController.cs @@ -92,6 +92,13 @@ namespace LANCommander.Controllers return RedirectToAction("Edit", "Games", new { id = gameId }); } + public async Task Browse(Guid id) + { + var archive = await ArchiveService.Get(id); + + return View(archive); + } + public async Task Validate(Guid id, Archive archive) { var path = $"Upload/{id}".ToPath(); diff --git a/LANCommander/Services/ArchiveService.cs b/LANCommander/Services/ArchiveService.cs index f245bb6..622ffcc 100644 --- a/LANCommander/Services/ArchiveService.cs +++ b/LANCommander/Services/ArchiveService.cs @@ -77,5 +77,17 @@ namespace LANCommander.Services } } } + + public async Task> GetContents(Guid archiveId) + { + var archive = await Get(archiveId); + + var upload = $"Upload/{archive.ObjectKey}".ToPath(); + + using (ZipArchive zip = ZipFile.OpenRead(upload)) + { + return zip.Entries; + } + } } } diff --git a/LANCommander/Views/Archives/Browse.cshtml b/LANCommander/Views/Archives/Browse.cshtml new file mode 100644 index 0000000..6d08108 --- /dev/null +++ b/LANCommander/Views/Archives/Browse.cshtml @@ -0,0 +1,32 @@ +@using LANCommander.Components; +@model LANCommander.Data.Models.Archive + +@{ + ViewData["Title"] = "Browse Archive"; +} + +
+ + +
+ +
+
+
+
+
+ +
+
+
+
+
diff --git a/LANCommander/Views/Games/Edit.cshtml b/LANCommander/Views/Games/Edit.cshtml index b3c4d16..f2c9801 100644 --- a/LANCommander/Views/Games/Edit.cshtml +++ b/LANCommander/Views/Games/Edit.cshtml @@ -205,6 +205,7 @@