Spaces:
Runtime error
Runtime error
Update server.js
Browse files
server.js
CHANGED
|
@@ -123,7 +123,10 @@ function getSession(req) {
|
|
| 123 |
// --- Auth Middleware ---
|
| 124 |
function requireAuth(req, res, next) {
|
| 125 |
const session = getSession(req);
|
| 126 |
-
if (session && session.user)
|
|
|
|
|
|
|
|
|
|
| 127 |
res.status(401).json({ error: 'Unauthorized' });
|
| 128 |
}
|
| 129 |
|
|
@@ -142,6 +145,10 @@ app.get('/', (req, res) => {
|
|
| 142 |
}
|
| 143 |
res.sendFile(path.join(__dirname, 'dashboard.html'));
|
| 144 |
});
|
|
|
|
|
|
|
|
|
|
|
|
|
| 145 |
app.get('/logo.png', (req, res) => {
|
| 146 |
const logo = path.join(__dirname, 'logo.png');
|
| 147 |
if (fs.existsSync(logo)) res.sendFile(logo);
|
|
@@ -177,6 +184,22 @@ app.get('/premium', (req, res) => {
|
|
| 177 |
res.sendFile(path.join(__dirname, 'premium.html'));
|
| 178 |
});
|
| 179 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 180 |
|
| 181 |
// --- Discord OAuth2: Step 1 — Redirect to Discord ---
|
| 182 |
app.get('/auth/login', (req, res) => {
|
|
@@ -471,7 +494,8 @@ app.get('/api/config/:guildId', requireAuth, (req, res) => {
|
|
| 471 |
cleanupHours: config.cleanupHours || 2,
|
| 472 |
lineupCleanupHours: config.lineupCleanupHours || 2,
|
| 473 |
remindersEnabled: !!config.remindersEnabled,
|
| 474 |
-
remindersLead: config.remindersLead || 30
|
|
|
|
| 475 |
});
|
| 476 |
});
|
| 477 |
|
|
@@ -489,7 +513,7 @@ app.get('/api/channels/:guildId', requireAuth, (req, res) => {
|
|
| 489 |
|
| 490 |
app.post('/api/config/:guildId', requireAuth, (req, res) => {
|
| 491 |
const { guildId } = req.params;
|
| 492 |
-
const { prefix, autoFriendlyEnabled, autoFriendlyInterval, autoFriendlyChannel, postEnabled, postChannelId, friendlyText, cleanupHours, lineupCleanupHours, remindersEnabled, remindersLead } = req.body;
|
| 493 |
const userGuilds = req.dashSession.guilds || [];
|
| 494 |
const ug = userGuilds.find(g => g.id === guildId);
|
| 495 |
|
|
@@ -516,6 +540,7 @@ app.post('/api/config/:guildId', requireAuth, (req, res) => {
|
|
| 516 |
if (lineupCleanupHours !== undefined) storage.data.config[guildId].lineupCleanupHours = parseInt(lineupCleanupHours) || 2;
|
| 517 |
if (remindersEnabled !== undefined) storage.data.config[guildId].remindersEnabled = !!remindersEnabled;
|
| 518 |
if (remindersLead !== undefined) storage.data.config[guildId].remindersLead = parseInt(remindersLead) || 30;
|
|
|
|
| 519 |
|
| 520 |
storage.save('config');
|
| 521 |
res.json({ success: true, message: 'Settings updated successfully' });
|
|
@@ -671,4 +696,4 @@ function startServerInternal(client, cmdsData) {
|
|
| 671 |
}
|
| 672 |
|
| 673 |
|
| 674 |
-
module.exports = { startServer, app };
|
|
|
|
| 123 |
// --- Auth Middleware ---
|
| 124 |
function requireAuth(req, res, next) {
|
| 125 |
const session = getSession(req);
|
| 126 |
+
if (session && session.user) {
|
| 127 |
+
req.user = session.user; // Attach user for convenience
|
| 128 |
+
return next();
|
| 129 |
+
}
|
| 130 |
res.status(401).json({ error: 'Unauthorized' });
|
| 131 |
}
|
| 132 |
|
|
|
|
| 145 |
}
|
| 146 |
res.sendFile(path.join(__dirname, 'dashboard.html'));
|
| 147 |
});
|
| 148 |
+
|
| 149 |
+
app.get('/dashboard', (req, res) => {
|
| 150 |
+
res.sendFile(path.join(__dirname, 'dashboard.html'));
|
| 151 |
+
});
|
| 152 |
app.get('/logo.png', (req, res) => {
|
| 153 |
const logo = path.join(__dirname, 'logo.png');
|
| 154 |
if (fs.existsSync(logo)) res.sendFile(logo);
|
|
|
|
| 184 |
res.sendFile(path.join(__dirname, 'premium.html'));
|
| 185 |
});
|
| 186 |
|
| 187 |
+
app.get('/aliases', (req, res) => {
|
| 188 |
+
res.sendFile(path.join(__dirname, 'aliases.html'));
|
| 189 |
+
});
|
| 190 |
+
|
| 191 |
+
app.get('/stats', (req, res) => {
|
| 192 |
+
res.sendFile(path.join(__dirname, 'stats.html'));
|
| 193 |
+
});
|
| 194 |
+
|
| 195 |
+
app.get('/scheduling', (req, res) => {
|
| 196 |
+
res.sendFile(path.join(__dirname, 'scheduling.html'));
|
| 197 |
+
});
|
| 198 |
+
|
| 199 |
+
app.get('/profiles', (req, res) => {
|
| 200 |
+
res.sendFile(path.join(__dirname, 'profiles.html'));
|
| 201 |
+
});
|
| 202 |
+
|
| 203 |
|
| 204 |
// --- Discord OAuth2: Step 1 — Redirect to Discord ---
|
| 205 |
app.get('/auth/login', (req, res) => {
|
|
|
|
| 494 |
cleanupHours: config.cleanupHours || 2,
|
| 495 |
lineupCleanupHours: config.lineupCleanupHours || 2,
|
| 496 |
remindersEnabled: !!config.remindersEnabled,
|
| 497 |
+
remindersLead: config.remindersLead || 30,
|
| 498 |
+
aliases: config.aliases || {}
|
| 499 |
});
|
| 500 |
});
|
| 501 |
|
|
|
|
| 513 |
|
| 514 |
app.post('/api/config/:guildId', requireAuth, (req, res) => {
|
| 515 |
const { guildId } = req.params;
|
| 516 |
+
const { prefix, autoFriendlyEnabled, autoFriendlyInterval, autoFriendlyChannel, postEnabled, postChannelId, friendlyText, cleanupHours, lineupCleanupHours, remindersEnabled, remindersLead, aliases } = req.body;
|
| 517 |
const userGuilds = req.dashSession.guilds || [];
|
| 518 |
const ug = userGuilds.find(g => g.id === guildId);
|
| 519 |
|
|
|
|
| 540 |
if (lineupCleanupHours !== undefined) storage.data.config[guildId].lineupCleanupHours = parseInt(lineupCleanupHours) || 2;
|
| 541 |
if (remindersEnabled !== undefined) storage.data.config[guildId].remindersEnabled = !!remindersEnabled;
|
| 542 |
if (remindersLead !== undefined) storage.data.config[guildId].remindersLead = parseInt(remindersLead) || 30;
|
| 543 |
+
if (aliases !== undefined) storage.data.config[guildId].aliases = aliases;
|
| 544 |
|
| 545 |
storage.save('config');
|
| 546 |
res.json({ success: true, message: 'Settings updated successfully' });
|
|
|
|
| 696 |
}
|
| 697 |
|
| 698 |
|
| 699 |
+
module.exports = { startServer, app };
|