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}`);
|
||||
if (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 fileLink = info.links.length === 1
|
||||
? info.links[0]
|
||||
: info.links[selectedFiles.indexOf(downloadFile)];
|
||||
: info.links[selectedFiles.indexOf(targetFile)];
|
||||
return _unrestrictLink(RD, fileLink);
|
||||
}
|
||||
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;
|
||||
console.time(infoHash);
|
||||
realDebrid.unrestrict(apiKey, infoHash, isNaN(fileIndex) ? undefined : parseInt(fileIndex))
|
||||
.then(url => {
|
||||
console.timeEnd(infoHash);
|
||||
res.writeHead(301, { Location: url });
|
||||
res.writeHead(301, {
|
||||
'Location': url,
|
||||
'Cache-Control': 'max-age=7200, public'
|
||||
});
|
||||
res.end();
|
||||
})
|
||||
.catch(error => {
|
||||
|
||||
Reference in New Issue
Block a user