mirror of
https://github.com/BobbyWibowo/lolisafe.git
synced 2024-12-14 16:36:21 +00:00
d7d6a29123
asserting auth and JSON body will now be done via route-specific mini middlewares (authController's requireUser or optionalUser)
35 lines
992 B
JavaScript
35 lines
992 B
JavaScript
const { Router } = require('hyper-express')
|
|
const routes = new Router()
|
|
const upload = require('./../controllers/uploadController')
|
|
const utils = require('./../controllers/utilsController')
|
|
const config = require('./../config')
|
|
|
|
routes.get('/nojs', async (req, res) => {
|
|
return res.render('nojs', {
|
|
config,
|
|
utils,
|
|
versions: utils.versionStrings
|
|
})
|
|
})
|
|
|
|
routes.post('/nojs', async (req, res) => {
|
|
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 upload.upload(req, res)
|
|
}, {
|
|
// HyperExpress defaults to 250kb
|
|
// https://github.com/kartikk221/hyper-express/blob/6.2.4/docs/Server.md#server-constructor-options
|
|
max_body_length: parseInt(config.uploads.maxSize) * 1e6
|
|
})
|
|
|
|
module.exports = routes
|