try to deploy

Signed-off-by: Kenneth Obsequio <k80308392@gmail.com>
This commit is contained in:
2026-07-13 21:27:37 +08:00
parent f5254f7571
commit c8dc2628a6
9 changed files with 120 additions and 46 deletions
+50
View File
@@ -0,0 +1,50 @@
/***********************************************************************************************************************************************************************
* File Name: asset_upload.middleware.js
* Type of Program: Middleware
* Description: Multer config for admin asset uploads (image/video/audio/document).
* Uses memory storage — buffer is passed directly to S3.
*
* Previously this route had no `limits.fileSize` at all, so an
* oversized upload wasn't rejected cleanly — it either exhausted
* server memory buffering the whole file or blew up with a raw
* multer/Node error that never reached R.error's JSON envelope.
* The frontend's fallback then had nothing to read a `message`
* out of, so every failure surfaced as the same generic
* "Something went wrong" regardless of cause.
*
* Limits:
* fileSize: 500 MB (matches task_upload.middleware.js)
*
* Author: Kenneth Obsequio (@lash0000)
* Date Created: Jul. 13, 2026
***********************************************************************************************************************************************************************/
const multer = require('multer');
const R = require('../utils/response.util');
const MAX_FILE_SIZE = 500 * 1024 * 1024; // 500 MB
const upload = multer({
storage: multer.memoryStorage(),
limits: { fileSize: MAX_FILE_SIZE },
});
// Wraps any multer middleware (fields/array/single) so oversized or malformed
// uploads always come back as a clean R.error JSON response the frontend can
// read a `message` out of, instead of an unhandled exception or Express's
// default HTML error page.
function handleUpload(multerMiddleware) {
return (req, res, next) => {
multerMiddleware(req, res, (err) => {
if (!err) return next();
if (err.code === 'LIMIT_FILE_SIZE') {
return R.error(res, `File exceeds the ${MAX_FILE_SIZE / (1024 * 1024)} MB size limit.`, 400);
}
console.error('[MULTER ERROR][ASSETS]', err);
return R.error(res, err.message ?? 'File upload failed.', 400);
});
};
}
module.exports = { upload, handleUpload, MAX_FILE_SIZE };