[addon] populate existing config values in template

This commit is contained in:
TheBeastLT
2020-03-19 20:01:59 +01:00
parent e8390ad2a5
commit 25aafc7555
3 changed files with 9 additions and 3 deletions

View File

@@ -185,7 +185,11 @@ button:active {
const { Providers } = require('./manifest'); const { Providers } = require('./manifest');
const { SortType } = require('./sort'); const { SortType } = require('./sort');
function landingTemplate(manifest, providers = [], realDebridApiKey = '') { function landingTemplate(manifest, config = {}) {
const providers = config.providers || [];
const realDebridApiKey = config.realdebrid || '';
const sort = config.sort === SortType.SEEDERS ? SortType.SEEDERS : SortType.QUALITY;
const limit = config.limit || '';
const background = manifest.background || 'https://dl.strem.io/addon-background.jpg'; const background = manifest.background || 'https://dl.strem.io/addon-background.jpg';
const logo = manifest.logo || 'https://dl.strem.io/addon-logo.png'; const logo = manifest.logo || 'https://dl.strem.io/addon-logo.png';
const contactHTML = manifest.contactEmail ? const contactHTML = manifest.contactEmail ?
@@ -266,6 +270,8 @@ function landingTemplate(manifest, providers = [], realDebridApiKey = '') {
}); });
$('#iProviders').multiselect('select', [${providers.map(provider => '"' + provider + '"')}]); $('#iProviders').multiselect('select', [${providers.map(provider => '"' + provider + '"')}]);
$('#iRealDebrid').val("${realDebridApiKey}"); $('#iRealDebrid').val("${realDebridApiKey}");
$('#iSort').val("${sort}");
$('#iLimit').val("${limit}");
generateInstallLink(); generateInstallLink();
}); });

View File

@@ -22,7 +22,7 @@ router.get('/', (_, res) => {
router.get('/:configuration', (req, res) => { router.get('/:configuration', (req, res) => {
const configValues = parseConfiguration(req.params.configuration); const configValues = parseConfiguration(req.params.configuration);
const landingHTML = landingTemplate(manifest(configValues), configValues.providers, configValues.realdebrid); const landingHTML = landingTemplate(manifest(configValues), configValues);
res.setHeader('content-type', 'text/html'); res.setHeader('content-type', 'text/html');
res.end(landingHTML); res.end(landingHTML);
}); });