[addon] add cache control for redirect

This commit is contained in:
TheBeastLT
2020-03-17 18:50:21 +01:00
parent 7fd638b9e0
commit 99e489f8b8
2 changed files with 7 additions and 4 deletions

View File

@@ -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");

View File

@@ -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 => {