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 = {
|
|
|
|
layout: false,
|
|
|
|
uploadDisabled: false,
|
|
|
|
maxFileSize: config.uploads.maxSize
|
|
|
|
}
|
|
|
|
|
|
|
|
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-04-13 16:20:57 +00:00
|
|
|
return res.render('nojs', renderOptions)
|
2018-04-12 14:37:42 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
routes.post('/nojs', (req, res, next) => {
|
2018-04-13 16:20:57 +00:00
|
|
|
res._json = res.json
|
|
|
|
res.json = (...args) => {
|
|
|
|
const result = args[0]
|
|
|
|
|
|
|
|
const _renderOptions = {}
|
|
|
|
Object.assign(_renderOptions, renderOptions)
|
|
|
|
|
|
|
|
_renderOptions.errorMessage = result.success ? '' : (result.description || 'An unexpected error occurred.')
|
|
|
|
_renderOptions.files = result.files || [{}]
|
|
|
|
|
|
|
|
return res.render('nojs', _renderOptions)
|
|
|
|
}
|
|
|
|
|
2018-04-12 14:37:42 +00:00
|
|
|
return uploadController.upload(req, res, next)
|
|
|
|
})
|
|
|
|
|
|
|
|
module.exports = routes
|