2018-04-13 16:20:57 +00:00
|
|
|
const config = require('./../config')
|
2018-04-12 14:37:42 +00:00
|
|
|
const routes = require('express').Router()
|
2018-04-13 16:20:57 +00:00
|
|
|
const uploadController = require('./../controllers/uploadController')
|
|
|
|
|
|
|
|
const renderOptions = {
|
|
|
|
uploadDisabled: false,
|
2018-05-09 08:41:30 +00:00
|
|
|
maxFileSize: config.cloudflare.noJsMaxSize || config.uploads.maxSize
|
2018-04-13 16:20:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (config.private) {
|
|
|
|
if (config.enableUserAccounts) {
|
|
|
|
renderOptions.uploadDisabled = 'Anonymous upload is disabled.'
|
|
|
|
} else {
|
|
|
|
renderOptions.uploadDisabled = 'Running in private mode.'
|
|
|
|
}
|
|
|
|
}
|
2018-04-12 14:37:42 +00:00
|
|
|
|
|
|
|
routes.get('/nojs', async (req, res, next) => {
|
2018-09-20 11:41:17 +00:00
|
|
|
const options = { renderOptions }
|
|
|
|
options.gitHash = req.app.get('git-hash')
|
|
|
|
|
|
|
|
return res.render('nojs', options)
|
2018-04-12 14:37:42 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
routes.post('/nojs', (req, res, next) => {
|
2018-05-11 14:34:13 +00:00
|
|
|
// TODO: Support upload by URLs.
|
2018-04-13 16:20:57 +00:00
|
|
|
res._json = res.json
|
|
|
|
res.json = (...args) => {
|
|
|
|
const result = args[0]
|
|
|
|
|
2018-04-25 13:16:34 +00:00
|
|
|
const options = { renderOptions }
|
2018-09-20 11:41:17 +00:00
|
|
|
options.gitHash = req.app.get('git-hash')
|
2018-04-13 16:20:57 +00:00
|
|
|
|
2018-04-25 13:16:34 +00:00
|
|
|
options.errorMessage = result.success ? '' : (result.description || 'An unexpected error occurred.')
|
|
|
|
options.files = result.files || [{}]
|
2018-04-13 16:20:57 +00:00
|
|
|
|
2018-04-25 13:16:34 +00:00
|
|
|
return res.render('nojs', options)
|
2018-04-13 16:20:57 +00:00
|
|
|
}
|
|
|
|
|
2018-04-12 14:37:42 +00:00
|
|
|
return uploadController.upload(req, res, next)
|
|
|
|
})
|
|
|
|
|
|
|
|
module.exports = routes
|