mirror of
https://github.com/remix-bot/fluxer.git
synced 2026-11-24 06:01:44 -05:00
rollback
This commit is contained in:
1 parent
2f51b7e1d7
commit
97fe282bb3
29 files changed
+101
-431
No files matched your search
@@ -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 };
|
||||
@@ -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") {
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in new issue
Block a user