Files
systemrevivalserver/Services/Admin/Pages/Assets/Index.cshtml
T
2025-12-25 19:01:20 -05:00

326 lines
18 KiB
Plaintext

@page "/admin/assets"
@model Assets.IndexModel
@using Server.Data.Entities
@{
ViewData["Title"] = "CDN Assets";
}
<div class="space-y-6">
<!-- Header -->
<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 MinIO bucket and manage tracked assets</p>
</div>
</div>
<!-- Tabs -->
<div class="flex gap-2 border-b border-gray-700">
<a href="/admin/assets?tab=browse" class="px-4 py-2 @(Model.Tab == "browse" ? "text-white border-b-2 border-indigo-500" : "text-gray-400 hover:text-white")">
Browse CDN
</a>
<a href="/admin/assets?tab=tracked" class="px-4 py-2 @(Model.Tab == "tracked" ? "text-white border-b-2 border-indigo-500" : "text-gray-400 hover:text-white")">
Tracked Assets (@Model.TrackedCount)
</a>
</div>
@if (Model.Tab == "browse")
{
@if (!Model.CdnConfigured)
{
<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, set these environment variables (Kubernetes secret):</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
MINIO_ACCESS_KEY=your-access-key
MINIO_SECRET_KEY=your-secret-key
MINIO_BUCKET=downloads
MINIO_USE_SSL=true</pre>
<p class="text-gray-500 text-sm mt-4">Or configure in appsettings.json under "MinIO" section.</p>
</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)
{
<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>
</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)
{
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>
}
}
}
else
{
<!-- 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" />
<div class="flex-1 min-w-[200px]">
<label class="label">Search</label>
<input type="text" name="search" value="@Model.Search" class="input" placeholder="Search by path..." />
</div>
<div class="w-40">
<label class="label">Type</label>
<select name="type" class="input">
<option value="">All Types</option>
@foreach (var t in Enum.GetValues<ClientAssetType>())
{
<option value="@t" selected="@(Model.AssetTypeFilter == t)">@t</option>
}
</select>
</div>
<button type="submit" class="btn btn-secondary">Filter</button>
<a href="/admin/assets?tab=tracked" class="btn btn-secondary">Clear</a>
</form>
</div>
<!-- Stats -->
<div class="grid grid-cols-2 md:grid-cols-4 gap-4">
<div class="card p-4">
<p class="text-2xl font-bold text-white">@Model.TrackedCount</p>
<p class="text-sm text-gray-400">Total Tracked</p>
</div>
<div class="card p-4">
<p class="text-2xl font-bold text-indigo-400">@Model.TextureCount</p>
<p class="text-sm text-gray-400">Textures</p>
</div>
<div class="card p-4">
<p class="text-2xl font-bold text-green-400">@Model.SceneCount</p>
<p class="text-sm text-gray-400">Scenes</p>
</div>
<div class="card p-4">
<p class="text-2xl font-bold text-yellow-400">@Model.ScriptCount</p>
<p class="text-sm text-gray-400">Scripts</p>
</div>
</div>
<!-- Assets Grid -->
<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 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"
loading="lazy" />
}
else
{
<div class="text-gray-600 text-center">
<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>
<div class="p-2">
<p class="text-xs text-white truncate" title="@asset.FilePath">@System.IO.Path.GetFileName(asset.FilePath)</p>
</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-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-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>
</form>
</div>
</div>
}
@if (!Model.Assets.Any())
{
<div class="col-span-full card p-12 text-center">
<p class="text-gray-400">No tracked assets found.</p>
</div>
}
</div>
<!-- Pagination -->
@if (Model.TrackedTotalPages > 1)
{
<div class="flex items-center justify-between">
<p class="text-sm text-gray-400">
Page @Model.TrackedPage of @Model.TrackedTotalPages
</p>
<div class="flex items-center gap-2">
@if (Model.TrackedPage > 1)
{
<a href="@Model.GetTrackedPageUrl(Model.TrackedPage - 1)" class="btn btn-secondary">← Prev</a>
}
@if (Model.TrackedPage < Model.TrackedTotalPages)
{
<a href="@Model.GetTrackedPageUrl(Model.TrackedPage + 1)" class="btn btn-secondary">Next →</a>
}
</div>
</div>
}
}
</div>
@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 z-50">
@Model.Message
</div>
}
@section Scripts {
<script>
function copyPath(path) {
navigator.clipboard.writeText(path).then(() => {
const toast = document.createElement('div');
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);
});
}
</script>
}