mirror of
https://github.com/wukko/cobalt.git
synced 2025-02-24 03:58:49 +01:00
api/proxy: add support for proxying range requests
This commit is contained in:
parent
305d0429f1
commit
2f63f6bab7
2 changed files with 14 additions and 4 deletions
|
@ -243,6 +243,11 @@ export const runAPI = (express, app, __dirname) => {
|
||||||
if (!streamInfo?.service) {
|
if (!streamInfo?.service) {
|
||||||
return res.status(streamInfo.status).end();
|
return res.status(streamInfo.status).end();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (streamInfo.type === 'proxy') {
|
||||||
|
streamInfo.range = req.headers['range'];
|
||||||
|
}
|
||||||
|
|
||||||
return stream(res, streamInfo);
|
return stream(res, streamInfo);
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
|
@ -52,16 +52,21 @@ const proxy = async (streamInfo, res) => {
|
||||||
filename = `${streamInfo.filename}.${streamInfo.audioFormat}`
|
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));
|
res.setHeader('Content-disposition', contentDisposition(filename));
|
||||||
|
|
||||||
const { body: stream, headers } = await request(streamInfo.urls, {
|
const { body: stream, headers, statusCode } = await request(streamInfo.urls, {
|
||||||
headers: getHeaders(streamInfo.service),
|
headers: {
|
||||||
|
...getHeaders(streamInfo.service),
|
||||||
|
Range: streamInfo.range
|
||||||
|
},
|
||||||
signal: abortController.signal,
|
signal: abortController.signal,
|
||||||
maxRedirections: 16
|
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]) {
|
if (headers[headerName]) {
|
||||||
res.setHeader(headerName, headers[headerName]);
|
res.setHeader(headerName, headers[headerName]);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue