refactor: some routes init

this format is now fixed with hyper-express@6.4.5
This commit is contained in:
Bobby Wibowo 2022-08-05 01:01:18 +07:00
parent aca4a02f53
commit 0e4f483506
No known key found for this signature in database
GPG Key ID: 51C3A1E1E22D26CF
2 changed files with 13 additions and 9 deletions

View File

@ -43,11 +43,14 @@ routes.post('/users/edit', [auth.requireUser, utils.assertJSON], auth.editUser)
/** ./controllers/uploadController.js */
// HyperExpress defaults to 250kb
// https://github.com/kartikk221/hyper-express/blob/6.4.4/docs/Server.md#server-constructor-options
const maxBodyLength = parseInt(config.uploads.maxSize) * 1e6
routes.post('/upload', { max_body_length: maxBodyLength }, auth.optionalUser, upload.upload)
routes.post('/upload/:albumid', { max_body_length: maxBodyLength }, auth.optionalUser, upload.upload)
const uploadRouteOptions = {
// HyperExpress defaults to 250kb
// https://github.com/kartikk221/hyper-express/blob/6.4.5/docs/Server.md#server-constructor-options
max_body_length: parseInt(config.uploads.maxSize) * 1e6,
middlewares: [auth.optionalUser]
}
routes.post('/upload', uploadRouteOptions, upload.upload)
routes.post('/upload/:albumid', uploadRouteOptions, upload.upload)
routes.post('/upload/finishchunks', [auth.optionalUser, utils.assertJSON], upload.finishChunks)
routes.get('/uploads', auth.requireUser, upload.list)

View File

@ -12,10 +12,11 @@ routes.get('/nojs', async (req, res) => {
})
})
// HyperExpress defaults to 250kb
// https://github.com/kartikk221/hyper-express/blob/6.4.4/docs/Server.md#server-constructor-options
const maxBodyLength = parseInt(config.uploads.maxSize) * 1e6
routes.post('/nojs', { max_body_length: maxBodyLength }, async (req, res) => {
routes.post('/nojs', {
// HyperExpress defaults to 250kb
// https://github.com/kartikk221/hyper-express/blob/6.4.4/docs/Server.md#server-constructor-options
max_body_length: parseInt(config.uploads.maxSize) * 1e6
}, async (req, res) => {
res._json = res.json
res.json = (...args) => {
const result = args[0]