Add Sync All buttons functionality for server matrix
WHAT WAS DONE: - Added POST /admin/servers/sync-all/:node endpoint - Accepts 'tx1' or 'nc1' as node parameter - Syncs whitelist to all servers on that node - Returns count of synced/errors - Wired up buttons in index.ejs with htmx - hx-post to the new endpoint - Results display in #sync-result span Files changed: - services/arbiter-3.0/src/routes/admin/servers.js (+45 lines) - services/arbiter-3.0/src/views/admin/servers/index.ejs Signed-off-by: Claude (Chronicler #60) <claude@firefrostgaming.com>
This commit is contained in:
@@ -108,4 +108,50 @@ router.post('/:identifier/toggle-whitelist', async (req, res) => {
|
|||||||
res.send(`<span class="text-yellow-500 font-bold text-sm">⚠️ Requires Restart</span>`);
|
res.send(`<span class="text-yellow-500 font-bold text-sm">⚠️ Requires Restart</span>`);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Sync all servers on a specific node
|
||||||
|
router.post('/sync-all/:node', async (req, res) => {
|
||||||
|
const { node } = req.params;
|
||||||
|
const nodeId = node === 'tx1' ? 3 : node === 'nc1' ? 2 : null;
|
||||||
|
|
||||||
|
if (!nodeId) {
|
||||||
|
return res.send(`<span class="text-red-500">Invalid node</span>`);
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
const discovered = await getMinecraftServers();
|
||||||
|
const nodeServers = discovered.filter(s => s.nodeId === nodeId);
|
||||||
|
|
||||||
|
const { rows: players } = await db.query(
|
||||||
|
`SELECT minecraft_username as name, minecraft_uuid as uuid FROM users
|
||||||
|
JOIN subscriptions ON users.discord_id = subscriptions.discord_id
|
||||||
|
WHERE subscriptions.status IN ('active', 'grace_period', 'lifetime')`
|
||||||
|
);
|
||||||
|
|
||||||
|
let synced = 0;
|
||||||
|
let errors = 0;
|
||||||
|
|
||||||
|
for (const srv of nodeServers) {
|
||||||
|
try {
|
||||||
|
await writeWhitelistFile(srv.identifier, players);
|
||||||
|
await reloadWhitelistCommand(srv.identifier);
|
||||||
|
await db.query(
|
||||||
|
"INSERT INTO server_sync_log (server_identifier, last_successful_sync, is_online, last_error) VALUES ($1, NOW(), true, NULL) ON CONFLICT (server_identifier) DO UPDATE SET last_successful_sync = NOW(), is_online = true, last_error = NULL",
|
||||||
|
[srv.identifier]
|
||||||
|
);
|
||||||
|
synced++;
|
||||||
|
} catch (err) {
|
||||||
|
await db.query(
|
||||||
|
"INSERT INTO server_sync_log (server_identifier, last_error, is_online) VALUES ($1, $2, false) ON CONFLICT (server_identifier) DO UPDATE SET last_error = $2, is_online = false",
|
||||||
|
[srv.identifier, err.message]
|
||||||
|
);
|
||||||
|
errors++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
res.send(`<span class="text-green-500 font-bold">✅ ${synced} synced</span>${errors > 0 ? ` <span class="text-red-500">(${errors} errors)</span>` : ''}`);
|
||||||
|
} catch (error) {
|
||||||
|
res.send(`<span class="text-red-500">❌ ${error.message}</span>`);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
module.exports = router;
|
module.exports = router;
|
||||||
|
|||||||
@@ -4,12 +4,19 @@
|
|||||||
<p class="text-gray-500 dark:text-gray-400 text-sm">Real-time status and whitelist controls</p>
|
<p class="text-gray-500 dark:text-gray-400 text-sm">Real-time status and whitelist controls</p>
|
||||||
</div>
|
</div>
|
||||||
<div class="space-x-3">
|
<div class="space-x-3">
|
||||||
<button class="bg-fire hover:bg-orange-600 text-white px-4 py-2 rounded-md text-sm font-medium shadow transition-colors">
|
<button hx-post="/admin/servers/sync-all/tx1"
|
||||||
|
hx-swap="innerHTML"
|
||||||
|
hx-target="#sync-result"
|
||||||
|
class="bg-fire hover:bg-orange-600 text-white px-4 py-2 rounded-md text-sm font-medium shadow transition-colors">
|
||||||
🔥 Sync All Dallas
|
🔥 Sync All Dallas
|
||||||
</button>
|
</button>
|
||||||
<button class="bg-frost hover:bg-cyan-600 text-white px-4 py-2 rounded-md text-sm font-medium shadow transition-colors">
|
<button hx-post="/admin/servers/sync-all/nc1"
|
||||||
|
hx-swap="innerHTML"
|
||||||
|
hx-target="#sync-result"
|
||||||
|
class="bg-frost hover:bg-cyan-600 text-white px-4 py-2 rounded-md text-sm font-medium shadow transition-colors">
|
||||||
❄️ Sync All Charlotte
|
❄️ Sync All Charlotte
|
||||||
</button>
|
</button>
|
||||||
|
<span id="sync-result" class="text-sm ml-2"></span>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user