filesafe/routes/nojs.js
Bobby Wibowo 0d38995b2b
Updates
* When gitHash in config.js is set to true, latest commit hash of the currently enabled git repo/branch will be displayed in home and nojs uploader pages.

* Error pages can now be configured with errorPages option (their root directory and their file names).
2018-09-20 18:41:17 +07:00

44 lines
1.1 KiB
JavaScript

const config = require('./../config')
const routes = require('express').Router()
const uploadController = require('./../controllers/uploadController')
const renderOptions = {
uploadDisabled: false,
maxFileSize: config.cloudflare.noJsMaxSize || config.uploads.maxSize
}
if (config.private) {
if (config.enableUserAccounts) {
renderOptions.uploadDisabled = 'Anonymous upload is disabled.'
} else {
renderOptions.uploadDisabled = 'Running in private mode.'
}
}
routes.get('/nojs', async (req, res, next) => {
const options = { renderOptions }
options.gitHash = req.app.get('git-hash')
return res.render('nojs', options)
})
routes.post('/nojs', (req, res, next) => {
// TODO: Support upload by URLs.
res._json = res.json
res.json = (...args) => {
const result = args[0]
const options = { renderOptions }
options.gitHash = req.app.get('git-hash')
options.errorMessage = result.success ? '' : (result.description || 'An unexpected error occurred.')
options.files = result.files || [{}]
return res.render('nojs', options)
}
return uploadController.upload(req, res, next)
})
module.exports = routes