CDN Integration for Admin
This commit is contained in:
@@ -0,0 +1,75 @@
|
|||||||
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
using Server.Services;
|
||||||
|
|
||||||
|
namespace Server.Api;
|
||||||
|
|
||||||
|
[ApiController]
|
||||||
|
[Route("api/admin/cdn")]
|
||||||
|
public class CdnBrowserController : ControllerBase
|
||||||
|
{
|
||||||
|
private readonly ICdnBrowserService _cdnService;
|
||||||
|
|
||||||
|
public CdnBrowserController(ICdnBrowserService cdnService)
|
||||||
|
{
|
||||||
|
_cdnService = cdnService;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Check if CDN browsing is configured
|
||||||
|
/// </summary>
|
||||||
|
[HttpGet("status")]
|
||||||
|
public IActionResult GetStatus()
|
||||||
|
{
|
||||||
|
return Ok(new {
|
||||||
|
configured = _cdnService.IsConfigured,
|
||||||
|
message = _cdnService.IsConfigured
|
||||||
|
? "MinIO configured and ready"
|
||||||
|
: "MinIO not configured - set AccessKey and SecretKey in appsettings"
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// List files in a CDN prefix/folder
|
||||||
|
/// </summary>
|
||||||
|
[HttpGet("list")]
|
||||||
|
public async Task<IActionResult> ListFiles(
|
||||||
|
[FromQuery] string prefix = "textures/items",
|
||||||
|
[FromQuery] int maxKeys = 100)
|
||||||
|
{
|
||||||
|
if (!_cdnService.IsConfigured)
|
||||||
|
{
|
||||||
|
return Ok(new {
|
||||||
|
files = new List<CdnFile>(),
|
||||||
|
error = "MinIO not configured"
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
var files = await _cdnService.ListFilesAsync(prefix, maxKeys);
|
||||||
|
return Ok(new {
|
||||||
|
prefix,
|
||||||
|
files,
|
||||||
|
count = files.Count
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// List subfolders in a prefix
|
||||||
|
/// </summary>
|
||||||
|
[HttpGet("folders")]
|
||||||
|
public async Task<IActionResult> ListFolders([FromQuery] string prefix = "textures")
|
||||||
|
{
|
||||||
|
if (!_cdnService.IsConfigured)
|
||||||
|
{
|
||||||
|
return Ok(new {
|
||||||
|
folders = new List<string>(),
|
||||||
|
error = "MinIO not configured"
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
var folders = await _cdnService.ListPrefixesAsync(prefix);
|
||||||
|
return Ok(new {
|
||||||
|
prefix,
|
||||||
|
folders
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
+1
-1
@@ -83,7 +83,7 @@ builder.Services.AddSingleton<MessageRouter>();
|
|||||||
|
|
||||||
builder.Services.AddSingleton<IItemService, CachedItemService>();
|
builder.Services.AddSingleton<IItemService, CachedItemService>();
|
||||||
builder.Services.AddSingleton<IAdminAuthService, AdminAuthService>();
|
builder.Services.AddSingleton<IAdminAuthService, AdminAuthService>();
|
||||||
|
builder.Services.AddSingleton<ICdnBrowserService, MinioCdnBrowserService>();
|
||||||
|
|
||||||
// Health checks
|
// Health checks
|
||||||
builder.Services.AddHealthChecks()
|
builder.Services.AddHealthChecks()
|
||||||
|
|||||||
@@ -10,7 +10,7 @@
|
|||||||
<div class="flex items-center justify-between">
|
<div class="flex items-center justify-between">
|
||||||
<div>
|
<div>
|
||||||
<h1 class="text-3xl font-bold text-white">CDN Assets</h1>
|
<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>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@@ -26,126 +26,165 @@
|
|||||||
|
|
||||||
@if (Model.Tab == "browse")
|
@if (Model.Tab == "browse")
|
||||||
{
|
{
|
||||||
<!-- CDN Browser -->
|
@if (!Model.CdnConfigured)
|
||||||
<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)
|
|
||||||
{
|
{
|
||||||
<div class="card">
|
<div class="card p-6 text-center">
|
||||||
<div class="p-4 border-b border-gray-700">
|
<svg class="w-16 h-16 mx-auto text-yellow-500 mb-4" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
||||||
<h2 class="text-lg font-semibold text-white">Preview - @Model.Folder</h2>
|
<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"/>
|
||||||
<p class="text-sm text-gray-500">Click an image to copy its path, or use the register button to track it.</p>
|
</svg>
|
||||||
</div>
|
<h3 class="text-xl font-semibold text-white mb-2">MinIO Not Configured</h3>
|
||||||
<div class="p-4">
|
<p class="text-gray-400 mb-4">To browse CDN files, configure MinIO credentials in appsettings.json:</p>
|
||||||
<div class="grid grid-cols-4 md:grid-cols-6 lg:grid-cols-8 xl:grid-cols-10 gap-2">
|
<pre class="bg-gray-900 p-4 rounded text-left text-sm text-gray-300 max-w-md mx-auto">"MinIO": {
|
||||||
@foreach (var file in Model.PreviewFiles)
|
"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);
|
<a href="/admin/assets?tab=browse&prefix=@Uri.EscapeDataString(folder)"
|
||||||
<div class="relative group">
|
class="btn @(Model.Prefix == folder ? "btn-primary" : "btn-secondary") text-sm">
|
||||||
<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">
|
@folder.TrimEnd('/').Split('/').Last()
|
||||||
<img src="@Html.Raw(Model.CdnBaseUrl)/downloads/@file"
|
</a>
|
||||||
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>
|
</div>
|
||||||
|
</div>
|
||||||
@if (!Model.PreviewFiles.Any())
|
|
||||||
|
<!-- 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">
|
currentPath += part + "/";
|
||||||
Enter file names manually or check that assets exist at this CDN path.
|
<span class="text-gray-600">/</span>
|
||||||
</p>
|
<a href="/admin/assets?tab=browse&prefix=@Uri.EscapeDataString(currentPath)" class="text-indigo-400 hover:underline">@part</a>
|
||||||
}
|
}
|
||||||
</div>
|
</div>
|
||||||
</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
|
else
|
||||||
{
|
{
|
||||||
<!-- Tracked Assets -->
|
<!-- Tracked Assets Tab -->
|
||||||
<div class="card p-4">
|
<div class="card p-4">
|
||||||
<form method="get" class="flex flex-wrap items-end gap-4">
|
<form method="get" class="flex flex-wrap items-end gap-4">
|
||||||
<input type="hidden" name="tab" value="tracked" />
|
<input type="hidden" name="tab" value="tracked" />
|
||||||
@@ -159,7 +198,7 @@
|
|||||||
<option value="">All Types</option>
|
<option value="">All Types</option>
|
||||||
@foreach (var t in Enum.GetValues<ClientAssetType>())
|
@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>
|
</select>
|
||||||
</div>
|
</div>
|
||||||
@@ -189,65 +228,44 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- Assets Grid -->
|
<!-- 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)
|
@foreach (var asset in Model.Assets)
|
||||||
{
|
{
|
||||||
<div class="card overflow-hidden group">
|
<div class="card overflow-hidden group relative">
|
||||||
<div class="h-32 bg-gray-900 flex items-center justify-center relative">
|
<div class="aspect-square bg-gray-900 flex items-center justify-center">
|
||||||
@if (asset.AssetType == ClientAssetType.Texture)
|
@if (asset.AssetType == ClientAssetType.Texture)
|
||||||
{
|
{
|
||||||
<img src="@Html.Raw(Model.CdnBaseUrl)/downloads/@asset.DownloadPath"
|
<img src="@Html.Raw(Model.CdnBaseUrl)/downloads/@asset.DownloadPath"
|
||||||
alt="@asset.FilePath"
|
alt="@asset.FilePath"
|
||||||
class="max-h-full max-w-full object-contain"
|
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
|
else
|
||||||
{
|
{
|
||||||
<div class="text-gray-600 text-center">
|
<div class="text-gray-600 text-center">
|
||||||
@switch (asset.AssetType)
|
<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"/>
|
||||||
case ClientAssetType.Scene:
|
</svg>
|
||||||
<svg class="w-12 h-12 mx-auto text-green-600" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
<p class="text-xs">@asset.AssetType</p>
|
||||||
<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>
|
||||||
}
|
}
|
||||||
<div class="absolute top-2 right-2">
|
|
||||||
<span class="badge badge-common text-xs">@asset.AssetType</span>
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
<div class="p-3">
|
<div class="p-2">
|
||||||
<p class="text-sm text-white font-medium truncate">@System.IO.Path.GetFileName(asset.FilePath)</p>
|
<p class="text-xs text-white truncate" title="@asset.FilePath">@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>
|
||||||
<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">
|
<!-- Hover actions -->
|
||||||
<svg class="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
<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"/>
|
<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>
|
</svg>
|
||||||
</button>
|
</button>
|
||||||
<form method="post" asp-page-handler="DeleteAsset" class="inline">
|
<form method="post" asp-page-handler="DeleteAsset" class="inline">
|
||||||
@Html.AntiForgeryToken()
|
@Html.AntiForgeryToken()
|
||||||
<input type="hidden" name="assetId" value="@asset.Id" />
|
<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?')">
|
<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" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
<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"/>
|
<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>
|
</svg>
|
||||||
</button>
|
</button>
|
||||||
@@ -265,20 +283,20 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- Pagination -->
|
<!-- Pagination -->
|
||||||
@if (Model.TotalPages > 1)
|
@if (Model.TrackedTotalPages > 1)
|
||||||
{
|
{
|
||||||
<div class="flex items-center justify-between">
|
<div class="flex items-center justify-between">
|
||||||
<p class="text-sm text-gray-400">
|
<p class="text-sm text-gray-400">
|
||||||
Page @Model.CurrentPage of @Model.TotalPages
|
Page @Model.TrackedPage of @Model.TrackedTotalPages
|
||||||
</p>
|
</p>
|
||||||
<div class="flex items-center gap-2">
|
<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>
|
||||||
</div>
|
</div>
|
||||||
@@ -288,27 +306,17 @@
|
|||||||
|
|
||||||
@if (!string.IsNullOrEmpty(Model.Message))
|
@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
|
@Model.Message
|
||||||
</div>
|
</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 {
|
@section Scripts {
|
||||||
<script>
|
<script>
|
||||||
function copyPath(path) {
|
function copyPath(path) {
|
||||||
navigator.clipboard.writeText(path).then(() => {
|
navigator.clipboard.writeText(path).then(() => {
|
||||||
// Quick visual feedback
|
|
||||||
const toast = document.createElement('div');
|
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;
|
toast.textContent = 'Copied: ' + path;
|
||||||
document.body.appendChild(toast);
|
document.body.appendChild(toast);
|
||||||
setTimeout(() => toast.remove(), 2000);
|
setTimeout(() => toast.remove(), 2000);
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ using Microsoft.AspNetCore.Mvc;
|
|||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
using Server.Data;
|
using Server.Data;
|
||||||
using Server.Data.Entities;
|
using Server.Data.Entities;
|
||||||
|
using Server.Services;
|
||||||
using System.Security.Cryptography;
|
using System.Security.Cryptography;
|
||||||
|
|
||||||
namespace VoidScavengers.Services.Admin.Pages.Assets;
|
namespace VoidScavengers.Services.Admin.Pages.Assets;
|
||||||
@@ -9,10 +10,12 @@ namespace VoidScavengers.Services.Admin.Pages.Assets;
|
|||||||
public class IndexModel : AdminPageModel
|
public class IndexModel : AdminPageModel
|
||||||
{
|
{
|
||||||
private readonly GameDbContext _db;
|
private readonly GameDbContext _db;
|
||||||
|
private readonly ICdnBrowserService _cdnService;
|
||||||
|
|
||||||
public IndexModel(GameDbContext db)
|
public IndexModel(GameDbContext db, ICdnBrowserService cdnService)
|
||||||
{
|
{
|
||||||
_db = db;
|
_db = db;
|
||||||
|
_cdnService = cdnService;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Tab state
|
// Tab state
|
||||||
@@ -20,29 +23,36 @@ public class IndexModel : AdminPageModel
|
|||||||
public string Tab { get; set; } = "browse";
|
public string Tab { get; set; } = "browse";
|
||||||
|
|
||||||
// Browse tab
|
// Browse tab
|
||||||
[FromQuery(Name = "folder")]
|
[FromQuery(Name = "prefix")]
|
||||||
public string Folder { get; set; } = "textures/items";
|
public string? Prefix { get; set; }
|
||||||
|
|
||||||
[FromQuery(Name = "files")]
|
public bool CdnConfigured => _cdnService.IsConfigured;
|
||||||
public string? FileList { get; set; }
|
public List<CdnFile> Files { get; set; } = new();
|
||||||
|
public List<string> Subfolders { get; set; } = new();
|
||||||
public List<string> PreviewFiles { get; set; } = new();
|
public List<string> AvailableFolders { get; set; } = new()
|
||||||
public HashSet<string> TrackedPaths { get; set; } = new();
|
{
|
||||||
|
"textures/items/",
|
||||||
|
"textures/mobs/",
|
||||||
|
"textures/objects/",
|
||||||
|
"textures/spells/",
|
||||||
|
"textures/ui/",
|
||||||
|
"scenes/mobs/"
|
||||||
|
};
|
||||||
|
|
||||||
// Tracked tab
|
// Tracked tab
|
||||||
public List<ClientAsset> Assets { get; set; } = new();
|
|
||||||
|
|
||||||
[FromQuery(Name = "search")]
|
[FromQuery(Name = "search")]
|
||||||
public string? Search { get; set; }
|
public string? Search { get; set; }
|
||||||
|
|
||||||
[FromQuery(Name = "type")]
|
[FromQuery(Name = "type")]
|
||||||
public ClientAssetType? TypeFilter { get; set; }
|
public ClientAssetType? AssetTypeFilter { get; set; }
|
||||||
|
|
||||||
[FromQuery(Name = "page")]
|
[FromQuery(Name = "tpage")]
|
||||||
public int CurrentPage { get; set; } = 1;
|
public int TrackedPage { get; set; } = 1;
|
||||||
|
|
||||||
public int PageSize { get; set; } = 24;
|
public List<ClientAsset> Assets { get; set; } = new();
|
||||||
public int TotalPages { get; set; }
|
public int TrackedTotalPages { get; set; }
|
||||||
|
|
||||||
|
public HashSet<string> TrackedPaths { get; set; } = new();
|
||||||
|
|
||||||
// Stats
|
// Stats
|
||||||
public int TrackedCount { get; set; }
|
public int TrackedCount { get; set; }
|
||||||
@@ -50,16 +60,18 @@ public class IndexModel : AdminPageModel
|
|||||||
public int SceneCount { get; set; }
|
public int SceneCount { get; set; }
|
||||||
public int ScriptCount { get; set; }
|
public int ScriptCount { get; set; }
|
||||||
|
|
||||||
|
public int PageSize { get; set; } = 60;
|
||||||
|
|
||||||
public string CdnBaseUrl { get; set; } = "https://assets.aeternalisgames.com";
|
public string CdnBaseUrl { get; set; } = "https://assets.aeternalisgames.com";
|
||||||
|
|
||||||
public string? Message { get; set; }
|
public string? Message { get; set; }
|
||||||
public bool IsError { 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 (!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);
|
return "/admin/assets?" + string.Join("&", parts);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -77,64 +89,58 @@ public class IndexModel : AdminPageModel
|
|||||||
// Get tracked paths for comparison
|
// Get tracked paths for comparison
|
||||||
TrackedPaths = (await _db.ClientAssets.Select(a => a.FilePath).ToListAsync()).ToHashSet();
|
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
|
// Normalize prefix
|
||||||
if (!string.IsNullOrEmpty(FileList))
|
Prefix = Prefix?.TrimEnd('/');
|
||||||
{
|
if (!string.IsNullOrEmpty(Prefix))
|
||||||
var files = FileList.Split(',', StringSplitOptions.RemoveEmptyEntries | StringSplitOptions.TrimEntries);
|
Prefix += "/";
|
||||||
PreviewFiles = files.Select(f => $"{Folder}/{f}".Replace("//", "/")).ToList();
|
|
||||||
}
|
// List files from MinIO
|
||||||
else
|
var allItems = await _cdnService.ListFilesAsync(Prefix ?? "", 200);
|
||||||
{
|
|
||||||
// Default preview files - try common naming patterns
|
// Separate files and folders
|
||||||
// For items, try fb001.png through fb999.png pattern
|
Subfolders = allItems
|
||||||
if (Folder == "textures/items")
|
.Where(f => f.IsDirectory)
|
||||||
{
|
.Select(f => f.Key)
|
||||||
// Just show a few placeholder suggestions
|
.OrderBy(f => f)
|
||||||
PreviewFiles = Enumerable.Range(1, 50)
|
.ToList();
|
||||||
.Select(i => $"{Folder}/fb{i:D3}.png")
|
|
||||||
.ToList();
|
Files = allItems
|
||||||
}
|
.Where(f => !f.IsDirectory)
|
||||||
else if (Folder == "textures/mobs")
|
.OrderBy(f => f.Name)
|
||||||
{
|
.ToList();
|
||||||
// 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
|
else if (Tab == "tracked")
|
||||||
{
|
{
|
||||||
// Tracked assets tab
|
if (TrackedPage < 1) TrackedPage = 1;
|
||||||
if (CurrentPage < 1) CurrentPage = 1;
|
|
||||||
|
|
||||||
var query = _db.ClientAssets.AsQueryable();
|
var query = _db.ClientAssets.AsQueryable();
|
||||||
|
|
||||||
if (!string.IsNullOrWhiteSpace(Search))
|
if (!string.IsNullOrWhiteSpace(Search))
|
||||||
query = query.Where(a => a.FilePath.Contains(Search));
|
query = query.Where(a => a.FilePath.Contains(Search));
|
||||||
|
|
||||||
if (TypeFilter.HasValue)
|
if (AssetTypeFilter.HasValue)
|
||||||
query = query.Where(a => a.AssetType == TypeFilter.Value);
|
query = query.Where(a => a.AssetType == AssetTypeFilter.Value);
|
||||||
|
|
||||||
var total = await query.CountAsync();
|
var total = await query.CountAsync();
|
||||||
TotalPages = (int)Math.Ceiling(total / (double)PageSize);
|
TrackedTotalPages = (int)Math.Ceiling(total / (double)PageSize);
|
||||||
|
|
||||||
Assets = await query
|
Assets = await query
|
||||||
.OrderByDescending(a => a.UpdatedAt)
|
.OrderByDescending(a => a.UpdatedAt)
|
||||||
.Skip((CurrentPage - 1) * PageSize)
|
.Skip((TrackedPage - 1) * PageSize)
|
||||||
.Take(PageSize)
|
.Take(PageSize)
|
||||||
.ToListAsync();
|
.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))
|
if (string.IsNullOrWhiteSpace(filePath))
|
||||||
{
|
{
|
||||||
Message = "File path is required.";
|
Message = "File path is required.";
|
||||||
IsError = true;
|
IsError = true;
|
||||||
return RedirectToPage(new { tab = Tab, folder = Folder });
|
return RedirectToPage(new { tab = "browse", prefix = returnPrefix });
|
||||||
}
|
}
|
||||||
|
|
||||||
// Normalize path
|
// Normalize path
|
||||||
@@ -145,9 +151,9 @@ public class IndexModel : AdminPageModel
|
|||||||
var existing = await _db.ClientAssets.FirstOrDefaultAsync(a => a.FilePath == filePath);
|
var existing = await _db.ClientAssets.FirstOrDefaultAsync(a => a.FilePath == filePath);
|
||||||
if (existing != null)
|
if (existing != null)
|
||||||
{
|
{
|
||||||
Message = $"Asset '{filePath}' is already tracked.";
|
Message = $"Asset already tracked.";
|
||||||
IsError = true;
|
IsError = true;
|
||||||
return RedirectToPage(new { tab = Tab, folder = Folder });
|
return RedirectToPage(new { tab = "browse", prefix = returnPrefix });
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create new asset tracking entry
|
// Create new asset tracking entry
|
||||||
@@ -155,8 +161,8 @@ public class IndexModel : AdminPageModel
|
|||||||
{
|
{
|
||||||
FilePath = filePath,
|
FilePath = filePath,
|
||||||
AssetType = assetType,
|
AssetType = assetType,
|
||||||
FileHash = GenerateHash(filePath), // Placeholder hash based on path
|
FileHash = GenerateHash(filePath),
|
||||||
FileSize = 0, // Unknown without actually fetching the file
|
FileSize = fileSize,
|
||||||
Version = 1,
|
Version = 1,
|
||||||
IsRequired = false,
|
IsRequired = false,
|
||||||
IsEnabled = true,
|
IsEnabled = true,
|
||||||
@@ -167,8 +173,8 @@ public class IndexModel : AdminPageModel
|
|||||||
_db.ClientAssets.Add(asset);
|
_db.ClientAssets.Add(asset);
|
||||||
await _db.SaveChangesAsync();
|
await _db.SaveChangesAsync();
|
||||||
|
|
||||||
Message = $"Asset '{filePath}' registered successfully.";
|
Message = $"Asset registered.";
|
||||||
return RedirectToPage(new { tab = Tab, folder = Folder });
|
return RedirectToPage(new { tab = "browse", prefix = returnPrefix });
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<IActionResult> OnPostDeleteAssetAsync(int assetId)
|
public async Task<IActionResult> OnPostDeleteAssetAsync(int assetId)
|
||||||
@@ -178,7 +184,7 @@ public class IndexModel : AdminPageModel
|
|||||||
{
|
{
|
||||||
_db.ClientAssets.Remove(asset);
|
_db.ClientAssets.Remove(asset);
|
||||||
await _db.SaveChangesAsync();
|
await _db.SaveChangesAsync();
|
||||||
Message = $"Asset '{asset.FilePath}' untracked.";
|
Message = $"Asset untracked.";
|
||||||
}
|
}
|
||||||
return RedirectToPage(new { tab = "tracked" });
|
return RedirectToPage(new { tab = "tracked" });
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -49,6 +49,11 @@ public class EditModel : AdminPageModel
|
|||||||
Item.IsEnabled = Request.Form.ContainsKey("Item.IsEnabled");
|
Item.IsEnabled = Request.Form.ContainsKey("Item.IsEnabled");
|
||||||
Item.Stackable = Request.Form.ContainsKey("Item.Stackable");
|
Item.Stackable = Request.Form.ContainsKey("Item.Stackable");
|
||||||
Item.IsTeleportScroll = Request.Form.ContainsKey("Item.IsTeleportScroll");
|
Item.IsTeleportScroll = Request.Form.ContainsKey("Item.IsTeleportScroll");
|
||||||
|
|
||||||
|
// Ensure nullable strings are never null
|
||||||
|
Item.Description ??= "";
|
||||||
|
Item.SpritePath ??= "";
|
||||||
|
Item.TintColor ??= "#ffffff";
|
||||||
|
|
||||||
if (string.IsNullOrWhiteSpace(Item.Name))
|
if (string.IsNullOrWhiteSpace(Item.Name))
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -73,6 +73,9 @@ public class EditModel : AdminPageModel
|
|||||||
// Handle checkbox binding
|
// Handle checkbox binding
|
||||||
LootTable.IsEnabled = Request.Form.ContainsKey("LootTable.IsEnabled");
|
LootTable.IsEnabled = Request.Form.ContainsKey("LootTable.IsEnabled");
|
||||||
LootTable.GuaranteedDrop = Request.Form.ContainsKey("LootTable.GuaranteedDrop");
|
LootTable.GuaranteedDrop = Request.Form.ContainsKey("LootTable.GuaranteedDrop");
|
||||||
|
|
||||||
|
// Ensure Description is never null
|
||||||
|
LootTable.Description ??= "";
|
||||||
|
|
||||||
if (string.IsNullOrWhiteSpace(LootTable.Name))
|
if (string.IsNullOrWhiteSpace(LootTable.Name))
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -75,6 +75,10 @@ public class EditModel : AdminPageModel
|
|||||||
|
|
||||||
// Handle checkbox binding
|
// Handle checkbox binding
|
||||||
Mob.IsEnabled = Request.Form.ContainsKey("Mob.IsEnabled");
|
Mob.IsEnabled = Request.Form.ContainsKey("Mob.IsEnabled");
|
||||||
|
|
||||||
|
// Ensure nullable strings are never null
|
||||||
|
Mob.Description ??= "";
|
||||||
|
Mob.TintColor ??= "#ffffff";
|
||||||
|
|
||||||
if (string.IsNullOrWhiteSpace(Mob.Name))
|
if (string.IsNullOrWhiteSpace(Mob.Name))
|
||||||
{
|
{
|
||||||
@@ -90,7 +94,7 @@ public class EditModel : AdminPageModel
|
|||||||
var newMob = new DungeonMobDefinition
|
var newMob = new DungeonMobDefinition
|
||||||
{
|
{
|
||||||
Name = Mob.Name + " (Copy)",
|
Name = Mob.Name + " (Copy)",
|
||||||
Description = Mob.Description,
|
Description = Mob.Description ?? "",
|
||||||
Type = Mob.Type,
|
Type = Mob.Type,
|
||||||
Category = Mob.Category,
|
Category = Mob.Category,
|
||||||
MinTier = Mob.MinTier,
|
MinTier = Mob.MinTier,
|
||||||
|
|||||||
@@ -72,6 +72,9 @@ public class EditModel : AdminPageModel
|
|||||||
Recipe.IsEnabled = Request.Form.ContainsKey("Recipe.IsEnabled");
|
Recipe.IsEnabled = Request.Form.ContainsKey("Recipe.IsEnabled");
|
||||||
Recipe.IsBaseRecipe = Request.Form.ContainsKey("Recipe.IsBaseRecipe");
|
Recipe.IsBaseRecipe = Request.Form.ContainsKey("Recipe.IsBaseRecipe");
|
||||||
Recipe.HasStatRolls = Request.Form.ContainsKey("Recipe.HasStatRolls");
|
Recipe.HasStatRolls = Request.Form.ContainsKey("Recipe.HasStatRolls");
|
||||||
|
|
||||||
|
// Ensure Description is never null
|
||||||
|
Recipe.Description ??= "";
|
||||||
|
|
||||||
if (string.IsNullOrWhiteSpace(Recipe.Name))
|
if (string.IsNullOrWhiteSpace(Recipe.Name))
|
||||||
{
|
{
|
||||||
@@ -107,7 +110,7 @@ public class EditModel : AdminPageModel
|
|||||||
}
|
}
|
||||||
|
|
||||||
existing.Name = Recipe.Name;
|
existing.Name = Recipe.Name;
|
||||||
existing.Description = Recipe.Description;
|
existing.Description = Recipe.Description ?? "";
|
||||||
existing.SkillType = Recipe.SkillType;
|
existing.SkillType = Recipe.SkillType;
|
||||||
existing.RequiredLevel = Recipe.RequiredLevel;
|
existing.RequiredLevel = Recipe.RequiredLevel;
|
||||||
existing.OutputItemDefinitionId = Recipe.OutputItemDefinitionId;
|
existing.OutputItemDefinitionId = Recipe.OutputItemDefinitionId;
|
||||||
|
|||||||
@@ -0,0 +1,146 @@
|
|||||||
|
using Minio;
|
||||||
|
using Minio.DataModel.Args;
|
||||||
|
|
||||||
|
namespace Server.Services;
|
||||||
|
|
||||||
|
public class MinioConfig
|
||||||
|
{
|
||||||
|
public string Endpoint { get; set; } = "";
|
||||||
|
public string AccessKey { get; set; } = "";
|
||||||
|
public string SecretKey { get; set; } = "";
|
||||||
|
public string BucketName { get; set; } = "downloads";
|
||||||
|
public bool UseSSL { get; set; } = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public class CdnFile
|
||||||
|
{
|
||||||
|
public string Key { get; set; } = "";
|
||||||
|
public string Name { get; set; } = "";
|
||||||
|
public long Size { get; set; }
|
||||||
|
public DateTime LastModified { get; set; }
|
||||||
|
public bool IsDirectory { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public interface ICdnBrowserService
|
||||||
|
{
|
||||||
|
Task<List<CdnFile>> ListFilesAsync(string prefix, int maxKeys = 100, string? continuationToken = null);
|
||||||
|
Task<List<string>> ListPrefixesAsync(string prefix);
|
||||||
|
bool IsConfigured { get; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public class MinioCdnBrowserService : ICdnBrowserService
|
||||||
|
{
|
||||||
|
private readonly IMinioClient? _client;
|
||||||
|
private readonly MinioConfig _config;
|
||||||
|
private readonly ILogger<MinioCdnBrowserService> _logger;
|
||||||
|
|
||||||
|
public bool IsConfigured => !string.IsNullOrEmpty(_config.AccessKey) && !string.IsNullOrEmpty(_config.SecretKey);
|
||||||
|
|
||||||
|
public MinioCdnBrowserService(IConfiguration configuration, ILogger<MinioCdnBrowserService> logger)
|
||||||
|
{
|
||||||
|
_logger = logger;
|
||||||
|
_config = configuration.GetSection("MinIO").Get<MinioConfig>() ?? new MinioConfig();
|
||||||
|
|
||||||
|
if (IsConfigured)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
_client = new MinioClient()
|
||||||
|
.WithEndpoint(_config.Endpoint)
|
||||||
|
.WithCredentials(_config.AccessKey, _config.SecretKey)
|
||||||
|
.WithSSL(_config.UseSSL)
|
||||||
|
.Build();
|
||||||
|
|
||||||
|
_logger.LogInformation("MinIO client initialized for endpoint: {Endpoint}", _config.Endpoint);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Failed to initialize MinIO client");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_logger.LogWarning("MinIO not configured - CDN browsing disabled. Set MinIO:AccessKey and MinIO:SecretKey in appsettings.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task<List<CdnFile>> ListFilesAsync(string prefix, int maxKeys = 100, string? continuationToken = null)
|
||||||
|
{
|
||||||
|
var files = new List<CdnFile>();
|
||||||
|
|
||||||
|
if (_client == null)
|
||||||
|
{
|
||||||
|
_logger.LogWarning("MinIO client not initialized");
|
||||||
|
return files;
|
||||||
|
}
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
// Normalize prefix
|
||||||
|
if (!string.IsNullOrEmpty(prefix) && !prefix.EndsWith("/"))
|
||||||
|
prefix += "/";
|
||||||
|
|
||||||
|
var listArgs = new ListObjectsArgs()
|
||||||
|
.WithBucket(_config.BucketName)
|
||||||
|
.WithPrefix(prefix)
|
||||||
|
.WithRecursive(false); // Only list current level
|
||||||
|
|
||||||
|
await foreach (var item in _client.ListObjectsEnumAsync(listArgs))
|
||||||
|
{
|
||||||
|
if (files.Count >= maxKeys) break;
|
||||||
|
|
||||||
|
var isDir = item.Key.EndsWith("/");
|
||||||
|
files.Add(new CdnFile
|
||||||
|
{
|
||||||
|
Key = item.Key,
|
||||||
|
Name = isDir
|
||||||
|
? item.Key.TrimEnd('/').Split('/').Last()
|
||||||
|
: Path.GetFileName(item.Key),
|
||||||
|
Size = (long)item.Size,
|
||||||
|
LastModified = item.LastModifiedDateTime ?? DateTime.MinValue,
|
||||||
|
IsDirectory = isDir
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
_logger.LogDebug("Listed {Count} files from prefix: {Prefix}", files.Count, prefix);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Error listing files from MinIO prefix: {Prefix}", prefix);
|
||||||
|
}
|
||||||
|
|
||||||
|
return files;
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task<List<string>> ListPrefixesAsync(string prefix)
|
||||||
|
{
|
||||||
|
var prefixes = new List<string>();
|
||||||
|
|
||||||
|
if (_client == null) return prefixes;
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
if (!string.IsNullOrEmpty(prefix) && !prefix.EndsWith("/"))
|
||||||
|
prefix += "/";
|
||||||
|
|
||||||
|
var listArgs = new ListObjectsArgs()
|
||||||
|
.WithBucket(_config.BucketName)
|
||||||
|
.WithPrefix(prefix)
|
||||||
|
.WithRecursive(false);
|
||||||
|
|
||||||
|
await foreach (var item in _client.ListObjectsEnumAsync(listArgs))
|
||||||
|
{
|
||||||
|
if (item.Key.EndsWith("/"))
|
||||||
|
{
|
||||||
|
prefixes.Add(item.Key);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Error listing prefixes from MinIO: {Prefix}", prefix);
|
||||||
|
}
|
||||||
|
|
||||||
|
return prefixes;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -17,6 +17,7 @@
|
|||||||
</PackageReference>
|
</PackageReference>
|
||||||
<PackageReference Include="Microsoft.Extensions.Diagnostics.HealthChecks" Version="9.0.10" />
|
<PackageReference Include="Microsoft.Extensions.Diagnostics.HealthChecks" Version="9.0.10" />
|
||||||
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.22.1" />
|
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.22.1" />
|
||||||
|
<PackageReference Include="Minio" Version="6.0.3" />
|
||||||
<PackageReference Include="MySqlConnector" Version="2.4.0" />
|
<PackageReference Include="MySqlConnector" Version="2.4.0" />
|
||||||
<PackageReference Include="Polly" Version="8.6.4" />
|
<PackageReference Include="Polly" Version="8.6.4" />
|
||||||
<PackageReference Include="Pomelo.EntityFrameworkCore.MySql" Version="9.0.0" />
|
<PackageReference Include="Pomelo.EntityFrameworkCore.MySql" Version="9.0.0" />
|
||||||
|
|||||||
@@ -11,5 +11,12 @@
|
|||||||
"CommandTimeoutSeconds": 30,
|
"CommandTimeoutSeconds": 30,
|
||||||
"MaxRetryCount": 3,
|
"MaxRetryCount": 3,
|
||||||
"RetryBaseDelayMs": 100
|
"RetryBaseDelayMs": 100
|
||||||
|
},
|
||||||
|
"MinIO": {
|
||||||
|
"Endpoint": "assets.aeternalisgames.com",
|
||||||
|
"AccessKey": "",
|
||||||
|
"SecretKey": "",
|
||||||
|
"BucketName": "downloads",
|
||||||
|
"UseSSL": true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user