From b117fa9ad123cd06ae53ba555055583615c2efd7 Mon Sep 17 00:00:00 2001 From: Bobby Wibowo Date: Wed, 29 Jun 2022 13:58:09 +0700 Subject: [PATCH] feat: expose utils to nunjucks templates also fix nunjucks templates not adhering to env vars overrides for domains config options, because they attempted to read config directly --- controllers/uploadController.js | 2 +- lolisafe.js | 7 ++----- routes/album.js | 2 ++ routes/file.js | 3 +-- routes/nojs.js | 6 +++--- routes/player.js | 3 +-- views/_layout.njk | 2 +- views/album.njk | 2 +- views/file.njk | 2 +- views/home.njk | 4 ++-- views/nojs.njk | 4 ++-- views/player.njk | 2 +- 12 files changed, 18 insertions(+), 21 deletions(-) diff --git a/controllers/uploadController.js b/controllers/uploadController.js index 79c1d59..e95fac7 100644 --- a/controllers/uploadController.js +++ b/controllers/uploadController.js @@ -954,7 +954,7 @@ self.sendUploadResponse = async (req, res, user, result) => { // If uploaded by user, add delete URL (intended for ShareX and its derivatives) // Homepage uploader will not use this (use dashboard instead) if (user) { - map.deleteUrl = `${config.homeDomain}/file/${file.name}?delete` + map.deleteUrl = `${utils.conf.homeDomain}/file/${file.name}?delete` } return map diff --git a/lolisafe.js b/lolisafe.js index 8170cae..5aca5e2 100644 --- a/lolisafe.js +++ b/lolisafe.js @@ -288,14 +288,11 @@ safe.use('/api', api) safe.get(`/${page === 'home' ? '' : page}`, (req, res, next) => res.sendFile(customPage)) } else if (page === 'home') { safe.get('/', (req, res, next) => res.render(page, { - config, - versions: utils.versionStrings, - gitHash: utils.gitHash + config, utils, versions: utils.versionStrings })) } else { safe.get(`/${page}`, (req, res, next) => res.render(page, { - config, - versions: utils.versionStrings + config, utils, versions: utils.versionStrings })) } } diff --git a/routes/album.js b/routes/album.js index c561324..104e4b8 100644 --- a/routes/album.js +++ b/routes/album.js @@ -39,6 +39,7 @@ routes.get('/a/:identifier', async (req, res, next) => { if (!utils.albumsCache[cacheid].cache && utils.albumsCache[cacheid].generating) { return res.render('album-notice', { config, + utils, versions: utils.versionStrings, album, notice: 'This album\'s public page is still being generated. Please try again later.' @@ -81,6 +82,7 @@ routes.get('/a/:identifier', async (req, res, next) => { return res.render('album', { config, + utils, versions: utils.versionStrings, album, files, diff --git a/routes/file.js b/routes/file.js index 7d8bba1..9872a12 100644 --- a/routes/file.js +++ b/routes/file.js @@ -7,8 +7,7 @@ routes.get([ ], async (req, res, next) => { // Uploads identifiers parsing, etc., are strictly handled by client-side JS at src/js/file.js return res.render('file', { - config, - versions: utils.versionStrings + config, utils, versions: utils.versionStrings }) }) diff --git a/routes/nojs.js b/routes/nojs.js index ac0da27..131f4c8 100644 --- a/routes/nojs.js +++ b/routes/nojs.js @@ -6,8 +6,8 @@ const config = require('./../config') routes.get('/nojs', async (req, res, next) => { return res.render('nojs', { config, - versions: utils.versionStrings, - gitHash: utils.gitHash + utils, + versions: utils.versionStrings }) }) @@ -17,8 +17,8 @@ routes.post('/nojs', (req, res, next) => { const result = args[0] return res.render('nojs', { config, + utils, versions: utils.versionStrings, - gitHash: utils.gitHash, errorMessage: result.success ? '' : (result.description || 'An unexpected error occurred.'), files: result.files || [{}] }) diff --git a/routes/player.js b/routes/player.js index 4e3b1e7..df75f9a 100644 --- a/routes/player.js +++ b/routes/player.js @@ -8,8 +8,7 @@ routes.get([ ], async (req, res, next) => { // Uploads identifiers parsing, etc., are strictly handled by client-side JS at src/js/player.js return res.render('player', { - config, - versions: utils.versionStrings + config, utils, versions: utils.versionStrings }) }) diff --git a/views/_layout.njk b/views/_layout.njk index 7e77b5b..ad95107 100644 --- a/views/_layout.njk +++ b/views/_layout.njk @@ -1,7 +1,7 @@ {%- import '_globals.njk' as globals -%} {# Set root domain here to inherit values from config file #} -{%- set root = config.homeDomain or config.domain -%} +{%- set root = utils.conf.homeDomain or utils.conf.domain -%} {%- set title -%} {%- if metaTitle -%} diff --git a/views/album.njk b/views/album.njk index d6a9176..ceaff23 100644 --- a/views/album.njk +++ b/views/album.njk @@ -4,7 +4,7 @@ {% set metaDesc = album.description | striptags | truncate(200, true, '…') %} {% set metaUrl = '/' + album.url %} -{% set fileRoot = config.domain %} +{% set fileRoot = utils.conf.domain %} {% set metaImage = fileRoot + '/' + album.thumb %} {% extends "_layout.njk" %} diff --git a/views/file.njk b/views/file.njk index 511e3d9..5db53a7 100644 --- a/views/file.njk +++ b/views/file.njk @@ -2,7 +2,7 @@ {% set metaTitle = "File" %} -{% set uploadRoot = config.domain %} +{% set uploadRoot = utils.conf.domain %} {% set titleFormat = '%identifier% | ' + globals.name %} {% extends "_layout.njk" %} diff --git a/views/home.njk b/views/home.njk index e48a42f..b9f5f67 100644 --- a/views/home.njk +++ b/views/home.njk @@ -184,11 +184,11 @@ {% include "_partial/links.njk" %} - {% if gitHash -%} + {% if utils.gitHash -%}
- Git commit: {{ gitHash }} + Git commit: {{ utils.gitHash }}
diff --git a/views/nojs.njk b/views/nojs.njk index 7308036..967aac4 100644 --- a/views/nojs.njk +++ b/views/nojs.njk @@ -82,11 +82,11 @@ {% set plain_links = true %} {% include "_partial/links.njk" %} - {% if gitHash -%} + {% if utils.gitHash -%}
- Git commit: {{ gitHash }} + Git commit: {{ utils.gitHash }}
diff --git a/views/player.njk b/views/player.njk index 8d8b658..4dbb86e 100644 --- a/views/player.njk +++ b/views/player.njk @@ -2,7 +2,7 @@ {% set metaTitle = "Player" %} -{% set uploadRoot = config.domain %} +{% set uploadRoot = utils.conf.domain %} {% set titleFormat = '%identifier% | ' + globals.name %} {% extends "_layout.njk" %}