mirror of
https://github.com/rgrgogu/new_starr.git
synced 2026-09-27 00:12:54 +08:00
chore: relocate backend into apps/api ahead of monorepo merge
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,50 @@
|
||||
/***********************************************************************************************************************************************************************
|
||||
* File Name: taskUpload.middleware.js
|
||||
* Type of Program: Middleware
|
||||
* Description: Multer config for task completion file uploads.
|
||||
* Uses memory storage — buffer is passed directly to S3.
|
||||
* Single file per request (matches the two-step upload flow in
|
||||
* ViewTaskDetails where each file is uploaded individually).
|
||||
*
|
||||
* Limits:
|
||||
* fileSize: 500 MB (matches FileUpload.jsx DEFAULT_MAX_BYTES)
|
||||
*
|
||||
* Author: rgrgogu
|
||||
* Date Created: Jun. 13, 2026
|
||||
***********************************************************************************************************************************************************************/
|
||||
const multer = require('multer');
|
||||
|
||||
const storage = multer.memoryStorage();
|
||||
|
||||
const upload = multer({
|
||||
storage,
|
||||
limits: {
|
||||
fileSize: 500 * 1024 * 1024, // 500 MB
|
||||
},
|
||||
});
|
||||
|
||||
// Single file per request — field name must be "file"
|
||||
const uploadTaskFile = upload.single('file');
|
||||
|
||||
// ─── Error wrapper ────────────────────────────────────────────────────────────
|
||||
// Converts multer errors to a consistent R.error-style response.
|
||||
const handleUpload = (req, res, next) => {
|
||||
uploadTaskFile(req, res, (err) => {
|
||||
if (!err) return next();
|
||||
|
||||
if (err.code === 'LIMIT_FILE_SIZE') {
|
||||
return res.status(400).json({
|
||||
status: 'error',
|
||||
message: 'File exceeds the 500 MB size limit.',
|
||||
});
|
||||
}
|
||||
|
||||
console.error('[MULTER ERROR]', err);
|
||||
return res.status(400).json({
|
||||
status: 'error',
|
||||
message: err.message ?? 'File upload failed.',
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
module.exports = { handleUpload };
|
||||
Reference in New Issue
Block a user