diff --git a/gsm-backend/routes/servers.js b/gsm-backend/routes/servers.js index fc7737f..694de90 100644 --- a/gsm-backend/routes/servers.js +++ b/gsm-backend/routes/servers.js @@ -900,4 +900,35 @@ router.post("/discord/send-update", authenticateToken, requireRole("superadmin") } }); +// Internal route for sending updates (localhost only, no auth) +router.post("/discord/internal-update", async (req, res) => { + const clientIp = req.ip || req.connection.remoteAddress; + if (clientIp !== '127.0.0.1' && clientIp !== '::1' && clientIp !== '::ffff:127.0.0.1') { + return res.status(403).json({ error: "Forbidden - localhost only" }); + } + + const { title, description, color, serverType } = req.body; + if (!title || !description) { + return res.status(400).json({ error: "Title and description required" }); + } + + try { + const serverIcons = { + minecraft: '⛏️', factorio: '⚙️', zomboid: '🧟', vrising: '🧛', + palworld: '🦎', terraria: '⚔️', openttd: '🚂', hytale: '🏰' + }; + + const embed = new EmbedBuilder() + .setTitle((serverIcons[serverType] || '📢') + ' ' + title) + .setDescription(description) + .setColor(color || 0x5865F2) + .setTimestamp(); + + await sendUpdateToAllGuilds(embed); + res.json({ message: "Update sent" }); + } catch (err) { + res.status(500).json({ error: err.message }); + } +}); + export default router;