2024-04-27 12:59:27 +02:00
|
|
|
import { genericUserAgent } from "../config.js";
|
2024-11-28 11:01:26 +01:00
|
|
|
import { vkClientAgent } from "../processing/services/vk.js";
|
2024-04-27 12:59:27 +02:00
|
|
|
|
|
|
|
const defaultHeaders = {
|
|
|
|
'user-agent': genericUserAgent
|
|
|
|
}
|
|
|
|
|
|
|
|
const serviceHeaders = {
|
|
|
|
bilibili: {
|
|
|
|
referer: 'https://www.bilibili.com/'
|
|
|
|
},
|
|
|
|
youtube: {
|
|
|
|
accept: '*/*',
|
|
|
|
origin: 'https://www.youtube.com',
|
|
|
|
referer: 'https://www.youtube.com',
|
|
|
|
DNT: '?1'
|
2024-11-28 11:01:26 +01:00
|
|
|
},
|
|
|
|
vk: {
|
|
|
|
'user-agent': vkClientAgent
|
2024-04-27 12:59:27 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-06-23 17:37:02 +02:00
|
|
|
export function closeRequest(controller) {
|
|
|
|
try { controller.abort() } catch {}
|
|
|
|
}
|
|
|
|
|
2024-05-21 21:20:54 +02:00
|
|
|
export function closeResponse(res) {
|
2024-05-22 17:09:14 +02:00
|
|
|
if (!res.headersSent) {
|
|
|
|
res.sendStatus(500);
|
|
|
|
}
|
|
|
|
|
|
|
|
return res.end();
|
2024-05-21 21:20:54 +02:00
|
|
|
}
|
|
|
|
|
2024-04-27 12:59:27 +02:00
|
|
|
export function getHeaders(service) {
|
2024-05-21 22:41:43 +02:00
|
|
|
// Converting all header values to strings
|
|
|
|
return Object.entries({ ...defaultHeaders, ...serviceHeaders[service] })
|
|
|
|
.reduce((p, [key, val]) => ({ ...p, [key]: String(val) }), {})
|
2024-06-06 16:39:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
export function pipe(from, to, done) {
|
|
|
|
from.on('error', done)
|
|
|
|
.on('close', done);
|
|
|
|
|
|
|
|
to.on('error', done)
|
|
|
|
.on('close', done);
|
|
|
|
|
|
|
|
from.pipe(to);
|
2024-08-03 10:47:13 +02:00
|
|
|
}
|