Files
systemrevivalserver/Services/Admin/Pages/Assets/Index.cshtml
T
2025-12-24 20:34:48 -05:00

211 lines
10 KiB
Plaintext

@page "/admin/assets"
@model VoidScavengers.Admin.Pages.Assets.IndexModel
@{
ViewData["Title"] = "CDN Assets";
}
<div class="space-y-6">
<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 assets from your CDN</p>
</div>
<a href="/admin/assets/sync" class="btn btn-secondary 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="M4 4v5h.582m15.356 2A8.001 8.001 0 004.582 9m0 0H9m11 11v-5h-.581m0 0a8.003 8.003 0 01-15.357-2m15.357 2H15"/>
</svg>
Sync from CDN
</a>
</div>
<!-- CDN Info -->
<div class="card p-4">
<div class="flex items-center gap-4">
<div class="p-3 bg-indigo-600/20 rounded-lg">
<svg class="w-6 h-6 text-indigo-500" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M3 15a4 4 0 004 4h9a5 5 0 10-.1-9.999 5.002 5.002 0 10-9.78 2.096A4.001 4.001 0 003 15z"/>
</svg>
</div>
<div>
<p class="text-sm text-gray-400">CDN Base URL</p>
<p class="text-white font-mono">@Model.CdnBaseUrl</p>
</div>
<div class="ml-auto text-right">
<p class="text-sm text-gray-400">Registered Assets</p>
<p class="text-2xl font-bold text-white">@Model.AssetCount</p>
</div>
</div>
</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..." />
</div>
<div class="w-48">
<label class="label">Type</label>
<select name="type" class="input">
<option value="">All Types</option>
<option value="sprite" selected="@(Model.TypeFilter == "sprite")">Sprites</option>
<option value="scene" selected="@(Model.TypeFilter == "scene")">Scenes</option>
<option value="script" selected="@(Model.TypeFilter == "script")">Scripts</option>
<option value="audio" selected="@(Model.TypeFilter == "audio")">Audio</option>
</select>
</div>
<button type="submit" class="btn btn-secondary">Filter</button>
<a href="/admin/assets" class="btn btn-secondary">Clear</a>
</form>
</div>
<!-- Assets Grid -->
<div class="grid grid-cols-2 md:grid-cols-4 lg:grid-cols-6 gap-4">
@foreach (var asset in Model.Assets)
{
<div class="card p-3 hover:border-indigo-500 transition-colors cursor-pointer group"
onclick="showAssetDetails('@asset.FilePath.Replace("'", "\\'")}')" >
<div class="aspect-square bg-gray-900 rounded-lg flex items-center justify-center mb-2 overflow-hidden">
@if (asset.AssetType == Server.Data.Entities.ClientAssetType.Texture)
{
<img src="@Model.CdnBaseUrl/@asset.DownloadPath"
alt="@asset.FilePath"
class="max-w-full max-h-full object-contain"
onerror="this.style.display='none'; this.nextElementSibling.style.display='flex'" />
<div class="hidden items-center justify-center text-gray-600">
<svg class="w-8 h-8" 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>
</div>
}
else if (asset.AssetType == Server.Data.Entities.ClientAssetType.Scene)
{
<svg class="w-12 h-12 text-purple-500" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M4 5a1 1 0 011-1h14a1 1 0 011 1v2a1 1 0 01-1 1H5a1 1 0 01-1-1V5zM4 13a1 1 0 011-1h6a1 1 0 011 1v6a1 1 0 01-1 1H5a1 1 0 01-1-1v-6zM16 13a1 1 0 011-1h2a1 1 0 011 1v6a1 1 0 01-1 1h-2a1 1 0 01-1-1v-6z"/>
</svg>
}
else if (asset.AssetType == Server.Data.Entities.ClientAssetType.Script)
{
<svg class="w-12 h-12 text-blue-500" 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>
}
else
{
<svg class="w-12 h-12 text-gray-600" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M7 21h10a2 2 0 002-2V9.414a1 1 0 00-.293-.707l-5.414-5.414A1 1 0 0012.586 3H7a2 2 0 00-2 2v14a2 2 0 002 2z"/>
</svg>
}
</div>
<p class="text-xs text-gray-400 truncate" title="@asset.FilePath">@System.IO.Path.GetFileName(asset.FilePath)</p>
</div>
}
@if (!Model.Assets.Any())
{
<div class="col-span-full card p-8 text-center">
<p class="text-gray-500">No assets found.</p>
<p class="text-gray-600 text-sm mt-2">Assets are registered in the client_assets table.</p>
</div>
}
</div>
<!-- Pagination -->
@if (Model.TotalPages > 1)
{
<div class="flex items-center justify-between">
<p class="text-sm text-gray-400">
Showing @((Model.Page - 1) * Model.PageSize + 1) to @Math.Min(Model.Page * Model.PageSize, Model.TotalCount) of @Model.TotalCount assets
</p>
<div class="flex items-center gap-2">
@if (Model.Page > 1)
{
<a href="/admin/assets?page=@(Model.Page - 1)&search=@Model.Search&type=@Model.TypeFilter" class="btn btn-secondary">Previous</a>
}
<span class="text-gray-400">Page @Model.Page of @Model.TotalPages</span>
@if (Model.Page < Model.TotalPages)
{
<a href="/admin/assets?page=@(Model.Page + 1)&search=@Model.Search&type=@Model.TypeFilter" class="btn btn-secondary">Next</a>
}
</div>
</div>
}
</div>
<!-- Asset Details Modal -->
<div id="assetModal" class="fixed inset-0 bg-black/50 hidden items-center justify-center z-50">
<div class="bg-gray-800 rounded-xl p-6 max-w-2xl w-full mx-4 border border-gray-700 max-h-[80vh] overflow-auto">
<div class="flex items-center justify-between mb-4">
<h3 class="text-lg font-semibold text-white">Asset Details</h3>
<button onclick="closeAssetModal()" class="text-gray-400 hover:text-white">
<svg class="w-6 h-6" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M6 18L18 6M6 6l12 12"/>
</svg>
</button>
</div>
<div id="assetModalContent">
<!-- Filled by JS -->
</div>
</div>
</div>
@section Scripts {
<script>
const cdnBaseUrl = '@Model.CdnBaseUrl';
function showAssetDetails(path) {
const modal = document.getElementById('assetModal');
const content = document.getElementById('assetModalContent');
const isImage = /\.(png|jpg|jpeg|webp|gif)$/i.test(path);
content.innerHTML = `
<div class="space-y-4">
${isImage ? `
<div class="bg-gray-900 rounded-lg p-4 flex items-center justify-center">
<img src="${cdnBaseUrl}/${path}" alt="${path}" class="max-w-full max-h-64 object-contain" />
</div>
` : ''}
<div>
<p class="text-sm text-gray-400">Path</p>
<p class="text-white font-mono text-sm break-all">${path}</p>
</div>
<div>
<p class="text-sm text-gray-400">Full URL</p>
<p class="text-indigo-400 font-mono text-sm break-all">
<a href="${cdnBaseUrl}/${path}" target="_blank">${cdnBaseUrl}/${path}</a>
</p>
</div>
<div class="flex gap-2">
<button onclick="copyToClipboard('${path}')" class="btn btn-secondary flex-1">
Copy Path
</button>
<button onclick="copyToClipboard('${cdnBaseUrl}/${path}')" class="btn btn-secondary flex-1">
Copy URL
</button>
</div>
</div>
`;
modal.classList.remove('hidden');
modal.classList.add('flex');
}
function closeAssetModal() {
const modal = document.getElementById('assetModal');
modal.classList.add('hidden');
modal.classList.remove('flex');
}
function copyToClipboard(text) {
navigator.clipboard.writeText(text).then(() => {
alert('Copied to clipboard!');
});
}
document.addEventListener('keydown', (e) => {
if (e.key === 'Escape') closeAssetModal();
});
</script>
}