mirror of
https://github.com/knightcrawler-stremio/knightcrawler.git
synced 2024-12-20 03:29:51 +00:00
[addon] add cache control for redirect
This commit is contained in:
@@ -44,11 +44,11 @@ async function _unrestrict(apiKey, infoHash, fileIndex) {
|
|||||||
console.log(`Retrieved torrentId: ${torrentId}`);
|
console.log(`Retrieved torrentId: ${torrentId}`);
|
||||||
if (torrentId) {
|
if (torrentId) {
|
||||||
const info = await RD.torrents.info(torrentId);
|
const info = await RD.torrents.info(torrentId);
|
||||||
const downloadFile = info.files.find(file => file.id === fileIndex + 1);
|
const targetFile = info.files.find(file => file.id === fileIndex + 1);
|
||||||
const selectedFiles = info.files.filter(file => file.selected);
|
const selectedFiles = info.files.filter(file => file.selected);
|
||||||
const fileLink = info.links.length === 1
|
const fileLink = info.links.length === 1
|
||||||
? info.links[0]
|
? info.links[0]
|
||||||
: info.links[selectedFiles.indexOf(downloadFile)];
|
: info.links[selectedFiles.indexOf(targetFile)];
|
||||||
return _unrestrictLink(RD, fileLink);
|
return _unrestrictLink(RD, fileLink);
|
||||||
}
|
}
|
||||||
return Promise.reject("Failed adding torrent");
|
return Promise.reject("Failed adding torrent");
|
||||||
|
|||||||
@@ -69,13 +69,16 @@ router.get('/:configuration/:resource/:type/:id.json', (req, res, next) => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
router.get('/realdebrid/:apiKey/:infoHash/:fileIndex?', (req, res) => {
|
router.get('/realdebrid/:apiKey/:infoHash/:fileIndex?.json', (req, res) => {
|
||||||
const { apiKey, infoHash, fileIndex } = req.params;
|
const { apiKey, infoHash, fileIndex } = req.params;
|
||||||
console.time(infoHash);
|
console.time(infoHash);
|
||||||
realDebrid.unrestrict(apiKey, infoHash, isNaN(fileIndex) ? undefined : parseInt(fileIndex))
|
realDebrid.unrestrict(apiKey, infoHash, isNaN(fileIndex) ? undefined : parseInt(fileIndex))
|
||||||
.then(url => {
|
.then(url => {
|
||||||
console.timeEnd(infoHash);
|
console.timeEnd(infoHash);
|
||||||
res.writeHead(301, { Location: url });
|
res.writeHead(301, {
|
||||||
|
'Location': url,
|
||||||
|
'Cache-Control': 'max-age=7200, public'
|
||||||
|
});
|
||||||
res.end();
|
res.end();
|
||||||
})
|
})
|
||||||
.catch(error => {
|
.catch(error => {
|
||||||
|
|||||||
Reference in New Issue
Block a user