Add endpoint to register all bot servers to the federation
Create a POST endpoint `/api/federation/register-all` in `webServer.js` to upsert all servers the Discord client is connected to into the `federation_servers` table, using `guild_id` as the conflict target. Replit-Commit-Author: Agent Replit-Commit-Session-Id: aed2e46d-25bb-4b73-81a1-bb9e8437c261 Replit-Commit-Checkpoint-Type: full_checkpoint Replit-Commit-Event-Id: 31d9f5da-0c63-4f85-a2fa-50807ff47f17 Replit-Commit-Screenshot-Url: https://storage.googleapis.com/screenshot-production-us-central1/3bdfff67-975a-46ad-9845-fbb6b4a4c4b5/aed2e46d-25bb-4b73-81a1-bb9e8437c261/2a77Jky Replit-Helium-Checkpoint-Created: true
This commit is contained in:
parent
b002fd39da
commit
6183ca3e0e
1 changed files with 49 additions and 0 deletions
|
|
@ -1381,6 +1381,55 @@ function createWebServer(discordClient, supabase, options = {}) {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Admin endpoint to register all bot servers to federation
|
||||||
|
app.post('/api/federation/register-all', async (req, res) => {
|
||||||
|
if (!supabase) {
|
||||||
|
return res.status(503).json({ error: 'Database not available' });
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
const guilds = discordClient.guilds.cache;
|
||||||
|
const results = [];
|
||||||
|
|
||||||
|
for (const [guildId, guild] of guilds) {
|
||||||
|
const serverData = {
|
||||||
|
guild_id: guildId,
|
||||||
|
guild_name: guild.name,
|
||||||
|
guild_icon: guild.iconURL({ size: 128 }),
|
||||||
|
owner_id: guild.ownerId,
|
||||||
|
member_count: guild.memberCount,
|
||||||
|
status: 'approved',
|
||||||
|
tier: 'free',
|
||||||
|
trust_level: 'bronze',
|
||||||
|
reputation_score: 0,
|
||||||
|
description: `Official AeThex server: ${guild.name}`,
|
||||||
|
joined_federation_at: new Date().toISOString()
|
||||||
|
};
|
||||||
|
|
||||||
|
const { error } = await supabase
|
||||||
|
.from('federation_servers')
|
||||||
|
.upsert(serverData, { onConflict: 'guild_id' });
|
||||||
|
|
||||||
|
results.push({
|
||||||
|
guild_id: guildId,
|
||||||
|
guild_name: guild.name,
|
||||||
|
success: !error,
|
||||||
|
error: error?.message
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
res.json({
|
||||||
|
success: true,
|
||||||
|
registered: results.filter(r => r.success).length,
|
||||||
|
failed: results.filter(r => !r.success).length,
|
||||||
|
results
|
||||||
|
});
|
||||||
|
} catch (error) {
|
||||||
|
console.error('[Federation] Register all error:', error);
|
||||||
|
res.status(500).json({ error: 'Failed to register servers' });
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
app.get('/api/federation/applications', async (req, res) => {
|
app.get('/api/federation/applications', async (req, res) => {
|
||||||
if (!supabase) {
|
if (!supabase) {
|
||||||
return res.status(503).json({ error: 'Database not available' });
|
return res.status(503).json({ error: 'Database not available' });
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue