filesafe/routes/nojs.js
Bobby Wibowo b117fa9ad1
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
2022-06-29 13:58:09 +07:00

30 lines
794 B
JavaScript

const routes = require('express').Router()
const uploadController = require('./../controllers/uploadController')
const utils = require('./../controllers/utilsController')
const config = require('./../config')
routes.get('/nojs', async (req, res, next) => {
return res.render('nojs', {
config,
utils,
versions: utils.versionStrings
})
})
routes.post('/nojs', (req, res, next) => {
res._json = res.json
res.json = (...args) => {
const result = args[0]
return res.render('nojs', {
config,
utils,
versions: utils.versionStrings,
errorMessage: result.success ? '' : (result.description || 'An unexpected error occurred.'),
files: result.files || [{}]
})
}
return uploadController.upload(req, res, next)
})
module.exports = routes