|
|
|
|
@ -197,17 +197,23 @@ function route(method, path, middleware, routeHandler, resultHandler, transactio
|
|
|
|
|
const MAX_ALLOWED_FILE_SIZE_MB = 250;
|
|
|
|
|
|
|
|
|
|
const GET = 'get', POST = 'post', PUT = 'put', PATCH = 'patch', DELETE = 'delete';
|
|
|
|
|
const uploadMiddleware = multer({
|
|
|
|
|
|
|
|
|
|
const multerOptions = {
|
|
|
|
|
fileFilter: (req, file, cb) => {
|
|
|
|
|
// UTF-8 file names are not well decoded by multer/busboy, so we handle the conversion on our side.
|
|
|
|
|
// See https://github.com/expressjs/multer/pull/1102.
|
|
|
|
|
file.originalname = Buffer.from(file.originalname, "latin1").toString("utf-8");
|
|
|
|
|
cb(null, true);
|
|
|
|
|
},
|
|
|
|
|
limits: {
|
|
|
|
|
fileSize: MAX_ALLOWED_FILE_SIZE_MB * 1024 * 1024
|
|
|
|
|
}
|
|
|
|
|
}).single('upload');
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
if (!process.env.TRILIUM_NO_UPLOAD_LIMIT) {
|
|
|
|
|
multerOptions.limits = {
|
|
|
|
|
fileSize: MAX_ALLOWED_FILE_SIZE_MB * 1024 * 1024
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const uploadMiddleware = multer(multerOptions).single('upload');
|
|
|
|
|
|
|
|
|
|
const uploadMiddlewareWithErrorHandling = function (req, res, next) {
|
|
|
|
|
uploadMiddleware(req, res, function (err) {
|
|
|
|
|
|