mirror of
https://github.com/imputnet/cobalt.git
synced 2024-12-29 11:06:10 +00:00
api/proxy: add support for proxying range requests
This commit is contained in:
parent
305d0429f1
commit
2f63f6bab7
|
@ -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);
|
||||
})
|
||||
|
||||
|
|
|
@ -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]);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue