42 lines
1.4 KiB
JavaScript
42 lines
1.4 KiB
JavaScript
"use strict";
|
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
};
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
exports.supportUpload = exports.SUPPORT_ALLOWED_MIMES = void 0;
|
|
const multer_1 = __importDefault(require("multer"));
|
|
const uuid_1 = require("uuid");
|
|
const supportService_1 = require("../services/supportService");
|
|
const MAX_BYTES = 8 * 1024 * 1024;
|
|
exports.SUPPORT_ALLOWED_MIMES = new Set([
|
|
'image/jpeg',
|
|
'image/png',
|
|
'image/gif',
|
|
'image/webp',
|
|
'application/pdf',
|
|
'text/plain',
|
|
'application/msword',
|
|
'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
|
|
]);
|
|
const storage = multer_1.default.diskStorage({
|
|
destination(_req, _file, cb) {
|
|
cb(null, (0, supportService_1.ensureUploadDir)());
|
|
},
|
|
filename(_req, _file, cb) {
|
|
// Temporary name only — controller renames to uuid + extension from detected MIME.
|
|
cb(null, `${(0, uuid_1.v4)()}.upload`);
|
|
},
|
|
});
|
|
exports.supportUpload = (0, multer_1.default)({
|
|
storage,
|
|
limits: { fileSize: MAX_BYTES, files: 1 },
|
|
fileFilter(_req, file, cb) {
|
|
if (exports.SUPPORT_ALLOWED_MIMES.has(file.mimetype)) {
|
|
cb(null, true);
|
|
}
|
|
else {
|
|
cb(new Error('File type not allowed'));
|
|
}
|
|
},
|
|
});
|
|
//# sourceMappingURL=supportUpload.js.map
|