This commit is contained in:
NoLogicAlan committed 2026-05-06 18:47:12 +03:00
1 parent 5c2dcac509
commit 5e0aefb79d
1 file changed
+22 -22
+22 -22
View File
@@ -58,7 +58,7 @@ export class Dashboard {
this.redis = new RedisHandler(opts.redis); this.redis = new RedisHandler(opts.redis);
this.redis.setRequestHandler(async (data) => { this.redis.setRequestHandler(async (data) => {
switch (data.type) { switch (data.type) {
// ── Existing request types ───────────────────────────────────────────── // ── Existing request types ─────────────────────────────────────────────
case "fetchPlayers": case "fetchPlayers":
return [...this.remix.players.playerMap.values()].map(p => Dashboard.convertPlayer(p)); return [...this.remix.players.playerMap.values()].map(p => Dashboard.convertPlayer(p));
@@ -97,13 +97,13 @@ export class Dashboard {
case "commands": case "commands":
return this.remix.handler.commands.map(c => return this.remix.handler.commands.map(c =>
Dashboard.convertCommand(c, this.remix.handler) Dashboard.convertCommand(c, this.remix.handler)
); );
case "function": case "function":
return await this.runFunction(data.params); return await this.runFunction(data.params);
// ── Fluxer OAuth2 request types ───────────────────────────────────────── // ── Fluxer OAuth2 request types ─────────────────────────────────────────
case "fluxerAuthorizeUrl": { case "fluxerAuthorizeUrl": {
// Returns the full OAuth2 authorize URL for the dashboard frontend to redirect to // Returns the full OAuth2 authorize URL for the dashboard frontend to redirect to
@@ -181,8 +181,8 @@ export class Dashboard {
displayName: fluxerUser.displayName ?? fluxerUser.globalName ?? fluxerUser.username, displayName: fluxerUser.displayName ?? fluxerUser.globalName ?? fluxerUser.username,
avatar: { avatar: {
url: fluxerUser.avatar url: fluxerUser.avatar
? `https://cdn.fluxer.app/avatars/${fluxerUser.id}/${fluxerUser.avatar}.webp` ? `https://cdn.fluxer.app/avatars/${fluxerUser.id}/${fluxerUser.avatar}.webp`
: null, : null,
}, },
knownToBot: !!botUser, knownToBot: !!botUser,
botUser: botUser ? Dashboard.convertUser(botUser) : null, botUser: botUser ? Dashboard.convertUser(botUser) : null,
@@ -210,7 +210,7 @@ export class Dashboard {
const now = Date.now(); const now = Date.now();
// Prune timestamps outside the current window // Prune timestamps outside the current window
this._tokenExchangeTimestamps = this._tokenExchangeTimestamps.filter( this._tokenExchangeTimestamps = this._tokenExchangeTimestamps.filter(
ts => now - ts < this._tokenExchangeWindowMs ts => now - ts < this._tokenExchangeWindowMs
); );
if (this._tokenExchangeTimestamps.length >= this._tokenExchangeMaxPerWindow) { if (this._tokenExchangeTimestamps.length >= this._tokenExchangeMaxPerWindow) {
console.log("[Dashboard] Token exchange rate limit hit"); console.log("[Dashboard] Token exchange rate limit hit");
@@ -385,7 +385,7 @@ export class Dashboard {
* Bot owners are always allowed. Otherwise the user must be physically in the * Bot owners are always allowed. Otherwise the user must be physically in the
* player's voice channel to control it. * player's voice channel to control it.
* *
* @param {import("fluxer.js").User|null} user * @param {import("@fluxerjs/core").User|null} user
* @param {Player} player * @param {Player} player
* @returns {string|null} Error message, or null if authorized * @returns {string|null} Error message, or null if authorized
*/ */
@@ -418,7 +418,7 @@ export class Dashboard {
* Verify the user has permission to perform an action in the target guild. * Verify the user has permission to perform an action in the target guild.
* Bot owners are always allowed. Otherwise the user must be a member of the guild. * Bot owners are always allowed. Otherwise the user must be a member of the guild.
* *
* @param {import("fluxer.js").User} user * @param {import("@fluxerjs/core").User} user
* @param {string} guildId * @param {string} guildId
* @returns {Promise<string|null>} Error message, or null if authorized * @returns {Promise<string|null>} Error message, or null if authorized
*/ */
@@ -443,10 +443,10 @@ export class Dashboard {
*/ */
_getPlayerById(id) { _getPlayerById(id) {
return this.remix.players.playerMap.get(id) return this.remix.players.playerMap.get(id)
?? [...this.remix.players.playerMap.values()].find( ?? [...this.remix.players.playerMap.values()].find(
p => p._channelId === id || p._guildId === id p => p._channelId === id || p._guildId === id
) )
?? null; ?? null;
} }
// ── Static converters ───────────────────────────────────────────────────── // ── Static converters ─────────────────────────────────────────────────────
@@ -460,7 +460,7 @@ export class Dashboard {
* @property {string} avatar.url * @property {string} avatar.url
*/ */
/** /**
* @param {import("fluxer.js").User} user * @param {import("@fluxerjs/core").User} user
* @returns {APIUser} * @returns {APIUser}
*/ */
static convertUser(user) { static convertUser(user) {
@@ -480,9 +480,9 @@ export class Dashboard {
static convertVideo(vid) { static convertVideo(vid) {
if (!vid) return null; if (!vid) return null;
const durationMs = const durationMs =
typeof vid.duration === "number" ? vid.duration : typeof vid.duration === "number" ? vid.duration :
typeof vid.duration === "object" && vid.duration?.seconds != null ? vid.duration.seconds * 1000 : typeof vid.duration === "object" && vid.duration?.seconds != null ? vid.duration.seconds * 1000 :
0; 0;
return { return {
title: vid.title, title: vid.title,
url: vid.type === "radio" ? vid.author?.url : vid.url, url: vid.type === "radio" ? vid.author?.url : vid.url,
@@ -499,7 +499,7 @@ export class Dashboard {
} }
/** /**
* @param {import("fluxer.js").GuildChannel} channel * @param {import("@fluxerjs/core").GuildChannel} channel
*/ */
static convertChannel(channel) { static convertChannel(channel) {
const isVoice = channel.isVoiceBased?.() ?? false; const isVoice = channel.isVoiceBased?.() ?? false;
@@ -509,7 +509,7 @@ export class Dashboard {
const guild = channel?.guild ?? channel?.client?.guilds?.get(channel?.guildId); const guild = channel?.guild ?? channel?.client?.guilds?.get(channel?.guildId);
if (guild?.voice_states) { if (guild?.voice_states) {
const vs = Array.isArray(guild.voice_states) ? guild.voice_states : const vs = Array.isArray(guild.voice_states) ? guild.voice_states :
typeof guild.voice_states.values === "function" ? [...guild.voice_states.values()] : Object.values(guild.voice_states); typeof guild.voice_states.values === "function" ? [...guild.voice_states.values()] : Object.values(guild.voice_states);
for (const state of vs) { for (const state of vs) {
const scId = String(state?.channelId ?? state?.channel_id ?? "").replace(/\D/g, ""); const scId = String(state?.channelId ?? state?.channel_id ?? "").replace(/\D/g, "");
const chId = String(channel?.id ?? "").replace(/\D/g, ""); const chId = String(channel?.id ?? "").replace(/\D/g, "");
@@ -535,7 +535,7 @@ export class Dashboard {
} }
/** /**
* @param {import("fluxer.js").Guild} guild * @param {import("@fluxerjs/core").Guild} guild
*/ */
static convertServer(guild) { static convertServer(guild) {
const channelStore = guild.channels; const channelStore = guild.channels;
@@ -561,7 +561,7 @@ export class Dashboard {
* Lightweight server summary for player payloads. * Lightweight server summary for player payloads.
* Unlike convertServer(), this omits the full channels array to keep * Unlike convertServer(), this omits the full channels array to keep
* per-player Redis messages small (especially for large guilds). * per-player Redis messages small (especially for large guilds).
* @param {import("fluxer.js").Guild} guild * @param {import("@fluxerjs/core").Guild} guild
*/ */
static convertServerSummary(guild) { static convertServerSummary(guild) {
return { return {
@@ -594,7 +594,7 @@ export class Dashboard {
const g = channel?.guild ?? channel?.client?.guilds?.get(channel?.guildId); const g = channel?.guild ?? channel?.client?.guilds?.get(channel?.guildId);
if (!g?.voice_states) return []; if (!g?.voice_states) return [];
const vs = Array.isArray(g.voice_states) ? g.voice_states : const vs = Array.isArray(g.voice_states) ? g.voice_states :
typeof g.voice_states.values === "function" ? [...g.voice_states.values()] : Object.values(g.voice_states); typeof g.voice_states.values === "function" ? [...g.voice_states.values()] : Object.values(g.voice_states);
const ids = []; const ids = [];
for (const state of vs) { for (const state of vs) {
const scId = String(state?.channelId ?? state?.channel_id ?? "").replace(/\D/g, ""); const scId = String(state?.channelId ?? state?.channel_id ?? "").replace(/\D/g, "");
@@ -696,7 +696,7 @@ export class Dashboard {
/** /**
* Global user update * Global user update
* @param {Object} details * @param {Object} details
* @param {import("fluxer.js").User} user * @param {import("@fluxerjs/core").User} user
*/ */
userUpdate(details, user) { userUpdate(details, user) {
if (!this.enabled) return; if (!this.enabled) return;