Refresh fix, Dungeon Builder v2

This commit is contained in:
dingo
2026-01-04 21:35:42 -05:00
parent 89e6684288
commit 7de9bd2761
8 changed files with 1559 additions and 67 deletions
+102
View File
@@ -114,6 +114,48 @@
</div>
</div>
</div>
<!-- Cache Management -->
<div class="card p-6">
<h2 class="text-lg font-semibold text-white mb-4">Cache Management</h2>
<p class="text-sm text-gray-400 mb-4">Refresh server caches without restarting. Use after adding/modifying game data.</p>
<div class="grid grid-cols-2 md:grid-cols-4 gap-3" id="cacheButtons">
<button type="button" onclick="refreshCache('recipes')" class="btn btn-secondary flex flex-col items-center gap-1 py-3">
<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 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2"/>
</svg>
<span class="text-xs">Recipes</span>
</button>
<button type="button" onclick="refreshCache('mobs')" class="btn btn-secondary flex flex-col items-center gap-1 py-3">
<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="M14.828 14.828a4 4 0 01-5.656 0M9 10h.01M15 10h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z"/>
</svg>
<span class="text-xs">Mobs</span>
</button>
<button type="button" onclick="refreshCache('loot')" class="btn btn-secondary flex flex-col items-center gap-1 py-3">
<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>
<span class="text-xs">Loot Tables</span>
</button>
<button type="button" onclick="refreshCache('all')" class="btn bg-purple-700 hover:bg-purple-600 text-white flex flex-col items-center gap-1 py-3">
<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>
<span class="text-xs">Refresh All</span>
</button>
</div>
<div id="cacheStatus" class="mt-4 hidden">
<div class="p-3 rounded-lg bg-gray-800 border border-gray-700">
<span id="cacheStatusText" class="text-gray-300"></span>
</div>
</div>
</div>
<!-- Recent Broadcasts -->
<div class="card p-6">
@@ -147,3 +189,63 @@
}
</div>
</div>
@section Scripts {
<script>
async function refreshCache(type) {
const statusDiv = document.getElementById('cacheStatus');
const statusText = document.getElementById('cacheStatusText');
const buttons = document.querySelectorAll('#cacheButtons button');
// Disable all buttons
buttons.forEach(btn => btn.disabled = true);
// Show loading
statusDiv.classList.remove('hidden');
statusText.innerHTML = '<span class="animate-pulse">Refreshing ' + type + ' cache...</span>';
statusDiv.querySelector('div').className = 'p-3 rounded-lg bg-blue-900/50 border border-blue-700';
try {
const token = document.querySelector('input[name="__RequestVerificationToken"]')?.value || '';
const response = await fetch('/admin/api?handler=RefreshCache&type=' + type, {
method: 'POST',
credentials: 'same-origin',
headers: {
'RequestVerificationToken': token
}
});
let data;
const text = await response.text();
try {
data = JSON.parse(text);
} catch (e) {
throw new Error('Invalid response from server: ' + text.substring(0, 100));
}
if (response.ok && data.success) {
statusText.innerHTML = '✓ Cache refreshed: ' + (data.refreshed || []).join(', ');
statusDiv.querySelector('div').className = 'p-3 rounded-lg bg-green-900/50 border border-green-700';
if (data.errors && data.errors.length > 0) {
statusText.innerHTML += '<br><span class="text-yellow-400">Warnings: ' + data.errors.join(', ') + '</span>';
}
} else {
statusText.innerHTML = '✗ Error: ' + (data.error || 'Unknown error');
statusDiv.querySelector('div').className = 'p-3 rounded-lg bg-red-900/50 border border-red-700';
}
} catch (err) {
statusText.innerHTML = '✗ Error: ' + err.message;
statusDiv.querySelector('div').className = 'p-3 rounded-lg bg-red-900/50 border border-red-700';
} finally {
// Re-enable buttons
buttons.forEach(btn => btn.disabled = false);
// Hide status after 5 seconds
setTimeout(() => {
statusDiv.classList.add('hidden');
}, 5000);
}
}
</script>
}