stream: use freebind dispatcher in internal streams
This commit is contained in:
parent
d5aa27f5f9
commit
9419266cd7
4 changed files with 20 additions and 5 deletions
|
@ -195,7 +195,8 @@ export default async function(host, patternMatch, url, lang, obj) {
|
||||||
return matchActionDecider(
|
return matchActionDecider(
|
||||||
r, host, obj.aFormat, isAudioOnly,
|
r, host, obj.aFormat, isAudioOnly,
|
||||||
lang, isAudioMuted, disableMetadata,
|
lang, isAudioMuted, disableMetadata,
|
||||||
obj.filenamePattern, obj.twitterGif
|
obj.filenamePattern, obj.twitterGif,
|
||||||
|
requestIP
|
||||||
)
|
)
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
return apiJSON(0, { t: genericError(lang, host) })
|
return apiJSON(0, { t: genericError(lang, host) })
|
||||||
|
|
|
@ -3,7 +3,7 @@ import { apiJSON } from "../sub/utils.js";
|
||||||
import loc from "../../localization/manager.js";
|
import loc from "../../localization/manager.js";
|
||||||
import createFilename from "./createFilename.js";
|
import createFilename from "./createFilename.js";
|
||||||
|
|
||||||
export default function(r, host, userFormat, isAudioOnly, lang, isAudioMuted, disableMetadata, filenamePattern, toGif) {
|
export default function(r, host, userFormat, isAudioOnly, lang, isAudioMuted, disableMetadata, filenamePattern, toGif, requestIP) {
|
||||||
let action,
|
let action,
|
||||||
responseType = 2,
|
responseType = 2,
|
||||||
defaultParams = {
|
defaultParams = {
|
||||||
|
@ -11,7 +11,8 @@ export default function(r, host, userFormat, isAudioOnly, lang, isAudioMuted, di
|
||||||
service: host,
|
service: host,
|
||||||
filename: r.filenameAttributes ?
|
filename: r.filenameAttributes ?
|
||||||
createFilename(r.filenameAttributes, filenamePattern, isAudioOnly, isAudioMuted) : r.filename,
|
createFilename(r.filenameAttributes, filenamePattern, isAudioOnly, isAudioMuted) : r.filename,
|
||||||
fileMetadata: !disableMetadata ? r.fileMetadata : false
|
fileMetadata: !disableMetadata ? r.fileMetadata : false,
|
||||||
|
requestIP
|
||||||
},
|
},
|
||||||
params = {},
|
params = {},
|
||||||
audioFormat = String(userFormat);
|
audioFormat = String(userFormat);
|
||||||
|
|
|
@ -18,6 +18,7 @@ async function* readChunks(streamInfo, size) {
|
||||||
...getHeaders('youtube'),
|
...getHeaders('youtube'),
|
||||||
Range: `bytes=${read}-${read + CHUNK_SIZE}`
|
Range: `bytes=${read}-${read + CHUNK_SIZE}`
|
||||||
},
|
},
|
||||||
|
dispatcher: streamInfo.dispatcher,
|
||||||
signal: streamInfo.controller.signal
|
signal: streamInfo.controller.signal
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -47,6 +48,7 @@ async function handleYoutubeStream(streamInfo, res) {
|
||||||
const req = await fetch(streamInfo.url, {
|
const req = await fetch(streamInfo.url, {
|
||||||
headers: getHeaders('youtube'),
|
headers: getHeaders('youtube'),
|
||||||
method: 'HEAD',
|
method: 'HEAD',
|
||||||
|
dispatcher: streamInfo.dispatcher,
|
||||||
signal: streamInfo.controller.signal
|
signal: streamInfo.controller.signal
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -81,6 +83,7 @@ export async function internalStream(streamInfo, res) {
|
||||||
...streamInfo.headers,
|
...streamInfo.headers,
|
||||||
host: undefined
|
host: undefined
|
||||||
},
|
},
|
||||||
|
dispatcher: streamInfo.dispatcher,
|
||||||
signal: streamInfo.controller.signal,
|
signal: streamInfo.controller.signal,
|
||||||
maxRedirections: 16
|
maxRedirections: 16
|
||||||
});
|
});
|
||||||
|
|
|
@ -6,6 +6,9 @@ import { decryptStream, encryptStream, generateHmac } from "../sub/crypto.js";
|
||||||
import { streamLifespan, env } from "../config.js";
|
import { streamLifespan, env } from "../config.js";
|
||||||
import { strict as assert } from "assert";
|
import { strict as assert } from "assert";
|
||||||
|
|
||||||
|
// optional dependency
|
||||||
|
const freebind = env.freebindCIDR && await import('freebind').catch(() => {});
|
||||||
|
|
||||||
const M3U_SERVICES = ['dailymotion', 'vimeo', 'rutube'];
|
const M3U_SERVICES = ['dailymotion', 'vimeo', 'rutube'];
|
||||||
|
|
||||||
const streamNoAccess = {
|
const streamNoAccess = {
|
||||||
|
@ -46,7 +49,8 @@ export function createStream(obj) {
|
||||||
isAudioOnly: !!obj.isAudioOnly,
|
isAudioOnly: !!obj.isAudioOnly,
|
||||||
copy: !!obj.copy,
|
copy: !!obj.copy,
|
||||||
mute: !!obj.mute,
|
mute: !!obj.mute,
|
||||||
metadata: obj.fileMetadata || false
|
metadata: obj.fileMetadata || false,
|
||||||
|
requestIP: obj.requestIP
|
||||||
};
|
};
|
||||||
|
|
||||||
streamCache.set(
|
streamCache.set(
|
||||||
|
@ -78,11 +82,17 @@ export function getInternalStream(id) {
|
||||||
export function createInternalStream(url, obj = {}) {
|
export function createInternalStream(url, obj = {}) {
|
||||||
assert(typeof url === 'string');
|
assert(typeof url === 'string');
|
||||||
|
|
||||||
|
let dispatcher;
|
||||||
|
if (obj.requestIP) {
|
||||||
|
dispatcher = freebind?.dispatcherFromIP(obj.requestIP, { strict: false })
|
||||||
|
}
|
||||||
|
|
||||||
const streamID = nanoid();
|
const streamID = nanoid();
|
||||||
internalStreamCache[streamID] = {
|
internalStreamCache[streamID] = {
|
||||||
url,
|
url,
|
||||||
service: obj.service,
|
service: obj.service,
|
||||||
controller: new AbortController()
|
controller: new AbortController(),
|
||||||
|
dispatcher
|
||||||
};
|
};
|
||||||
|
|
||||||
let streamLink = new URL('/api/istream', `http://127.0.0.1:${env.apiPort}`);
|
let streamLink = new URL('/api/istream', `http://127.0.0.1:${env.apiPort}`);
|
||||||
|
|
Loading…
Reference in a new issue