Update proxy
This commit is contained in:
parent
7345b98579
commit
3256e845aa
|
@ -8,22 +8,35 @@ export function requiresProxy(stream: Stream): boolean {
|
||||||
}
|
}
|
||||||
|
|
||||||
export function setupProxy(stream: Stream): Stream {
|
export function setupProxy(stream: Stream): Stream {
|
||||||
const headers =
|
const headers = stream.headers && Object.keys(stream.headers).length > 0 ? stream.headers : undefined;
|
||||||
stream.headers && Object.keys(stream.headers).length > 0 ? btoa(JSON.stringify(stream.headers)) : null;
|
|
||||||
|
|
||||||
const options = btoa(
|
const options = {
|
||||||
JSON.stringify({
|
|
||||||
...(stream.type === 'hls' && { depth: stream.proxyDepth ?? 0 }),
|
...(stream.type === 'hls' && { depth: stream.proxyDepth ?? 0 }),
|
||||||
}),
|
};
|
||||||
);
|
|
||||||
|
|
||||||
if (stream.type === 'hls')
|
const payload: {
|
||||||
stream.playlist = `https://proxy.nsbx.ru/hls/${btoa(stream.playlist)}/${headers}/${options}`;
|
type?: 'hls' | 'mp4';
|
||||||
|
url?: string;
|
||||||
|
headers?: Record<string, string>;
|
||||||
|
options?: { depth?: 0 | 1 | 2 };
|
||||||
|
} = {
|
||||||
|
headers,
|
||||||
|
options,
|
||||||
|
};
|
||||||
|
|
||||||
if (stream.type === 'file')
|
if (stream.type === 'hls') {
|
||||||
|
payload.type = 'hls';
|
||||||
|
payload.url = stream.playlist;
|
||||||
|
stream.playlist = `https://proxy.nsbx.ru/proxy?${new URLSearchParams({ payload: Buffer.from(JSON.stringify(payload)).toString('base64url') })}`;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (stream.type === 'file') {
|
||||||
|
payload.type = 'mp4';
|
||||||
Object.entries(stream.qualities).forEach((entry) => {
|
Object.entries(stream.qualities).forEach((entry) => {
|
||||||
entry[1].url = `https://proxy.nsbx.ru/mp4/${btoa(entry[1].url)}/${headers}/${options}`;
|
payload.url = entry[1].url;
|
||||||
|
entry[1].url = `https://proxy.nsbx.ru/proxy?${new URLSearchParams({ payload: Buffer.from(JSON.stringify(payload)).toString('base64url') })}`;
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
|
||||||
stream.headers = {};
|
stream.headers = {};
|
||||||
stream.flags = [flags.CORS_ALLOWED];
|
stream.flags = [flags.CORS_ALLOWED];
|
||||||
|
|
Loading…
Reference in New Issue