43 lines
1.4 KiB
JavaScript
43 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 = void 0;
|
|
const multer_1 = __importDefault(require("multer"));
|
|
const path_1 = __importDefault(require("path"));
|
|
const uuid_1 = require("uuid");
|
|
const supportService_1 = require("../services/supportService");
|
|
const MAX_BYTES = 8 * 1024 * 1024;
|
|
const 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) {
|
|
const ext = path_1.default.extname(file.originalname).slice(0, 20);
|
|
cb(null, `${(0, uuid_1.v4)()}${ext}`);
|
|
},
|
|
});
|
|
exports.supportUpload = (0, multer_1.default)({
|
|
storage,
|
|
limits: { fileSize: MAX_BYTES, files: 1 },
|
|
fileFilter(_req, file, cb) {
|
|
if (ALLOWED_MIMES.has(file.mimetype)) {
|
|
cb(null, true);
|
|
}
|
|
else {
|
|
cb(new Error('File type not allowed'));
|
|
}
|
|
},
|
|
});
|
|
//# sourceMappingURL=supportUpload.js.map
|