Admin v10
This commit is contained in:
@@ -10,183 +10,289 @@
|
||||
<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 and manage client assets</p>
|
||||
<p class="text-gray-400 mt-1">Browse CDN and manage tracked assets</p>
|
||||
</div>
|
||||
<a href="/admin/assets/edit" class="btn btn-primary flex items-center gap-2">
|
||||
<svg class="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
||||
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 4v16m8-8H4"/>
|
||||
</svg>
|
||||
Add Asset
|
||||
</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>
|
||||
|
||||
<!-- Filters -->
|
||||
<div class="card p-4">
|
||||
<form method="get" class="flex flex-wrap items-end gap-4">
|
||||
<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..." />
|
||||
|
||||
@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>
|
||||
<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.TypeFilter == t)">@t</option>
|
||||
}
|
||||
</select>
|
||||
</div>
|
||||
<button type="submit" class="btn btn-secondary">Filter</button>
|
||||
<a href="/admin/assets" 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.TotalCount</p>
|
||||
<p class="text-sm text-gray-400">Total Assets</p>
|
||||
|
||||
<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">
|
||||
<p class="text-2xl font-bold text-indigo-400">@Model.TextureCount</p>
|
||||
<p class="text-sm text-gray-400">Textures</p>
|
||||
<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>
|
||||
<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-1 md:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4 gap-4">
|
||||
@foreach (var asset in Model.Assets)
|
||||
|
||||
<!-- Preview Grid for common textures -->
|
||||
@if (Model.Folder?.StartsWith("textures/") == true)
|
||||
{
|
||||
<div class="card overflow-hidden group">
|
||||
<!-- Preview -->
|
||||
<div class="h-32 bg-gray-900 flex items-center justify-center relative">
|
||||
@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-gray-600 text-center\'><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=\'M4 16l4.586-4.586a2 2 0 012.828 0L16 16m-2-2l1.586-1.586a2 2 0 012.828 0L20 14m-6-6h.01M6 20h12a2 2 0 002-2V6a2 2 0 00-2-2H6a2 2 0 00-2 2v12a2 2 0 002 2z\'/></svg><p class=\'text-xs mt-1\'>Failed to load</p></div>'" />
|
||||
}
|
||||
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;
|
||||
case ClientAssetType.Audio:
|
||||
<svg class="w-12 h-12 mx-auto text-purple-600" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
||||
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 19V6l12-3v13M9 19c0 1.105-1.343 2-3 2s-3-.895-3-2 1.343-2 3-2 3 .895 3 2zm12-3c0 1.105-1.343 2-3 2s-3-.895-3-2 1.343-2 3-2 3 .895 3 2zM9 10l12-3"/>
|
||||
</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>
|
||||
</div>
|
||||
}
|
||||
<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)
|
||||
{
|
||||
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>
|
||||
}
|
||||
</div>
|
||||
|
||||
<!-- Type badge -->
|
||||
<div class="absolute top-2 right-2">
|
||||
<span class="badge @(asset.AssetType == ClientAssetType.Texture ? "badge-rare" : asset.AssetType == ClientAssetType.Scene ? "badge-uncommon" : "badge-common")">
|
||||
@asset.AssetType
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Info -->
|
||||
<div class="p-3">
|
||||
<p class="text-sm text-white font-medium truncate" title="@asset.FilePath">
|
||||
@System.IO.Path.GetFileName(asset.FilePath)
|
||||
</p>
|
||||
<p class="text-xs text-gray-500 truncate" title="@asset.FilePath">
|
||||
@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="flex items-center gap-1 mt-2">
|
||||
@if (asset.IsRequired)
|
||||
{
|
||||
<span class="text-xs text-yellow-400">Required</span>
|
||||
}
|
||||
@if (!asset.IsEnabled)
|
||||
{
|
||||
<span class="text-xs text-red-400">Disabled</span>
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Actions (hidden until hover) -->
|
||||
<div class="border-t border-gray-700 p-2 flex justify-end gap-2 opacity-0 group-hover:opacity-100 transition-opacity">
|
||||
<a href="@Html.Raw(Model.CdnBaseUrl)/downloads/@asset.DownloadPath" target="_blank" class="p-1.5 hover:bg-gray-700 rounded text-gray-400" title="Download">
|
||||
<svg class="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
||||
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M4 16v1a3 3 0 003 3h10a3 3 0 003-3v-1m-4-4l-4 4m0 0l-4-4m4 4V4"/>
|
||||
</svg>
|
||||
</a>
|
||||
<button type="button" onclick="copyToClipboard('@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">
|
||||
<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 (!Model.PreviewFiles.Any())
|
||||
{
|
||||
<p class="text-gray-500 text-center py-8">
|
||||
Enter file names manually or check that assets exist at this CDN path.
|
||||
</p>
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
|
||||
@if (!Model.Assets.Any())
|
||||
{
|
||||
<div class="col-span-full card p-12 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="M4 16l4.586-4.586a2 2 0 012.828 0L16 16m-2-2l1.586-1.586a2 2 0 012.828 0L20 14m-6-6h.01M6 20h12a2 2 0 002-2V6a2 2 0 00-2-2H6a2 2 0 00-2 2v12a2 2 0 002 2z"/>
|
||||
</svg>
|
||||
<p class="text-gray-400 mt-4">No assets found.</p>
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
|
||||
<!-- Pagination -->
|
||||
@if (Model.TotalPages > 1)
|
||||
{
|
||||
<div class="flex items-center justify-between">
|
||||
<p class="text-sm text-gray-400">
|
||||
Showing @((Model.CurrentPage - 1) * Model.PageSize + 1)-@Math.Min(Model.CurrentPage * Model.PageSize, Model.TotalCount) of @Model.TotalCount
|
||||
</p>
|
||||
<div class="flex items-center gap-2">
|
||||
@if (Model.CurrentPage > 1)
|
||||
{
|
||||
<a href="@Model.GetPageUrl(Model.CurrentPage - 1)" class="btn btn-secondary">← Prev</a>
|
||||
}
|
||||
<span class="text-gray-400 px-2">@Model.CurrentPage / @Model.TotalPages</span>
|
||||
@if (Model.CurrentPage < Model.TotalPages)
|
||||
{
|
||||
<a href="@Model.GetPageUrl(Model.CurrentPage + 1)" class="btn btn-secondary">Next →</a>
|
||||
}
|
||||
</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 -->
|
||||
<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.TypeFilter == 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-1 md:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4 gap-4">
|
||||
@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">
|
||||
@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>'" />
|
||||
}
|
||||
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>
|
||||
</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>
|
||||
<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">
|
||||
<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">
|
||||
<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.TotalPages > 1)
|
||||
{
|
||||
<div class="flex items-center justify-between">
|
||||
<p class="text-sm text-gray-400">
|
||||
Page @Model.CurrentPage of @Model.TotalPages
|
||||
</p>
|
||||
<div class="flex items-center gap-2">
|
||||
@if (Model.CurrentPage > 1)
|
||||
{
|
||||
<a href="@Model.GetPageUrl(Model.CurrentPage - 1)" class="btn btn-secondary">← Prev</a>
|
||||
}
|
||||
@if (Model.CurrentPage < Model.TotalPages)
|
||||
{
|
||||
<a href="@Model.GetPageUrl(Model.CurrentPage + 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">
|
||||
@Model.Message
|
||||
</div>
|
||||
}
|
||||
|
||||
@functions {
|
||||
string FormatFileSize(long bytes)
|
||||
{
|
||||
@@ -198,10 +304,14 @@
|
||||
|
||||
@section Scripts {
|
||||
<script>
|
||||
function copyToClipboard(text) {
|
||||
navigator.clipboard.writeText(text).then(() => {
|
||||
// Show a quick toast or just change cursor briefly
|
||||
console.log('Copied:', text);
|
||||
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.textContent = 'Copied: ' + path;
|
||||
document.body.appendChild(toast);
|
||||
setTimeout(() => toast.remove(), 2000);
|
||||
});
|
||||
}
|
||||
</script>
|
||||
|
||||
@@ -2,6 +2,7 @@ using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Server.Data;
|
||||
using Server.Data.Entities;
|
||||
using System.Security.Cryptography;
|
||||
|
||||
namespace VoidScavengers.Services.Admin.Pages.Assets;
|
||||
|
||||
@@ -14,6 +15,21 @@ public class IndexModel : AdminPageModel
|
||||
_db = db;
|
||||
}
|
||||
|
||||
// Tab state
|
||||
[FromQuery(Name = "tab")]
|
||||
public string Tab { get; set; } = "browse";
|
||||
|
||||
// Browse tab
|
||||
[FromQuery(Name = "folder")]
|
||||
public string Folder { get; set; } = "textures/items";
|
||||
|
||||
[FromQuery(Name = "files")]
|
||||
public string? FileList { get; set; }
|
||||
|
||||
public List<string> PreviewFiles { get; set; } = new();
|
||||
public HashSet<string> TrackedPaths { get; set; } = new();
|
||||
|
||||
// Tracked tab
|
||||
public List<ClientAsset> Assets { get; set; } = new();
|
||||
|
||||
[FromQuery(Name = "search")]
|
||||
@@ -26,18 +42,22 @@ public class IndexModel : AdminPageModel
|
||||
public int CurrentPage { get; set; } = 1;
|
||||
|
||||
public int PageSize { get; set; } = 24;
|
||||
public int TotalCount { get; set; }
|
||||
public int TotalPages => (int)Math.Ceiling(TotalCount / (double)PageSize);
|
||||
public int TotalPages { get; set; }
|
||||
|
||||
// Stats
|
||||
public int TrackedCount { get; set; }
|
||||
public int TextureCount { get; set; }
|
||||
public int SceneCount { get; set; }
|
||||
public int ScriptCount { get; set; }
|
||||
|
||||
public string CdnBaseUrl { get; set; } = "https://assets.aeternalisgames.com";
|
||||
|
||||
public string? Message { get; set; }
|
||||
public bool IsError { get; set; }
|
||||
|
||||
public string GetPageUrl(int page)
|
||||
{
|
||||
var parts = new List<string> { $"page={page}" };
|
||||
var parts = new List<string> { $"tab=tracked", $"page={page}" };
|
||||
if (!string.IsNullOrEmpty(Search)) parts.Add($"search={Uri.EscapeDataString(Search)}");
|
||||
if (TypeFilter.HasValue) parts.Add($"type={TypeFilter}");
|
||||
return "/admin/assets?" + string.Join("&", parts);
|
||||
@@ -45,30 +65,129 @@ public class IndexModel : AdminPageModel
|
||||
|
||||
public async Task OnGetAsync()
|
||||
{
|
||||
if (CurrentPage < 1) CurrentPage = 1;
|
||||
|
||||
var cdnUrl = Environment.GetEnvironmentVariable("CDN_BASE_URL");
|
||||
if (!string.IsNullOrEmpty(cdnUrl)) CdnBaseUrl = cdnUrl;
|
||||
|
||||
// Stats
|
||||
TrackedCount = await _db.ClientAssets.CountAsync();
|
||||
TextureCount = await _db.ClientAssets.CountAsync(a => a.AssetType == ClientAssetType.Texture);
|
||||
SceneCount = await _db.ClientAssets.CountAsync(a => a.AssetType == ClientAssetType.Scene);
|
||||
ScriptCount = await _db.ClientAssets.CountAsync(a => a.AssetType == ClientAssetType.Script);
|
||||
|
||||
// Get tracked paths for comparison
|
||||
TrackedPaths = (await _db.ClientAssets.Select(a => a.FilePath).ToListAsync()).ToHashSet();
|
||||
|
||||
var query = _db.ClientAssets.AsQueryable();
|
||||
if (Tab == "browse")
|
||||
{
|
||||
// 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();
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// Tracked assets tab
|
||||
if (CurrentPage < 1) CurrentPage = 1;
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(Search))
|
||||
query = query.Where(a => a.FilePath.Contains(Search));
|
||||
var query = _db.ClientAssets.AsQueryable();
|
||||
|
||||
if (TypeFilter.HasValue)
|
||||
query = query.Where(a => a.AssetType == TypeFilter.Value);
|
||||
if (!string.IsNullOrWhiteSpace(Search))
|
||||
query = query.Where(a => a.FilePath.Contains(Search));
|
||||
|
||||
TotalCount = await query.CountAsync();
|
||||
if (TypeFilter.HasValue)
|
||||
query = query.Where(a => a.AssetType == TypeFilter.Value);
|
||||
|
||||
Assets = await query
|
||||
.OrderByDescending(a => a.UpdatedAt)
|
||||
.Skip((CurrentPage - 1) * PageSize)
|
||||
.Take(PageSize)
|
||||
.ToListAsync();
|
||||
var total = await query.CountAsync();
|
||||
TotalPages = (int)Math.Ceiling(total / (double)PageSize);
|
||||
|
||||
Assets = await query
|
||||
.OrderByDescending(a => a.UpdatedAt)
|
||||
.Skip((CurrentPage - 1) * PageSize)
|
||||
.Take(PageSize)
|
||||
.ToListAsync();
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<IActionResult> OnPostRegisterAssetAsync(string filePath, ClientAssetType assetType)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(filePath))
|
||||
{
|
||||
Message = "File path is required.";
|
||||
IsError = true;
|
||||
return RedirectToPage(new { tab = Tab, folder = Folder });
|
||||
}
|
||||
|
||||
// Normalize path
|
||||
filePath = filePath.Trim().Replace("\\", "/");
|
||||
if (filePath.StartsWith("/")) filePath = filePath.Substring(1);
|
||||
|
||||
// Check if already tracked
|
||||
var existing = await _db.ClientAssets.FirstOrDefaultAsync(a => a.FilePath == filePath);
|
||||
if (existing != null)
|
||||
{
|
||||
Message = $"Asset '{filePath}' is already tracked.";
|
||||
IsError = true;
|
||||
return RedirectToPage(new { tab = Tab, folder = Folder });
|
||||
}
|
||||
|
||||
// Create new asset tracking entry
|
||||
var asset = new ClientAsset
|
||||
{
|
||||
FilePath = filePath,
|
||||
AssetType = assetType,
|
||||
FileHash = GenerateHash(filePath), // Placeholder hash based on path
|
||||
FileSize = 0, // Unknown without actually fetching the file
|
||||
Version = 1,
|
||||
IsRequired = false,
|
||||
IsEnabled = true,
|
||||
CreatedAt = DateTime.UtcNow,
|
||||
UpdatedAt = DateTime.UtcNow
|
||||
};
|
||||
|
||||
_db.ClientAssets.Add(asset);
|
||||
await _db.SaveChangesAsync();
|
||||
|
||||
Message = $"Asset '{filePath}' registered successfully.";
|
||||
return RedirectToPage(new { tab = Tab, folder = Folder });
|
||||
}
|
||||
|
||||
public async Task<IActionResult> OnPostDeleteAssetAsync(int assetId)
|
||||
{
|
||||
var asset = await _db.ClientAssets.FindAsync(assetId);
|
||||
if (asset != null)
|
||||
{
|
||||
_db.ClientAssets.Remove(asset);
|
||||
await _db.SaveChangesAsync();
|
||||
Message = $"Asset '{asset.FilePath}' untracked.";
|
||||
}
|
||||
return RedirectToPage(new { tab = "tracked" });
|
||||
}
|
||||
|
||||
private string GenerateHash(string input)
|
||||
{
|
||||
using var md5 = MD5.Create();
|
||||
var bytes = System.Text.Encoding.UTF8.GetBytes(input + DateTime.UtcNow.Ticks);
|
||||
var hash = md5.ComputeHash(bytes);
|
||||
return Convert.ToHexString(hash).ToLower();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -281,7 +281,7 @@
|
||||
|
||||
@section Scripts {
|
||||
<script>
|
||||
const cdnBase = '@Html.Raw(Model.CdnBaseUrl)';
|
||||
const cdnBase = '@Html.Raw(Model.CdnBaseUrl)/downloads';
|
||||
|
||||
function updatePreview() {
|
||||
const path = document.getElementById('spritePath').value;
|
||||
|
||||
@@ -75,7 +75,7 @@
|
||||
<td class="table-cell">
|
||||
@if (!string.IsNullOrEmpty(item.SpritePath))
|
||||
{
|
||||
<img src="@Html.Raw(Model.CdnBaseUrl)/@item.SpritePath"
|
||||
<img src="@Html.Raw(Model.CdnBaseUrl)/downloads/@item.SpritePath"
|
||||
alt="@item.Name"
|
||||
class="w-10 h-10 object-contain bg-gray-900 rounded border border-gray-700"
|
||||
onerror="this.style.display='none'" />
|
||||
|
||||
@@ -122,7 +122,7 @@
|
||||
<td class="table-cell">
|
||||
@if (entry.ItemDefinition != null && !string.IsNullOrEmpty(entry.ItemDefinition.SpritePath))
|
||||
{
|
||||
<img src="@Html.Raw(Model.CdnBaseUrl)/@entry.ItemDefinition.SpritePath"
|
||||
<img src="@Html.Raw(Model.CdnBaseUrl)/downloads/@entry.ItemDefinition.SpritePath"
|
||||
alt="@entry.ItemDefinition.Name"
|
||||
class="w-8 h-8 object-contain bg-gray-900 rounded border border-gray-700"
|
||||
onerror="this.style.display='none'" />
|
||||
|
||||
@@ -142,7 +142,7 @@
|
||||
{
|
||||
@if (ingredient.ItemDefinition != null && !string.IsNullOrEmpty(ingredient.ItemDefinition.SpritePath))
|
||||
{
|
||||
<img src="@Html.Raw(Model.CdnBaseUrl)/@ingredient.ItemDefinition.SpritePath"
|
||||
<img src="@Html.Raw(Model.CdnBaseUrl)/downloads/@ingredient.ItemDefinition.SpritePath"
|
||||
class="w-10 h-10 object-contain"
|
||||
onerror="this.style.display='none'" />
|
||||
}
|
||||
@@ -178,7 +178,7 @@
|
||||
<div class="w-20 h-20 bg-gray-800 rounded-lg border-2 border-indigo-600 flex items-center justify-center relative">
|
||||
@if (Model.Recipe.OutputItem != null && !string.IsNullOrEmpty(Model.Recipe.OutputItem.SpritePath))
|
||||
{
|
||||
<img src="@Html.Raw(Model.CdnBaseUrl)/@Model.Recipe.OutputItem.SpritePath"
|
||||
<img src="@Html.Raw(Model.CdnBaseUrl)/downloads/@Model.Recipe.OutputItem.SpritePath"
|
||||
class="w-14 h-14 object-contain" />
|
||||
}
|
||||
else
|
||||
@@ -213,7 +213,7 @@
|
||||
<td class="table-cell">
|
||||
@if (ing.ItemDefinition != null && !string.IsNullOrEmpty(ing.ItemDefinition.SpritePath))
|
||||
{
|
||||
<img src="@Html.Raw(Model.CdnBaseUrl)/@ing.ItemDefinition.SpritePath"
|
||||
<img src="@Html.Raw(Model.CdnBaseUrl)/downloads/@ing.ItemDefinition.SpritePath"
|
||||
class="w-8 h-8 object-contain bg-gray-900 rounded" />
|
||||
}
|
||||
</td>
|
||||
|
||||
@@ -76,7 +76,7 @@
|
||||
<div class="flex items-center gap-2">
|
||||
@if (!string.IsNullOrEmpty(recipe.OutputItem.SpritePath))
|
||||
{
|
||||
<img src="@Html.Raw(Model.CdnBaseUrl)/@recipe.OutputItem.SpritePath"
|
||||
<img src="@Html.Raw(Model.CdnBaseUrl)/downloads/@recipe.OutputItem.SpritePath"
|
||||
class="w-8 h-8 object-contain bg-gray-900 rounded"
|
||||
onerror="this.style.display='none'" />
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user