let currentTab = 'clients';
// Check authentication on load
async function checkAuth() {
try {
const res = await fetch('/admin/check');
const data = await res.json();
if (!data.authenticated) {
window.location.href = '/admin/';
}
} catch (e) {
console.error('Auth check failed:', e);
}
}
// Logout
async function logout() {
await fetch('/admin/logout', { method: 'POST' });
location.reload();
}
// Load stats
async function loadStats() {
try {
const res = await fetch('/admin/stats');
const data = await res.json();
document.getElementById('stats-grid').innerHTML =
'
Clients
' + data.client_count + '
' +
'Total Snapshots
' + data.total_snapshots + '
' +
'Total Storage
' + data.total_storage_gb.toFixed(2) + ' GB
';
} catch (e) {
console.error('Failed to load stats:', e);
}
}
// Load clients
async function loadClients() {
try {
const res = await fetch('/admin/clients');
const clients = await res.json();
const tbody = document.getElementById('clients-table');
tbody.innerHTML = clients.map(c => {
const usedPercent = c.max_size_bytes > 0 ? (c.current_usage / c.max_size_bytes * 100).toFixed(1) : 0;
const usedGB = (c.current_usage / (1024*1024*1024)).toFixed(2);
const maxGB = (c.max_size_bytes / (1024*1024*1024)).toFixed(0);
return '