api/proxy: add support for proxying range requests

This commit is contained in:
dumbmoron 2024-08-31 07:15:20 +00:00
parent 305d0429f1
commit 2f63f6bab7
No known key found for this signature in database
2 changed files with 14 additions and 4 deletions

View file

@ -243,6 +243,11 @@ export const runAPI = (express, app, __dirname) => {
if (!streamInfo?.service) {
return res.status(streamInfo.status).end();
}
if (streamInfo.type === 'proxy') {
streamInfo.range = req.headers['range'];
}
return stream(res, streamInfo);
})

View file

@ -52,16 +52,21 @@ const proxy = async (streamInfo, res) => {
filename = `${streamInfo.filename}.${streamInfo.audioFormat}`
}
res.setHeader("Cross-Origin-Resource-Policy", "cross-origin");
res.setHeader('Cross-Origin-Resource-Policy', 'cross-origin');
res.setHeader('Content-disposition', contentDisposition(filename));
const { body: stream, headers } = await request(streamInfo.urls, {
headers: getHeaders(streamInfo.service),
const { body: stream, headers, statusCode } = await request(streamInfo.urls, {
headers: {
...getHeaders(streamInfo.service),
Range: streamInfo.range
},
signal: abortController.signal,
maxRedirections: 16
});
for (const headerName of ['content-type', 'content-length']) {
res.status(statusCode);
for (const headerName of ['accept-ranges', 'content-type', 'content-length']) {
if (headers[headerName]) {
res.setHeader(headerName, headers[headerName]);
}