Fixed Invite Accordion

This commit is contained in:
2025-10-10 05:12:54 -04:00
parent 900ce85e2c
commit 8236c1e0e7
7 changed files with 219 additions and 7 deletions

View File

@@ -1049,7 +1049,36 @@ app.get('/api/servers/:guildId/invites', async (req, res) => {
app.post('/api/servers/:guildId/invites', async (req, res) => {
try {
const { guildId } = req.params;
const { channelId, maxAge, maxUses, temporary } = req.body || {};
const { code, url, channelId, maxAge, maxUses, temporary, createdAt } = req.body || {};
// If code is provided, this is an existing invite to store (from Discord events)
if (code) {
const item = {
code,
url: url || `https://discord.gg/${code}`,
channelId: channelId || '',
createdAt: createdAt || new Date().toISOString(),
maxUses: maxUses || 0,
maxAge: maxAge || 0,
temporary: !!temporary,
};
await pgClient.addInvite({
code: item.code,
guildId,
url: item.url,
channelId: item.channelId,
createdAt: item.createdAt,
maxUses: item.maxUses,
maxAge: item.maxAge,
temporary: item.temporary
});
res.json({ success: true, invite: item });
return;
}
// Otherwise, create a new invite
const guild = bot.client.guilds.cache.get(guildId);
if (!guild) return res.status(404).json({ success: false, message: 'Guild not found' });
@@ -1089,7 +1118,7 @@ app.post('/api/servers/:guildId/invites', async (req, res) => {
res.json({ success: true, invite: item });
} catch (error) {
console.error('Error creating invite:', error);
console.error('Error creating/storing invite:', error);
res.status(500).json({ success: false, message: 'Internal Server Error' });
}
});