This commit is contained in:
NoLogicAlan committed 2026-10-06 00:32:48 +03:00
1 parent 2f51b7e1d7
commit 97fe282bb3
29 files changed
+101 -431

No files matched your search

-4
View File
@@ -32,10 +32,6 @@ export class LavalinkManager extends EventEmitter {
this._client = client;
const requestSignalTimeoutMS = Number(nodeCfg.requestTimeout ?? 60_000);
if (["youshallnotpass", "change-me-nodelink"].includes(nodeCfg.password ?? "youshallnotpass")) {
logger.warn("[Lavalink] NodeLink is using a well-known/placeholder password. Set a strong one in config.json (nodelink.password) and as NODELINK_PASSWORD in docker/.env.");
}
this.lavalink = new LavalinkClientManager({
nodes: [
{
+2 -8
View File
@@ -220,10 +220,7 @@ export class PlayerManager {
try {
const textChannelId = message?.channel?.id ?? message?.channel?.channel?.id ?? null;
if (guildId && textChannelId) {
const announceSrv = this.settings.getServer(guildId);
if (announceSrv && announceSrv.get("announcementChannelId") !== textChannelId) {
announceSrv.set("announcementChannelId", textChannelId);
}
this.settings.getServer(guildId)?.set("announcementChannelId", textChannelId);
}
} catch(e) {
logger.warn("[PlayerManager] Failed to save announcement channel ID:", e?.message);
@@ -259,10 +256,7 @@ export class PlayerManager {
try {
const textChannelId = message?.channel?.id ?? message?.channel?.channel?.id ?? null;
if (cleanGuildId && textChannelId) {
const announceSrv = this.settings.getServer(cleanGuildId);
if (announceSrv && announceSrv.get("announcementChannelId") !== textChannelId) {
announceSrv.set("announcementChannelId", textChannelId);
}
this.settings.getServer(cleanGuildId)?.set("announcementChannelId", textChannelId);
}
} catch(e) {
logger.warn("[PlayerManager] Failed to save announcement channel ID:", e?.message);
+1 -12
View File
@@ -4,8 +4,6 @@
const _settings = {
/** @type {boolean} @description Whether the legacy /v4/loadstream route may be used (server-side seek, filters, MP3/AAC decode). Disabled by default: playback runs on /v4/trackstream only. */
allowLoadstream: false,
/** @type {boolean} @description Whether direct audio URLs typed by users may point at private/loopback/link-local addresses (LAN radio, a home Icecast...). Off by default so %play cannot be used to probe internal services. Admin-configured radio stations and the local Bilibili proxy are always trusted. */
allowPrivateUrls: false,
};
/**
@@ -17,8 +15,6 @@ const _settings = {
export function configureAudio(section = null) {
const raw = section?.allowLoadstream;
_settings.allowLoadstream = raw === true || raw === "true";
const rawPrivate = section?.allowPrivateUrls;
_settings.allowPrivateUrls = rawPrivate === true || rawPrivate === "true";
}
/**
@@ -37,11 +33,4 @@ export function isLoadstreamEnabled() {
return _settings.allowLoadstream === true;
}
/**
* @returns {boolean} Whether user-supplied direct URLs may target private/internal addresses.
*/
export function isPrivateUrlsAllowed() {
return _settings.allowPrivateUrls === true;
}
export default { configureAudio, getAudioSettings, isLoadstreamEnabled, isPrivateUrlsAllowed };
export default { configureAudio, getAudioSettings, isLoadstreamEnabled };
+8 -5
View File
@@ -2,9 +2,9 @@
import { logger } from "../../core/Logger.mjs";
import { EventEmitter } from "node:events";
import { Readable } from "node:stream";
import { applyMixins } from "../../utils/mixins.mjs";
import { isLoadstreamEnabled, isPrivateUrlsAllowed } from "./AudioSettings.mjs";
import { openPublicStream } from "./SafeHttp.mjs";
import { isLoadstreamEnabled } from "./AudioSettings.mjs";
import StreamPipeline from "./StreamPipeline.mjs";
import HttpStreams from "./HttpStreams.mjs";
@@ -168,12 +168,15 @@ export class FluxerAudioBridge extends EventEmitter {
// source page.
if (!trackInfo.encoded && trackInfo.url && trackInfo.url.startsWith("http")) {
logger.player("[AudioBridge] Route 3: Fetching directly: " + trackInfo.url.substring(0, 80) + "...");
const { stream, req: sourceReq } = await openPublicStream(trackInfo.url, {
const response = await fetch(trackInfo.url, {
headers: { "User-Agent": "Mozilla/5.0 (compatible; Bot/1.0)" },
allowPrivate: trackInfo.trusted === true || isPrivateUrlsAllowed(),
redirect: "follow",
});
if (!response.ok) {
throw new Error("HTTP " + response.status + " for " + trackInfo.url);
}
const stream = Readable.fromWeb(response.body);
this._sourceStream = stream;
this._sourceReq = sourceReq;
const routed = await this._routeByMagic(stream);
if (routed.kind === "webm") {
+3 -31
View File
@@ -26,11 +26,6 @@ const PCM_FRAME_SIZE = 960;
/** @type {number} @description Opus encoding bitrate. */
const OPUS_BITRATE = 128000;
/** @type {number} @description Max wait for the first bytes of a stream when sniffing its container. */
const PEEK_TIMEOUT_MS = 15_000;
/** @type {number} @description Max wait for an OpusHead before an Ogg stream is declared "not Ogg/Opus". */
const OGG_HEAD_TIMEOUT_MS = 10_000;
/** @type {Buffer} @description WebM/Matroska EBML magic bytes. */
const WEBM_MAGIC = Buffer.from([0x1a, 0x45, 0xdf, 0xa3]);
/** @type {Buffer} @description OGG container magic bytes ("OggS"). */
@@ -173,7 +168,7 @@ const StreamPipeline = {
* @returns {Promise<Buffer>}
* @private
*/
_peek(stream, n, timeoutMs = PEEK_TIMEOUT_MS) {
_peek(stream, n) {
return new Promise((resolve, reject) => {
const tryRead = () => {
const chunks = [];
@@ -194,9 +189,7 @@ const StreamPipeline = {
const onReadable = () => { cleanup(); tryRead(); };
const onEnd = () => { cleanup(); tryRead(); };
const onError = (err) => { cleanup(); reject(err); };
let timer = null;
const cleanup = () => {
if (timer) { clearTimeout(timer); timer = null; }
stream.off("readable", onReadable);
stream.off("end", onEnd);
stream.off("error", onError);
@@ -204,10 +197,6 @@ const StreamPipeline = {
stream.once("readable", onReadable);
stream.once("end", onEnd);
stream.once("error", onError);
timer = setTimeout(() => {
cleanup();
reject(new Error("Timed out waiting for stream data (" + timeoutMs + "ms)"));
}, timeoutMs);
tryRead();
});
},
@@ -259,37 +248,20 @@ const StreamPipeline = {
* @returns {Promise<{stream: WebMOpusMuxer, getDurationMs: function}>}
* @private
*/
async _remuxOggToWebM(oggStream, { headTimeoutMs = OGG_HEAD_TIMEOUT_MS } = {}) {
async _remuxOggToWebM(oggStream) {
const demuxer = new PrismOggDemuxer();
const muxer = new WebMOpusMuxer();
muxer.on("error", () => {});
oggStream.on("error", (err) => demuxer.destroy(err));
demuxer.on("error", (err) => muxer.destroy(err));
let frameCount = 0;
demuxer.on("data", () => { frameCount++; });
let headTimer = null;
const headPromise = new Promise((resolve, reject) => {
demuxer.once("head", () => resolve());
demuxer.once("error", (err) => reject(new Error("OGG demux: " + err.message)));
oggStream.once("error", (err) => reject(new Error("OGG source: " + err.message)));
demuxer.once("end", () => reject(new Error("Ogg stream ended without an OpusHead (not Ogg/Opus)")));
demuxer.once("close", () => reject(new Error("Ogg demuxer closed before an OpusHead was seen")));
headTimer = setTimeout(
() => reject(new Error("Timed out waiting for an OpusHead (" + headTimeoutMs + "ms): not Ogg/Opus or the source stalled")),
headTimeoutMs
);
});
oggStream.pipe(demuxer).pipe(muxer);
try {
await headPromise;
} catch (err) {
try { oggStream.destroy(); } catch (_) {}
try { demuxer.destroy(); } catch (_) {}
try { muxer.destroy(); } catch (_) {}
throw err;
} finally {
clearTimeout(headTimer);
}
await headPromise;
const wrapper = Object.create(muxer);
wrapper.getDurationMs = () => frameCount * OPUS_FRAME_MS;
return wrapper;
+1 -4
View File
@@ -122,7 +122,6 @@ const PlaybackMixin = {
if (currentBeforeNext) this._lastPlayedTrack = currentBeforeNext;
const songData = this.queue.next();
if (!songData) {
this._consecutiveErrors = 0;
this.emit("stopplay");
this.emit("queueEnd");
@@ -172,6 +171,7 @@ const PlaybackMixin = {
this._paused = false;
this._pausedAt = null;
this._queueEndedSent = false;
this._consecutiveErrors = 0;
this._radioReconnects = 0;
if (songData.type !== "radio" || !this._radioAnnounced) {
@@ -214,8 +214,6 @@ const PlaybackMixin = {
await this._playTrackViaBridge(songData, { seekSeconds: seekSec });
}
this._consecutiveErrors = 0;
if (trackOptMatch && trackOptMatch.endMs > 0) {
const elapsedMs = Date.now() - this.startedPlaying;
const remainingMs = trackOptMatch.endMs - elapsedMs;
@@ -315,7 +313,6 @@ const PlaybackMixin = {
url: bridgeUrl,
title: songData.title,
guildId: this._guildId,
trusted: songData.type === "radio" || songData.type === "bilibili",
}, {
seekSeconds: options.seekSeconds ?? 0,
durationMs,
+3 -3
View File
@@ -67,7 +67,7 @@ export class Queue extends EventEmitter {
* @returns {string} Result message indicating success or out-of-bounds error.
*/
remove(idx) {
if (!Number.isInteger(idx) || idx < 0 || idx >= this.data.length) return "Index out of bounds";
if (idx < 0 || idx >= this.data.length) return "Index out of bounds";
const title = this.data[idx].title;
const removed = this.data.splice(idx, 1);
this.emit("queue", { type: "remove", data: { index: idx, old: this.data.slice(), removed, new: this.data } });
@@ -81,8 +81,8 @@ export class Queue extends EventEmitter {
* @returns {string} Result message indicating success or error.
*/
move(from, to) {
if (!Number.isInteger(from) || from < 0 || from >= this.data.length) return "Source index out of bounds";
if (!Number.isInteger(to) || to < 0 || to >= this.data.length) return "Target index out of bounds";
if (from < 0 || from >= this.data.length) return "Source index out of bounds";
if (to < 0 || to >= this.data.length) return "Target index out of bounds";
if (from === to) return "Track is already in that position";
const [track] = this.data.splice(from, 1);
this.data.splice(to, 0, track);