[addon] adds experimental realdebrid support for cached torrents

This commit is contained in:
TheBeastLT
2020-03-17 15:17:10 +01:00
parent 7948f4877e
commit ea0250c910
7 changed files with 433 additions and 23 deletions

View File

@@ -4,8 +4,9 @@ const addonInterface = require('./addon');
const { manifest } = require('./lib/manifest');
const parseConfiguration = require('./lib/configuration');
const landingTemplate = require('./lib/landingTemplate');
const router = getRouter(addonInterface);
const realDebrid = require('./moch/realdebrid');
const router = getRouter(addonInterface);
const limiter = rateLimit({
windowMs: 10 * 1000, // 10 seconds
max: 10, // limit each IP to 10 requests per windowMs
@@ -68,6 +69,20 @@ router.get('/:configuration/:resource/:type/:id.json', (req, res, next) => {
});
});
router.get('/realdebrid/:apiKey/:infoHash/:fileIndex?', (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.redirect(301, url)
})
.catch(error => {
console.log(error);
res.sendStatus(404);
});
});
module.exports = function (req, res) {
router(req, res, function () {
res.statusCode = 404;