This commit is contained in:
dingo
2025-12-26 23:11:59 -05:00
parent 9b757bf5ff
commit 4d26c37671
5 changed files with 294 additions and 26 deletions
+31
View File
@@ -105,6 +105,26 @@ MINIO_BUCKET=downloads</pre>
<a href="/admin/assets?tab=browse&prefix=@Uri.EscapeDataString(currentPath)" class="text-indigo-400 hover:underline">@part</a>
}
</div>
<!-- Upload Form -->
<div class="mt-4 p-3 bg-gray-800 rounded-lg">
<form method="post" asp-page-handler="UploadFile" enctype="multipart/form-data" class="flex flex-wrap items-center gap-3">
@Html.AntiForgeryToken()
<input type="hidden" name="uploadPath" value="@Model.Prefix" />
<input type="file" name="file" class="flex-1 min-w-[200px] text-sm text-gray-400
file:mr-3 file:py-2 file:px-4
file:rounded file:border-0
file:text-sm file:font-medium
file:bg-indigo-600 file:text-white
hover:file:bg-indigo-500" />
<button type="submit" class="btn btn-primary flex items-center gap-2">
<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-8l-4-4m0 0L8 8m4-4v12"/>
</svg>
Upload to @(string.IsNullOrEmpty(Model.Prefix) ? "root" : Model.Prefix)
</button>
</form>
</div>
</div>
<!-- Subfolders -->
@@ -211,6 +231,17 @@ MINIO_BUCKET=downloads</pre>
</svg>
</a>
}
<!-- Delete from CDN -->
<form method="post" asp-page-handler="DeleteCdnFile" class="inline" onsubmit="return confirm('Delete @file.Name from CDN? This cannot be undone.')">
@Html.AntiForgeryToken()
<input type="hidden" name="filePath" value="@file.Key" />
<input type="hidden" name="returnPrefix" value="@Model.Prefix" />
<button type="submit" class="p-1.5 bg-red-700 rounded hover:bg-red-600" title="Delete from CDN">
<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>
}
+100
View File
@@ -322,4 +322,104 @@ public class IndexModel : AdminPageModel
var placeholderHash = md5.ComputeHash(placeholderBytes);
return Convert.ToHexString(placeholderHash).ToLower();
}
public async Task<IActionResult> OnPostUploadFileAsync(IFormFile file, string? uploadPath)
{
if (file == null || file.Length == 0)
{
Message = "Please select a file to upload.";
IsError = true;
return RedirectToPage(new { tab = "browse", prefix = uploadPath });
}
// Sanitize and build the full path
var fileName = Path.GetFileName(file.FileName).Replace(" ", "_");
var fullPath = string.IsNullOrEmpty(uploadPath)
? fileName
: $"{uploadPath.TrimEnd('/')}/{fileName}";
try
{
// Determine content type
var contentType = file.ContentType;
if (string.IsNullOrEmpty(contentType))
{
var ext = Path.GetExtension(fileName).ToLower();
contentType = ext switch
{
".png" => "image/png",
".jpg" or ".jpeg" => "image/jpeg",
".gif" => "image/gif",
".webp" => "image/webp",
".tscn" => "text/plain",
".gd" => "text/plain",
".json" => "application/json",
_ => "application/octet-stream"
};
}
using var stream = file.OpenReadStream();
var success = await _cdnService.UploadFileAsync(fullPath, stream, contentType);
if (success)
{
Message = $"Uploaded: {fullPath}";
}
else
{
Message = "Upload failed. Check server logs.";
IsError = true;
}
}
catch (Exception ex)
{
Message = $"Upload error: {ex.Message}";
IsError = true;
}
return RedirectToPage(new { tab = "browse", prefix = uploadPath });
}
public async Task<IActionResult> OnPostDeleteCdnFileAsync(string filePath, string? returnPrefix)
{
if (string.IsNullOrEmpty(filePath))
{
Message = "File path is required.";
IsError = true;
return RedirectToPage(new { tab = "browse", prefix = returnPrefix });
}
try
{
var success = await _cdnService.DeleteFileAsync(filePath);
if (success)
{
// Also remove from tracking if exists
var tracked = await _db.ClientAssets.FirstOrDefaultAsync(a => a.FilePath == filePath);
if (tracked != null)
{
_db.ClientAssets.Remove(tracked);
await _db.SaveChangesAsync();
Message = $"Deleted from CDN and removed tracking: {filePath}";
}
else
{
Message = $"Deleted from CDN: {filePath}";
}
}
else
{
Message = "Delete failed. Check server logs.";
IsError = true;
}
}
catch (Exception ex)
{
Message = $"Delete error: {ex.Message}";
IsError = true;
}
return RedirectToPage(new { tab = "browse", prefix = returnPrefix });
}
}
@@ -31,12 +31,12 @@ public class IndexModel : AdminPageModel
{
try
{
// Try to get connected player count from Redis
var playerCount = await _redis.Db.StringGetAsync("server:player_count");
// Use correct Redis keys (stats:players and stats:dungeons)
var playerCount = await _redis.Db.StringGetAsync("stats:players");
if (playerCount.HasValue && int.TryParse(playerCount, out var count))
ConnectedPlayers = count;
var dungeonCount = await _redis.Db.StringGetAsync("server:dungeon_count");
var dungeonCount = await _redis.Db.StringGetAsync("stats:dungeons");
if (dungeonCount.HasValue && int.TryParse(dungeonCount, out var dCount))
ActiveDungeons = dCount;
}
+105 -23
View File
@@ -4,7 +4,7 @@
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>@ViewData["Title"] - Dungeon Divers Admin</title>
<title>@ViewData["Title"] - Void Scavengers Admin</title>
<script src="https://cdn.tailwindcss.com"></script>
<script>
tailwind.config = {
@@ -47,26 +47,66 @@
.badge-rare { background-color: #2563eb; color: white; }
.badge-epic { background-color: #9333ea; color: white; }
.badge-legendary { background-color: #f97316; color: white; }
/* Drawer styles */
.drawer-overlay {
opacity: 0;
visibility: hidden;
transition: opacity 0.3s, visibility 0.3s;
}
.drawer-overlay.open {
opacity: 1;
visibility: visible;
}
.drawer-sidebar {
transform: translateX(-100%);
transition: transform 0.3s ease-in-out;
}
.drawer-sidebar.open {
transform: translateX(0);
}
@@media (min-width: 1024px) {
.drawer-sidebar {
transform: translateX(0) !important;
}
.drawer-overlay {
display: none !important;
}
.mobile-menu-btn {
display: none !important;
}
}
</style>
</head>
<body class="h-full">
<div class="flex h-full">
<!-- Mobile overlay -->
<div id="drawer-overlay" class="drawer-overlay fixed inset-0 bg-black/50 z-40 lg:hidden" onclick="toggleDrawer()"></div>
<!-- Sidebar -->
<aside class="w-64 bg-gray-800 border-r border-gray-700 flex flex-col">
<aside id="sidebar" class="drawer-sidebar fixed lg:static inset-y-0 left-0 z-50 w-64 bg-gray-800 border-r border-gray-700 flex flex-col">
<!-- Logo -->
<div class="p-4 border-b border-gray-700">
<h1 class="text-xl font-bold text-white flex items-center gap-2">
<svg class="w-8 h-8 text-indigo-500" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M13 10V3L4 14h7v7l9-11h-7z"/>
<div class="p-4 border-b border-gray-700 flex items-center justify-between">
<div>
<h1 class="text-xl font-bold text-white flex items-center gap-2">
<svg class="w-8 h-8 text-indigo-500" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M13 10V3L4 14h7v7l9-11h-7z"/>
</svg>
Void Scavengers
</h1>
<p class="text-xs text-gray-500 mt-1">Admin Panel</p>
</div>
<!-- Close button for mobile -->
<button class="lg:hidden text-gray-400 hover:text-white p-1" onclick="toggleDrawer()">
<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>
Dungeon Divers
</h1>
<p class="text-xs text-gray-500 mt-1">Admin Panel</p>
</button>
</div>
<!-- Navigation -->
<nav class="flex-1 p-4 space-y-1">
<a href="/admin" class="sidebar-link @(ViewContext.RouteData.Values["page"]?.ToString() == "/Index" ? "active" : "")">
<nav class="flex-1 p-4 space-y-1 overflow-y-auto">
<a href="/admin" class="sidebar-link @(ViewContext.RouteData.Values["page"]?.ToString() == "/Index" ? "active" : "")" onclick="closeMobileMenu()">
<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="M3 12l2-2m0 0l7-7 7 7M5 10v10a1 1 0 001 1h3m10-11l2 2m-2-2v10a1 1 0 01-1 1h-3m-6 0a1 1 0 001-1v-4a1 1 0 011-1h2a1 1 0 011 1v4a1 1 0 001 1m-6 0h6"/>
</svg>
@@ -77,42 +117,42 @@
<p class="px-4 text-xs font-semibold text-gray-500 uppercase tracking-wider">Content</p>
</div>
<a href="/admin/items" class="sidebar-link @(ViewContext.RouteData.Values["page"]?.ToString()?.StartsWith("/Items") == true ? "active" : "")">
<a href="/admin/items" class="sidebar-link @(ViewContext.RouteData.Values["page"]?.ToString()?.StartsWith("/Items") == true ? "active" : "")" onclick="closeMobileMenu()">
<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="M20 7l-8-4-8 4m16 0l-8 4m8-4v10l-8 4m0-10L4 7m8 4v10M4 7v10l8 4"/>
</svg>
Items
</a>
<a href="/admin/recipes" class="sidebar-link @(ViewContext.RouteData.Values["page"]?.ToString()?.StartsWith("/Recipes") == true ? "active" : "")">
<a href="/admin/recipes" class="sidebar-link @(ViewContext.RouteData.Values["page"]?.ToString()?.StartsWith("/Recipes") == true ? "active" : "")" onclick="closeMobileMenu()">
<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="M19.428 15.428a2 2 0 00-1.022-.547l-2.387-.477a6 6 0 00-3.86.517l-.318.158a6 6 0 01-3.86.517L6.05 15.21a2 2 0 00-1.806.547M8 4h8l-1 1v5.172a2 2 0 00.586 1.414l5 5c1.26 1.26.367 3.414-1.415 3.414H4.828c-1.782 0-2.674-2.154-1.414-3.414l5-5A2 2 0 009 10.172V5L8 4z"/>
</svg>
Recipes
</a>
<a href="/admin/mobs" class="sidebar-link @(ViewContext.RouteData.Values["page"]?.ToString()?.StartsWith("/Mobs") == true ? "active" : "")">
<a href="/admin/mobs" class="sidebar-link @(ViewContext.RouteData.Values["page"]?.ToString()?.StartsWith("/Mobs") == true ? "active" : "")" onclick="closeMobileMenu()">
<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 6.253v13m0-13C10.832 5.477 9.246 5 7.5 5S4.168 5.477 3 6.253v13C4.168 18.477 5.754 18 7.5 18s3.332.477 4.5 1.253m0-13C13.168 5.477 14.754 5 16.5 5c1.747 0 3.332.477 4.5 1.253v13C19.832 18.477 18.247 18 16.5 18c-1.746 0-3.332.477-4.5 1.253"/>
</svg>
Mobs
</a>
<a href="/admin/assets" class="sidebar-link @(ViewContext.RouteData.Values["page"]?.ToString()?.StartsWith("/Assets") == true ? "active" : "")">
<a href="/admin/assets" class="sidebar-link @(ViewContext.RouteData.Values["page"]?.ToString()?.StartsWith("/Assets") == true ? "active" : "")" onclick="closeMobileMenu()">
<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 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>
CDN Assets
</a>
<a href="/admin/loottables" class="sidebar-link @(ViewContext.RouteData.Values["page"]?.ToString()?.StartsWith("/LootTables") == true ? "active" : "")">
<a href="/admin/loottables" class="sidebar-link @(ViewContext.RouteData.Values["page"]?.ToString()?.StartsWith("/LootTables") == true ? "active" : "")" onclick="closeMobileMenu()">
<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 8c-1.657 0-3 .895-3 2s1.343 2 3 2 3 .895 3 2-1.343 2-3 2m0-8c1.11 0 2.08.402 2.599 1M12 8V7m0 1v8m0 0v1m0-1c-1.11 0-2.08-.402-2.599-1M21 12a9 9 0 11-18 0 9 9 0 0118 0z"/>
</svg>
Loot Tables
</a>
<a href="/admin/resistances" class="sidebar-link @(ViewContext.RouteData.Values["page"]?.ToString()?.StartsWith("/Resistances") == true ? "active" : "")">
<a href="/admin/resistances" class="sidebar-link @(ViewContext.RouteData.Values["page"]?.ToString()?.StartsWith("/Resistances") == true ? "active" : "")" onclick="closeMobileMenu()">
<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="M9 12l2 2 4-4m5.618-4.016A11.955 11.955 0 0112 2.944a11.955 11.955 0 01-8.618 3.04A12.02 12.02 0 003 9c0 5.591 3.824 10.29 9 11.622 5.176-1.332 9-6.03 9-11.622 0-1.042-.133-2.052-.382-3.016z"/>
</svg>
@@ -123,18 +163,18 @@
<p class="px-4 text-xs font-semibold text-gray-500 uppercase tracking-wider">Management</p>
</div>
<a href="/admin/players" class="sidebar-link @(ViewContext.RouteData.Values["page"]?.ToString()?.StartsWith("/Players") == true ? "active" : "")">
<a href="/admin/players" class="sidebar-link @(ViewContext.RouteData.Values["page"]?.ToString()?.StartsWith("/Players") == true ? "active" : "")" onclick="closeMobileMenu()">
<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 4.354a4 4 0 110 5.292M15 21H3v-1a6 6 0 0112 0v1zm0 0h6v-1a6 6 0 00-9-5.197M13 7a4 4 0 11-8 0 4 4 0 018 0z"/>
</svg>
Players
</a>
<a href="/admin/broadcast" class="sidebar-link @(ViewContext.RouteData.Values["page"]?.ToString()?.StartsWith("/Broadcast") == true ? "active" : "")">
<a href="/admin/server" class="sidebar-link @(ViewContext.RouteData.Values["page"]?.ToString()?.StartsWith("/Server") == true ? "active" : "")" onclick="closeMobileMenu()">
<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="M11 5.882V19.24a1.76 1.76 0 01-3.417.592l-2.147-6.15M18 13a3 3 0 100-6M5.436 13.683A4.001 4.001 0 017 6h1.832c4.1 0 7.625-1.234 9.168-3v14c-1.543-1.766-5.067-3-9.168-3H7a3.988 3.988 0 01-1.564-.317z"/>
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M5 12h14M5 12a2 2 0 01-2-2V6a2 2 0 012-2h14a2 2 0 012 2v4a2 2 0 01-2 2M5 12a2 2 0 00-2 2v4a2 2 0 002 2h14a2 2 0 002-2v-4a2 2 0 00-2-2m-2-4h.01M17 16h.01"/>
</svg>
Broadcast
Server
</a>
</nav>
@@ -158,13 +198,55 @@
</aside>
<!-- Main content -->
<main class="flex-1 overflow-auto">
<div class="p-8">
<main class="flex-1 overflow-auto min-w-0">
<!-- Mobile header -->
<div class="lg:hidden sticky top-0 z-30 bg-gray-800 border-b border-gray-700 p-4 flex items-center gap-4">
<button class="mobile-menu-btn text-gray-400 hover:text-white" onclick="toggleDrawer()">
<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="M4 6h16M4 12h16M4 18h16"/>
</svg>
</button>
<h1 class="text-lg font-semibold text-white truncate">@ViewData["Title"]</h1>
</div>
<div class="p-4 md:p-6 lg:p-8">
@RenderBody()
</div>
</main>
</div>
<script>
function toggleDrawer() {
document.getElementById('sidebar').classList.toggle('open');
document.getElementById('drawer-overlay').classList.toggle('open');
document.body.classList.toggle('overflow-hidden');
}
function closeMobileMenu() {
if (window.innerWidth < 1024) {
document.getElementById('sidebar').classList.remove('open');
document.getElementById('drawer-overlay').classList.remove('open');
document.body.classList.remove('overflow-hidden');
}
}
// Close drawer on escape key
document.addEventListener('keydown', function(e) {
if (e.key === 'Escape') {
closeMobileMenu();
}
});
// Close drawer on window resize to desktop
window.addEventListener('resize', function() {
if (window.innerWidth >= 1024) {
document.getElementById('sidebar').classList.remove('open');
document.getElementById('drawer-overlay').classList.remove('open');
document.body.classList.remove('overflow-hidden');
}
});
</script>
@await RenderSectionAsync("Scripts", required: false)
</body>
</html>