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