diff --git a/routes/api.js b/routes/api.js index a1dfacf..2f670b8 100644 --- a/routes/api.js +++ b/routes/api.js @@ -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) diff --git a/routes/nojs.js b/routes/nojs.js index cea0953..31a07ef 100644 --- a/routes/nojs.js +++ b/routes/nojs.js @@ -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]