[addon] add min api key length requirement check

This commit is contained in:
TheBeastLT
2020-12-24 12:10:07 +01:00
parent 59d4bfaa66
commit d299f4e024

View File

@@ -7,6 +7,7 @@ const putio = require('./putio');
const StaticResponse = require('./static');
const { cacheWrapResolvedUrl } = require('../lib/cache');
const MIN_API_KEY_SYMBOLS = 20;
const RESOLVER_HOST = process.env.RESOLVER_HOST || 'http://localhost:7050';
const MOCHS = {
realdebrid: {
@@ -51,6 +52,7 @@ async function applyMochs(streams, config) {
const configuredMochs = Object.keys(config)
.filter(configKey => MOCHS[configKey])
.filter(configKey => config[configKey].length >= MIN_API_KEY_SYMBOLS)
.map(configKey => MOCHS[configKey]);
const mochResults = await Promise.all(configuredMochs
.map(moch => moch.instance.getCachedStreams(streams, config[moch.key])
@@ -93,6 +95,9 @@ async function getMochCatalog(mochKey, config) {
if (!moch) {
return Promise.reject(`Not a valid moch provider: ${mochKey}`);
}
if (config[mochKey].length < MIN_API_KEY_SYMBOLS) {
return Promise.reject(`Invalid API key for moch provider: ${mochKey}`);
}
return moch.instance.getCatalog(config[moch.key], config.skip);
}