Spaces:
Runtime error
Runtime error
Update server.js
Browse files
server.js
CHANGED
|
@@ -376,6 +376,7 @@ app.get('/api/stats', requireAuth, (req, res) => {
|
|
| 376 |
|
| 377 |
// --- Server List ---
|
| 378 |
// --- Server List (shared with bot + permissions) ---
|
|
|
|
| 379 |
app.get('/api/servers', requireAuth, async (req, res) => {
|
| 380 |
try {
|
| 381 |
if (!discordClient || !discordClient.isReady()) {
|
|
@@ -383,24 +384,25 @@ app.get('/api/servers', requireAuth, async (req, res) => {
|
|
| 383 |
}
|
| 384 |
|
| 385 |
const userGuilds = req.dashSession.guilds || [];
|
| 386 |
-
|
| 387 |
-
|
| 388 |
-
|
| 389 |
-
|
| 390 |
-
|
| 391 |
-
|
| 392 |
-
|
| 393 |
-
|
| 394 |
-
|
| 395 |
-
|
|
|
|
|
|
|
| 396 |
}
|
| 397 |
}
|
| 398 |
-
|
| 399 |
-
|
| 400 |
console.log(`[Dashboard] Request by ${req.dashSession.user.username} (Owner: ${isBotOwner})`);
|
| 401 |
|
| 402 |
// Filter guilds to only those that the user is actually in AND has permissions for.
|
| 403 |
-
// This applies even to the Bot Owner to keep the dashboard clean.
|
| 404 |
const mutualGuilds = userGuilds
|
| 405 |
.filter(ug => discordClient.guilds.cache.has(ug.id))
|
| 406 |
.filter(Boolean);
|
|
@@ -410,11 +412,9 @@ app.get('/api/servers', requireAuth, async (req, res) => {
|
|
| 410 |
return hasDashboardPermissions(permBits);
|
| 411 |
});
|
| 412 |
|
| 413 |
-
// Fallback: if manageable list is empty, don't show everything, just show mutuals if they have any perms.
|
| 414 |
-
// But for absolute privacy, we strictly use manageableGuilds.
|
| 415 |
const guildsToShow = manageableGuilds;
|
| 416 |
|
| 417 |
-
visibleGuilds = guildsToShow
|
| 418 |
.map(ug => discordClient.guilds.cache.get(ug.id))
|
| 419 |
.filter(Boolean);
|
| 420 |
|
|
@@ -425,7 +425,7 @@ app.get('/api/servers', requireAuth, async (req, res) => {
|
|
| 425 |
icon: g.iconURL({ size: 64 }) || null
|
| 426 |
}));
|
| 427 |
|
| 428 |
-
if (isBotOwner) console.log(`[Dashboard] Owner access
|
| 429 |
console.log(`[Dashboard] Serving ${list.length} managed servers to ${req.dashSession.user.username}`);
|
| 430 |
res.json({ pending: false, servers: list });
|
| 431 |
} catch (err) {
|
|
|
|
| 376 |
|
| 377 |
// --- Server List ---
|
| 378 |
// --- Server List (shared with bot + permissions) ---
|
| 379 |
+
let cachedOwnerId = null;
|
| 380 |
app.get('/api/servers', requireAuth, async (req, res) => {
|
| 381 |
try {
|
| 382 |
if (!discordClient || !discordClient.isReady()) {
|
|
|
|
| 384 |
}
|
| 385 |
|
| 386 |
const userGuilds = req.dashSession.guilds || [];
|
| 387 |
+
|
| 388 |
+
// recognize owner (cached to avoid redundant API calls)
|
| 389 |
+
if (!cachedOwnerId) {
|
| 390 |
+
const app = await discordClient.application.fetch().catch(() => null);
|
| 391 |
+
if (app) {
|
| 392 |
+
cachedOwnerId = app.owner?.ownerId || app.owner?.id;
|
| 393 |
+
// Support teams
|
| 394 |
+
if (!cachedOwnerId && app.owner?.members) {
|
| 395 |
+
// Just check the first member as a fallback if ownerId is missing
|
| 396 |
+
const firstMember = Array.from(app.owner.members.values())[0];
|
| 397 |
+
cachedOwnerId = firstMember?.user?.id || firstMember?.id;
|
| 398 |
+
}
|
| 399 |
}
|
| 400 |
}
|
| 401 |
+
|
| 402 |
+
const isBotOwner = req.dashSession.user.id === cachedOwnerId;
|
| 403 |
console.log(`[Dashboard] Request by ${req.dashSession.user.username} (Owner: ${isBotOwner})`);
|
| 404 |
|
| 405 |
// Filter guilds to only those that the user is actually in AND has permissions for.
|
|
|
|
| 406 |
const mutualGuilds = userGuilds
|
| 407 |
.filter(ug => discordClient.guilds.cache.has(ug.id))
|
| 408 |
.filter(Boolean);
|
|
|
|
| 412 |
return hasDashboardPermissions(permBits);
|
| 413 |
});
|
| 414 |
|
|
|
|
|
|
|
| 415 |
const guildsToShow = manageableGuilds;
|
| 416 |
|
| 417 |
+
const visibleGuilds = guildsToShow
|
| 418 |
.map(ug => discordClient.guilds.cache.get(ug.id))
|
| 419 |
.filter(Boolean);
|
| 420 |
|
|
|
|
| 425 |
icon: g.iconURL({ size: 64 }) || null
|
| 426 |
}));
|
| 427 |
|
| 428 |
+
if (isBotOwner) console.log(`[Dashboard] Owner access verified for ${req.dashSession.user.username}`);
|
| 429 |
console.log(`[Dashboard] Serving ${list.length} managed servers to ${req.dashSession.user.username}`);
|
| 430 |
res.json({ pending: false, servers: list });
|
| 431 |
} catch (err) {
|