CDN Integration for Admin

This commit is contained in:
dingo
2025-12-25 17:39:00 -05:00
parent 5afe3884fa
commit 1d5fbd29ce
11 changed files with 486 additions and 228 deletions
+174 -166
View File
@@ -10,7 +10,7 @@
<div class="flex items-center justify-between">
<div>
<h1 class="text-3xl font-bold text-white">CDN Assets</h1>
<p class="text-gray-400 mt-1">Browse CDN and manage tracked assets</p>
<p class="text-gray-400 mt-1">Browse MinIO bucket and manage tracked assets</p>
</div>
</div>
@@ -26,126 +26,165 @@
@if (Model.Tab == "browse")
{
<!-- CDN Browser -->
<div class="card p-4">
<div class="flex items-center gap-4 mb-4">
<label class="label mb-0">Category:</label>
<div class="flex gap-2">
<a href="/admin/assets?tab=browse&folder=textures/items" class="btn @(Model.Folder == "textures/items" ? "btn-primary" : "btn-secondary") text-sm">Items</a>
<a href="/admin/assets?tab=browse&folder=textures/mobs" class="btn @(Model.Folder == "textures/mobs" ? "btn-primary" : "btn-secondary") text-sm">Mobs</a>
<a href="/admin/assets?tab=browse&folder=textures/objects" class="btn @(Model.Folder == "textures/objects" ? "btn-primary" : "btn-secondary") text-sm">Objects</a>
<a href="/admin/assets?tab=browse&folder=textures/spells" class="btn @(Model.Folder == "textures/spells" ? "btn-primary" : "btn-secondary") text-sm">Spells</a>
<a href="/admin/assets?tab=browse&folder=textures/ui" class="btn @(Model.Folder == "textures/ui" ? "btn-primary" : "btn-secondary") text-sm">UI</a>
<a href="/admin/assets?tab=browse&folder=scenes/mobs" class="btn @(Model.Folder == "scenes/mobs" ? "btn-primary" : "btn-secondary") text-sm">Mob Scenes</a>
</div>
</div>
<p class="text-sm text-gray-500 mb-4">
CDN Path: <code class="bg-gray-900 px-2 py-1 rounded">@Model.CdnBaseUrl/downloads/@Model.Folder/</code>
</p>
</div>
<!-- Manual Path Entry -->
<div class="card p-4">
<form method="post" asp-page-handler="RegisterAsset" class="flex items-end gap-4">
@Html.AntiForgeryToken()
<div class="flex-1">
<label class="label">Register Asset by Path</label>
<input type="text" name="filePath" class="input" placeholder="e.g., textures/items/sword.png" required />
</div>
<div class="w-40">
<label class="label">Type</label>
<select name="assetType" class="input">
@foreach (var t in Enum.GetValues<ClientAssetType>())
{
<option value="@t">@t</option>
}
</select>
</div>
<button type="submit" class="btn btn-primary">Register</button>
</form>
</div>
<!-- Preview Grid for common textures -->
@if (Model.Folder?.StartsWith("textures/") == true)
@if (!Model.CdnConfigured)
{
<div class="card">
<div class="p-4 border-b border-gray-700">
<h2 class="text-lg font-semibold text-white">Preview - @Model.Folder</h2>
<p class="text-sm text-gray-500">Click an image to copy its path, or use the register button to track it.</p>
</div>
<div class="p-4">
<div class="grid grid-cols-4 md:grid-cols-6 lg:grid-cols-8 xl:grid-cols-10 gap-2">
@foreach (var file in Model.PreviewFiles)
<div class="card p-6 text-center">
<svg class="w-16 h-16 mx-auto text-yellow-500 mb-4" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 9v2m0 4h.01m-6.938 4h13.856c1.54 0 2.502-1.667 1.732-3L13.732 4c-.77-1.333-2.694-1.333-3.464 0L3.34 16c-.77 1.333.192 3 1.732 3z"/>
</svg>
<h3 class="text-xl font-semibold text-white mb-2">MinIO Not Configured</h3>
<p class="text-gray-400 mb-4">To browse CDN files, configure MinIO credentials in appsettings.json:</p>
<pre class="bg-gray-900 p-4 rounded text-left text-sm text-gray-300 max-w-md mx-auto">"MinIO": {
"Endpoint": "assets.aeternalisgames.com",
"AccessKey": "your-access-key",
"SecretKey": "your-secret-key",
"BucketName": "downloads",
"UseSSL": true
}</pre>
</div>
}
else
{
<!-- Folder Navigation -->
<div class="card p-4">
<div class="flex items-center gap-4 mb-4">
<label class="label mb-0">Folder:</label>
<div class="flex flex-wrap gap-2">
@foreach (var folder in Model.AvailableFolders)
{
var isTracked = Model.TrackedPaths.Contains(file);
<div class="relative group">
<div class="w-full aspect-square bg-gray-900 rounded border @(isTracked ? "border-green-600" : "border-gray-700") flex items-center justify-center overflow-hidden">
<img src="@Html.Raw(Model.CdnBaseUrl)/downloads/@file"
alt="@System.IO.Path.GetFileName(file)"
class="max-w-full max-h-full object-contain"
loading="lazy"
onerror="this.parentElement.innerHTML='<span class=\'text-xs text-red-400\'>404</span>'" />
</div>
<p class="text-xs text-gray-500 truncate mt-1" title="@file">@System.IO.Path.GetFileName(file)</p>
<!-- Hover actions -->
<div class="absolute inset-0 bg-black/70 opacity-0 group-hover:opacity-100 transition-opacity flex items-center justify-center gap-1 rounded">
<button type="button" onclick="copyPath('@file')" class="p-1 bg-gray-700 rounded hover:bg-gray-600" title="Copy Path">
<svg class="w-4 h-4 text-white" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M8 16H6a2 2 0 01-2-2V6a2 2 0 012-2h8a2 2 0 012 2v2m-6 12h8a2 2 0 002-2v-8a2 2 0 00-2-2h-8a2 2 0 00-2 2v8a2 2 0 002 2z"/>
</svg>
</button>
@if (!isTracked)
{
<form method="post" asp-page-handler="RegisterAsset" class="inline">
@Html.AntiForgeryToken()
<input type="hidden" name="filePath" value="@file" />
<input type="hidden" name="assetType" value="Texture" />
<button type="submit" class="p-1 bg-green-700 rounded hover:bg-green-600" title="Register">
<svg class="w-4 h-4 text-white" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 4v16m8-8H4"/>
</svg>
</button>
</form>
}
else
{
<span class="p-1 bg-green-900 rounded" title="Already tracked">
<svg class="w-4 h-4 text-green-400" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M5 13l4 4L19 7"/>
</svg>
</span>
}
</div>
</div>
<a href="/admin/assets?tab=browse&prefix=@Uri.EscapeDataString(folder)"
class="btn @(Model.Prefix == folder ? "btn-primary" : "btn-secondary") text-sm">
@folder.TrimEnd('/').Split('/').Last()
</a>
}
</div>
@if (!Model.PreviewFiles.Any())
</div>
<!-- Breadcrumb -->
<div class="flex items-center gap-1 text-sm">
<a href="/admin/assets?tab=browse&prefix=" class="text-indigo-400 hover:underline">root</a>
@{
var parts = Model.Prefix?.Split('/', StringSplitOptions.RemoveEmptyEntries) ?? Array.Empty<string>();
var currentPath = "";
}
@foreach (var part in parts)
{
<p class="text-gray-500 text-center py-8">
Enter file names manually or check that assets exist at this CDN path.
</p>
currentPath += part + "/";
<span class="text-gray-600">/</span>
<a href="/admin/assets?tab=browse&prefix=@Uri.EscapeDataString(currentPath)" class="text-indigo-400 hover:underline">@part</a>
}
</div>
</div>
<!-- Subfolders -->
@if (Model.Subfolders.Any())
{
<div class="card p-4">
<h3 class="text-white font-medium mb-3">Subfolders</h3>
<div class="flex flex-wrap gap-2">
@foreach (var subfolder in Model.Subfolders)
{
<a href="/admin/assets?tab=browse&prefix=@Uri.EscapeDataString(subfolder)"
class="flex items-center gap-2 px-3 py-2 bg-gray-800 hover:bg-gray-700 rounded text-gray-300">
<svg class="w-4 h-4 text-yellow-500" fill="currentColor" viewBox="0 0 20 20">
<path d="M2 6a2 2 0 012-2h5l2 2h5a2 2 0 012 2v6a2 2 0 01-2 2H4a2 2 0 01-2-2V6z"/>
</svg>
@subfolder.TrimEnd('/').Split('/').Last()
</a>
}
</div>
</div>
}
<!-- Files Grid -->
@if (Model.Files.Any())
{
<div class="card">
<div class="p-4 border-b border-gray-700 flex items-center justify-between">
<div>
<h2 class="text-lg font-semibold text-white">Files in @(string.IsNullOrEmpty(Model.Prefix) ? "root" : Model.Prefix)</h2>
<p class="text-sm text-gray-500">@Model.Files.Count files. Click to copy path, + to register.</p>
</div>
</div>
<div class="p-4">
<div class="grid grid-cols-4 md:grid-cols-6 lg:grid-cols-8 xl:grid-cols-10 gap-3">
@foreach (var file in Model.Files.Where(f => !f.IsDirectory))
{
var isTracked = Model.TrackedPaths.Contains(file.Key);
var isImage = file.Name.EndsWith(".png") || file.Name.EndsWith(".jpg") || file.Name.EndsWith(".webp");
<div class="relative group">
<div class="aspect-square bg-gray-900 rounded border @(isTracked ? "border-green-600" : "border-gray-700") flex items-center justify-center overflow-hidden">
@if (isImage)
{
<img src="@Html.Raw(Model.CdnBaseUrl)/downloads/@file.Key"
alt="@file.Name"
class="max-w-full max-h-full object-contain"
loading="lazy"
onerror="this.src='data:image/svg+xml,<svg xmlns=%22http://www.w3.org/2000/svg%22 viewBox=%220 0 24 24%22 fill=%22%23991b1b%22><text x=%2250%%22 y=%2250%%22 text-anchor=%22middle%22 dy=%22.3em%22 font-size=%228%22>ERR</text></svg>'" />
}
else
{
<div class="text-center text-gray-500">
<svg class="w-8 h-8 mx-auto" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 12h6m-6 4h6m2 5H7a2 2 0 01-2-2V5a2 2 0 012-2h5.586a1 1 0 01.707.293l5.414 5.414a1 1 0 01.293.707V19a2 2 0 01-2 2z"/>
</svg>
<p class="text-xs mt-1">@System.IO.Path.GetExtension(file.Name)</p>
</div>
}
</div>
<p class="text-xs text-gray-500 truncate mt-1 text-center" title="@file.Key">@file.Name</p>
@if (isTracked)
{
<div class="absolute top-1 right-1 bg-green-600 rounded-full p-0.5">
<svg class="w-3 h-3 text-white" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="3" d="M5 13l4 4L19 7"/>
</svg>
</div>
}
<!-- Hover actions -->
<div class="absolute inset-0 bg-black/80 opacity-0 group-hover:opacity-100 transition-opacity flex items-center justify-center gap-1 rounded">
<button type="button" onclick="copyPath('@file.Key')" class="p-1.5 bg-gray-700 rounded hover:bg-gray-600" title="Copy Path">
<svg class="w-4 h-4 text-white" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M8 16H6a2 2 0 01-2-2V6a2 2 0 012-2h8a2 2 0 012 2v2m-6 12h8a2 2 0 002-2v-8a2 2 0 00-2-2h-8a2 2 0 00-2 2v8a2 2 0 002 2z"/>
</svg>
</button>
@if (!isTracked)
{
<form method="post" asp-page-handler="RegisterAsset" class="inline">
@Html.AntiForgeryToken()
<input type="hidden" name="filePath" value="@file.Key" />
<input type="hidden" name="assetType" value="@(isImage ? "Texture" : "Data")" />
<input type="hidden" name="fileSize" value="@file.Size" />
<input type="hidden" name="returnPrefix" value="@Model.Prefix" />
<button type="submit" class="p-1.5 bg-green-700 rounded hover:bg-green-600" title="Register">
<svg class="w-4 h-4 text-white" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 4v16m8-8H4"/>
</svg>
</button>
</form>
}
</div>
</div>
}
</div>
</div>
</div>
}
else if (!Model.Subfolders.Any())
{
<div class="card p-8 text-center">
<svg class="w-16 h-16 mx-auto text-gray-600" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M3 7v10a2 2 0 002 2h14a2 2 0 002-2V9a2 2 0 00-2-2h-6l-2-2H5a2 2 0 00-2 2z"/>
</svg>
<p class="text-gray-400 mt-4">This folder is empty.</p>
</div>
}
}
<!-- Quick Add Common Files -->
<div class="card p-4">
<h3 class="text-white font-medium mb-3">Quick Test - Enter filenames (comma separated)</h3>
<form method="get" class="flex gap-4">
<input type="hidden" name="tab" value="browse" />
<input type="hidden" name="folder" value="@Model.Folder" />
<input type="text" name="files" value="@Model.FileList" class="input flex-1" placeholder="e.g., sword.png, shield.png, potion.png" />
<button type="submit" class="btn btn-secondary">Load Preview</button>
</form>
</div>
}
else
{
<!-- Tracked Assets -->
<!-- Tracked Assets Tab -->
<div class="card p-4">
<form method="get" class="flex flex-wrap items-end gap-4">
<input type="hidden" name="tab" value="tracked" />
@@ -159,7 +198,7 @@
<option value="">All Types</option>
@foreach (var t in Enum.GetValues<ClientAssetType>())
{
<option value="@t" selected="@(Model.TypeFilter == t)">@t</option>
<option value="@t" selected="@(Model.AssetTypeFilter == t)">@t</option>
}
</select>
</div>
@@ -189,65 +228,44 @@
</div>
<!-- Assets Grid -->
<div class="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4 gap-4">
<div class="grid grid-cols-3 md:grid-cols-5 lg:grid-cols-7 xl:grid-cols-9 gap-3">
@foreach (var asset in Model.Assets)
{
<div class="card overflow-hidden group">
<div class="h-32 bg-gray-900 flex items-center justify-center relative">
<div class="card overflow-hidden group relative">
<div class="aspect-square bg-gray-900 flex items-center justify-center">
@if (asset.AssetType == ClientAssetType.Texture)
{
<img src="@Html.Raw(Model.CdnBaseUrl)/downloads/@asset.DownloadPath"
alt="@asset.FilePath"
class="max-h-full max-w-full object-contain"
onerror="this.parentElement.innerHTML='<div class=\'text-red-400 text-center\'><p class=\'text-xs\'>Failed to load</p></div>'" />
loading="lazy" />
}
else
{
<div class="text-gray-600 text-center">
@switch (asset.AssetType)
{
case ClientAssetType.Scene:
<svg class="w-12 h-12 mx-auto text-green-600" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M19 11H5m14 0a2 2 0 012 2v6a2 2 0 01-2 2H5a2 2 0 01-2-2v-6a2 2 0 012-2m14 0V9a2 2 0 00-2-2M5 11V9a2 2 0 012-2m0 0V5a2 2 0 012-2h6a2 2 0 012 2v2M7 7h10"/>
</svg>
break;
case ClientAssetType.Script:
<svg class="w-12 h-12 mx-auto text-yellow-600" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M10 20l4-16m4 4l4 4-4 4M6 16l-4-4 4-4"/>
</svg>
break;
default:
<svg class="w-12 h-12 mx-auto" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 12h6m-6 4h6m2 5H7a2 2 0 01-2-2V5a2 2 0 012-2h5.586a1 1 0 01.707.293l5.414 5.414a1 1 0 01.293.707V19a2 2 0 01-2 2z"/>
</svg>
break;
}
<p class="text-xs mt-1">@asset.AssetType</p>
<svg class="w-8 h-8 mx-auto" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 12h6m-6 4h6m2 5H7a2 2 0 01-2-2V5a2 2 0 012-2h5.586a1 1 0 01.707.293l5.414 5.414a1 1 0 01.293.707V19a2 2 0 01-2 2z"/>
</svg>
<p class="text-xs">@asset.AssetType</p>
</div>
}
<div class="absolute top-2 right-2">
<span class="badge badge-common text-xs">@asset.AssetType</span>
</div>
</div>
<div class="p-3">
<p class="text-sm text-white font-medium truncate">@System.IO.Path.GetFileName(asset.FilePath)</p>
<p class="text-xs text-gray-500 truncate">@asset.FilePath</p>
<div class="flex items-center justify-between mt-2 text-xs text-gray-400">
<span>v@asset.Version</span>
<span>@FormatFileSize(asset.FileSize)</span>
</div>
<div class="p-2">
<p class="text-xs text-white truncate" title="@asset.FilePath">@System.IO.Path.GetFileName(asset.FilePath)</p>
</div>
<div class="border-t border-gray-700 p-2 flex justify-end gap-2">
<button onclick="copyPath('@asset.FilePath')" class="p-1.5 hover:bg-gray-700 rounded text-gray-400" title="Copy Path">
<svg class="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<!-- Hover actions -->
<div class="absolute inset-0 bg-black/80 opacity-0 group-hover:opacity-100 transition-opacity flex items-center justify-center gap-2 rounded">
<button onclick="copyPath('@asset.FilePath')" class="p-2 bg-gray-700 rounded hover:bg-gray-600" title="Copy">
<svg class="w-4 h-4 text-white" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M8 16H6a2 2 0 01-2-2V6a2 2 0 012-2h8a2 2 0 012 2v2m-6 12h8a2 2 0 002-2v-8a2 2 0 00-2-2h-8a2 2 0 00-2 2v8a2 2 0 002 2z"/>
</svg>
</button>
<form method="post" asp-page-handler="DeleteAsset" class="inline">
@Html.AntiForgeryToken()
<input type="hidden" name="assetId" value="@asset.Id" />
<button type="submit" class="p-1.5 hover:bg-gray-700 rounded text-red-400" title="Untrack" onclick="return confirm('Remove tracking for this asset?')">
<svg class="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<button type="submit" class="p-2 bg-red-700 rounded hover:bg-red-600" title="Untrack" onclick="return confirm('Untrack?')">
<svg class="w-4 h-4 text-white" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M19 7l-.867 12.142A2 2 0 0116.138 21H7.862a2 2 0 01-1.995-1.858L5 7m5 4v6m4-6v6m1-10V4a1 1 0 00-1-1h-4a1 1 0 00-1 1v3M4 7h16"/>
</svg>
</button>
@@ -265,20 +283,20 @@
</div>
<!-- Pagination -->
@if (Model.TotalPages > 1)
@if (Model.TrackedTotalPages > 1)
{
<div class="flex items-center justify-between">
<p class="text-sm text-gray-400">
Page @Model.CurrentPage of @Model.TotalPages
Page @Model.TrackedPage of @Model.TrackedTotalPages
</p>
<div class="flex items-center gap-2">
@if (Model.CurrentPage > 1)
@if (Model.TrackedPage > 1)
{
<a href="@Model.GetPageUrl(Model.CurrentPage - 1)" class="btn btn-secondary">← Prev</a>
<a href="@Model.GetTrackedPageUrl(Model.TrackedPage - 1)" class="btn btn-secondary">← Prev</a>
}
@if (Model.CurrentPage < Model.TotalPages)
@if (Model.TrackedPage < Model.TrackedTotalPages)
{
<a href="@Model.GetPageUrl(Model.CurrentPage + 1)" class="btn btn-secondary">Next →</a>
<a href="@Model.GetTrackedPageUrl(Model.TrackedPage + 1)" class="btn btn-secondary">Next →</a>
}
</div>
</div>
@@ -288,27 +306,17 @@
@if (!string.IsNullOrEmpty(Model.Message))
{
<div class="fixed bottom-4 right-4 p-4 rounded-lg @(Model.IsError ? "bg-red-900 border border-red-700" : "bg-green-900 border border-green-700") text-white shadow-lg">
<div class="fixed bottom-4 right-4 p-4 rounded-lg @(Model.IsError ? "bg-red-900 border border-red-700" : "bg-green-900 border border-green-700") text-white shadow-lg z-50">
@Model.Message
</div>
}
@functions {
string FormatFileSize(long bytes)
{
if (bytes < 1024) return $"{bytes} B";
if (bytes < 1024 * 1024) return $"{bytes / 1024.0:F1} KB";
return $"{bytes / (1024.0 * 1024.0):F1} MB";
}
}
@section Scripts {
<script>
function copyPath(path) {
navigator.clipboard.writeText(path).then(() => {
// Quick visual feedback
const toast = document.createElement('div');
toast.className = 'fixed bottom-4 left-4 bg-gray-800 text-white px-4 py-2 rounded shadow-lg';
toast.className = 'fixed bottom-4 left-4 bg-gray-800 text-white px-4 py-2 rounded shadow-lg z-50';
toast.textContent = 'Copied: ' + path;
document.body.appendChild(toast);
setTimeout(() => toast.remove(), 2000);
+65 -59
View File
@@ -2,6 +2,7 @@ using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
using Server.Data;
using Server.Data.Entities;
using Server.Services;
using System.Security.Cryptography;
namespace VoidScavengers.Services.Admin.Pages.Assets;
@@ -9,10 +10,12 @@ namespace VoidScavengers.Services.Admin.Pages.Assets;
public class IndexModel : AdminPageModel
{
private readonly GameDbContext _db;
private readonly ICdnBrowserService _cdnService;
public IndexModel(GameDbContext db)
public IndexModel(GameDbContext db, ICdnBrowserService cdnService)
{
_db = db;
_cdnService = cdnService;
}
// Tab state
@@ -20,29 +23,36 @@ public class IndexModel : AdminPageModel
public string Tab { get; set; } = "browse";
// Browse tab
[FromQuery(Name = "folder")]
public string Folder { get; set; } = "textures/items";
[FromQuery(Name = "prefix")]
public string? Prefix { get; set; }
[FromQuery(Name = "files")]
public string? FileList { get; set; }
public List<string> PreviewFiles { get; set; } = new();
public HashSet<string> TrackedPaths { get; set; } = new();
public bool CdnConfigured => _cdnService.IsConfigured;
public List<CdnFile> Files { get; set; } = new();
public List<string> Subfolders { get; set; } = new();
public List<string> AvailableFolders { get; set; } = new()
{
"textures/items/",
"textures/mobs/",
"textures/objects/",
"textures/spells/",
"textures/ui/",
"scenes/mobs/"
};
// Tracked tab
public List<ClientAsset> Assets { get; set; } = new();
[FromQuery(Name = "search")]
public string? Search { get; set; }
[FromQuery(Name = "type")]
public ClientAssetType? TypeFilter { get; set; }
public ClientAssetType? AssetTypeFilter { get; set; }
[FromQuery(Name = "page")]
public int CurrentPage { get; set; } = 1;
[FromQuery(Name = "tpage")]
public int TrackedPage { get; set; } = 1;
public int PageSize { get; set; } = 24;
public int TotalPages { get; set; }
public List<ClientAsset> Assets { get; set; } = new();
public int TrackedTotalPages { get; set; }
public HashSet<string> TrackedPaths { get; set; } = new();
// Stats
public int TrackedCount { get; set; }
@@ -50,16 +60,18 @@ public class IndexModel : AdminPageModel
public int SceneCount { get; set; }
public int ScriptCount { get; set; }
public int PageSize { get; set; } = 60;
public string CdnBaseUrl { get; set; } = "https://assets.aeternalisgames.com";
public string? Message { get; set; }
public bool IsError { get; set; }
public string GetPageUrl(int page)
public string GetTrackedPageUrl(int page)
{
var parts = new List<string> { $"tab=tracked", $"page={page}" };
var parts = new List<string> { $"tab=tracked", $"tpage={page}" };
if (!string.IsNullOrEmpty(Search)) parts.Add($"search={Uri.EscapeDataString(Search)}");
if (TypeFilter.HasValue) parts.Add($"type={TypeFilter}");
if (AssetTypeFilter.HasValue) parts.Add($"type={AssetTypeFilter}");
return "/admin/assets?" + string.Join("&", parts);
}
@@ -77,64 +89,58 @@ public class IndexModel : AdminPageModel
// Get tracked paths for comparison
TrackedPaths = (await _db.ClientAssets.Select(a => a.FilePath).ToListAsync()).ToHashSet();
if (Tab == "browse")
if (Tab == "browse" && CdnConfigured)
{
// Generate preview files based on folder and file list
if (!string.IsNullOrEmpty(FileList))
{
var files = FileList.Split(',', StringSplitOptions.RemoveEmptyEntries | StringSplitOptions.TrimEntries);
PreviewFiles = files.Select(f => $"{Folder}/{f}".Replace("//", "/")).ToList();
}
else
{
// Default preview files - try common naming patterns
// For items, try fb001.png through fb999.png pattern
if (Folder == "textures/items")
{
// Just show a few placeholder suggestions
PreviewFiles = Enumerable.Range(1, 50)
.Select(i => $"{Folder}/fb{i:D3}.png")
.ToList();
}
else if (Folder == "textures/mobs")
{
// Try common mob names
var mobNames = new[] { "skeleton", "zombie", "slime", "goblin", "orc", "spider", "bat", "wolf", "bear", "demon" };
PreviewFiles = mobNames.Select(m => $"{Folder}/{m}.png").ToList();
}
}
// Normalize prefix
Prefix = Prefix?.TrimEnd('/');
if (!string.IsNullOrEmpty(Prefix))
Prefix += "/";
// List files from MinIO
var allItems = await _cdnService.ListFilesAsync(Prefix ?? "", 200);
// Separate files and folders
Subfolders = allItems
.Where(f => f.IsDirectory)
.Select(f => f.Key)
.OrderBy(f => f)
.ToList();
Files = allItems
.Where(f => !f.IsDirectory)
.OrderBy(f => f.Name)
.ToList();
}
else
else if (Tab == "tracked")
{
// Tracked assets tab
if (CurrentPage < 1) CurrentPage = 1;
if (TrackedPage < 1) TrackedPage = 1;
var query = _db.ClientAssets.AsQueryable();
if (!string.IsNullOrWhiteSpace(Search))
query = query.Where(a => a.FilePath.Contains(Search));
if (TypeFilter.HasValue)
query = query.Where(a => a.AssetType == TypeFilter.Value);
if (AssetTypeFilter.HasValue)
query = query.Where(a => a.AssetType == AssetTypeFilter.Value);
var total = await query.CountAsync();
TotalPages = (int)Math.Ceiling(total / (double)PageSize);
TrackedTotalPages = (int)Math.Ceiling(total / (double)PageSize);
Assets = await query
.OrderByDescending(a => a.UpdatedAt)
.Skip((CurrentPage - 1) * PageSize)
.Skip((TrackedPage - 1) * PageSize)
.Take(PageSize)
.ToListAsync();
}
}
public async Task<IActionResult> OnPostRegisterAssetAsync(string filePath, ClientAssetType assetType)
public async Task<IActionResult> OnPostRegisterAssetAsync(string filePath, ClientAssetType assetType, long fileSize, string? returnPrefix)
{
if (string.IsNullOrWhiteSpace(filePath))
{
Message = "File path is required.";
IsError = true;
return RedirectToPage(new { tab = Tab, folder = Folder });
return RedirectToPage(new { tab = "browse", prefix = returnPrefix });
}
// Normalize path
@@ -145,9 +151,9 @@ public class IndexModel : AdminPageModel
var existing = await _db.ClientAssets.FirstOrDefaultAsync(a => a.FilePath == filePath);
if (existing != null)
{
Message = $"Asset '{filePath}' is already tracked.";
Message = $"Asset already tracked.";
IsError = true;
return RedirectToPage(new { tab = Tab, folder = Folder });
return RedirectToPage(new { tab = "browse", prefix = returnPrefix });
}
// Create new asset tracking entry
@@ -155,8 +161,8 @@ public class IndexModel : AdminPageModel
{
FilePath = filePath,
AssetType = assetType,
FileHash = GenerateHash(filePath), // Placeholder hash based on path
FileSize = 0, // Unknown without actually fetching the file
FileHash = GenerateHash(filePath),
FileSize = fileSize,
Version = 1,
IsRequired = false,
IsEnabled = true,
@@ -167,8 +173,8 @@ public class IndexModel : AdminPageModel
_db.ClientAssets.Add(asset);
await _db.SaveChangesAsync();
Message = $"Asset '{filePath}' registered successfully.";
return RedirectToPage(new { tab = Tab, folder = Folder });
Message = $"Asset registered.";
return RedirectToPage(new { tab = "browse", prefix = returnPrefix });
}
public async Task<IActionResult> OnPostDeleteAssetAsync(int assetId)
@@ -178,7 +184,7 @@ public class IndexModel : AdminPageModel
{
_db.ClientAssets.Remove(asset);
await _db.SaveChangesAsync();
Message = $"Asset '{asset.FilePath}' untracked.";
Message = $"Asset untracked.";
}
return RedirectToPage(new { tab = "tracked" });
}