mirror of
https://github.com/knightcrawler-stremio/knightcrawler.git
synced 2024-12-20 03:29:51 +00:00
[addon] adds filtering based on provider
This commit is contained in:
@@ -22,19 +22,52 @@ router.get('/', (_, res) => {
|
||||
|
||||
router.get('/:configuration', (req, res) => {
|
||||
const configValues = parseConfiguration(req.params.configuration);
|
||||
console.log(configValues);
|
||||
const landingHTML = landingTemplate(manifest(), configValues.providers, configValues.realdebrid);
|
||||
const landingHTML = landingTemplate(manifest(configValues), configValues.providers, configValues.realdebrid);
|
||||
res.setHeader('content-type', 'text/html');
|
||||
res.end(landingHTML);
|
||||
});
|
||||
|
||||
router.get('/:configuration/manifest.json', (req, res) => {
|
||||
const configValues = parseConfiguration(req.params.configuration);
|
||||
const manifestBuf = JSON.stringify(manifest(configValues.providers, configValues.realdebrid));
|
||||
const manifestBuf = JSON.stringify(manifest(configValues));
|
||||
res.setHeader('Content-Type', 'application/json; charset=utf-8');
|
||||
res.end(manifestBuf)
|
||||
});
|
||||
|
||||
router.get('/:configuration/:resource/:type/:id.json', (req, res, next) => {
|
||||
const { configuration, resource, type, id } = req.params;
|
||||
const configValues = parseConfiguration(configuration);
|
||||
addonInterface.get(resource, type, id, configValues)
|
||||
.then(resp => {
|
||||
const cacheHeaders = {
|
||||
cacheMaxAge: 'max-age',
|
||||
staleRevalidate: 'stale-while-revalidate',
|
||||
staleError: 'stale-if-error'
|
||||
};
|
||||
const cacheControl = Object.keys(cacheHeaders)
|
||||
.map(prop => resp[prop] && cacheHeaders[prop] + '=' + resp[prop])
|
||||
.filter(val => !!val).join(', ');
|
||||
|
||||
res.setHeader('Cache-Control', `${cacheControl}, public`);
|
||||
res.setHeader('Content-Type', 'application/json; charset=utf-8');
|
||||
res.end(JSON.stringify(resp));
|
||||
})
|
||||
.catch(err => {
|
||||
if (err.noHandler) {
|
||||
if (next) {
|
||||
next()
|
||||
} else {
|
||||
res.writeHead(404);
|
||||
res.end(JSON.stringify({ err: 'not found' }));
|
||||
}
|
||||
} else {
|
||||
console.error(err);
|
||||
res.writeHead(500);
|
||||
res.end(JSON.stringify({ err: 'handler error' }));
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
module.exports = function (req, res) {
|
||||
router(req, res, function () {
|
||||
res.statusCode = 404;
|
||||
|
||||
Reference in New Issue
Block a user