Brozy123 commited on
Commit
3b97150
·
verified ·
1 Parent(s): 9402118

Update server.js

Browse files
Files changed (1) hide show
  1. server.js +17 -17
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
- const app = await discordClient.application.fetch().catch(() => null);
387
-
388
- // Owner recognition for both single-owner apps and team-owned apps.
389
- const ownerCandidates = new Set();
390
- if (app?.owner?.id) ownerCandidates.add(app.owner.id);
391
- if (app?.owner?.ownerId) ownerCandidates.add(app.owner.ownerId);
392
- if (app?.owner?.members) {
393
- for (const member of app.owner.members.values()) {
394
- if (member?.id) ownerCandidates.add(member.id);
395
- if (member?.user?.id) ownerCandidates.add(member.user.id);
 
 
396
  }
397
  }
398
- const isBotOwner = ownerCandidates.has(req.dashSession.user.id);
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 enabled 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) {
 
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) {