pangea-server 3.1.3 → 3.1.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -2,4 +2,3 @@ export declare const processImage: (req: Req, res: Res, next: Next) => void;
|
|
|
2
2
|
export declare const processImages: (req: Req, res: Res, next: Next) => void;
|
|
3
3
|
export declare const processVideo: (req: Req, res: Res, next: Next) => void;
|
|
4
4
|
export declare const processVideos: (req: Req, res: Res, next: Next) => void;
|
|
5
|
-
export declare const processFiles: (req: Req, res: Res, next: Next) => void;
|
|
@@ -3,43 +3,43 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.
|
|
6
|
+
exports.processVideos = exports.processVideo = exports.processImages = exports.processImage = void 0;
|
|
7
7
|
const multer_1 = __importDefault(require("multer"));
|
|
8
8
|
// helpers
|
|
9
9
|
const helpers_1 = require("../helpers");
|
|
10
|
+
const imageStorage = multer_1.default.memoryStorage();
|
|
11
|
+
const videoStorage = multer_1.default.diskStorage({});
|
|
10
12
|
const invalidInputDataError = new helpers_1.AppError({ statusCodeName: 'BAD_REQUEST', errorCode: 'INVALID_INPUT_DATA' });
|
|
11
|
-
|
|
12
|
-
exports.
|
|
13
|
-
exports.
|
|
14
|
-
exports.
|
|
15
|
-
|
|
16
|
-
exports.processFiles = getProcessFn({ method: 'array', field: 'files', types: ['image', 'video'] });
|
|
17
|
-
function getProcessFn({ method, field, types }) {
|
|
13
|
+
exports.processImage = getProcessFn({ type: 'image', method: 'single' });
|
|
14
|
+
exports.processImages = getProcessFn({ type: 'image', method: 'array' });
|
|
15
|
+
exports.processVideo = getProcessFn({ type: 'video', method: 'single' });
|
|
16
|
+
exports.processVideos = getProcessFn({ type: 'video', method: 'array' });
|
|
17
|
+
function getProcessFn({ type, method }) {
|
|
18
18
|
return (req, res, next) => {
|
|
19
|
-
const process = (0, multer_1.default)({
|
|
19
|
+
const process = (0, multer_1.default)({
|
|
20
|
+
storage: type === 'image' ? imageStorage : videoStorage,
|
|
21
|
+
fileFilter: (_req, file, next) => {
|
|
22
|
+
if (!file.mimetype.startsWith(`${type}/`)) {
|
|
23
|
+
next(invalidInputDataError);
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
next(null, true);
|
|
27
|
+
},
|
|
28
|
+
})[method]('file');
|
|
20
29
|
process(req, res, (err) => {
|
|
21
30
|
if (err) {
|
|
22
31
|
next(err);
|
|
23
32
|
return;
|
|
24
33
|
}
|
|
25
|
-
if (method === 'single' &&
|
|
26
|
-
next(
|
|
34
|
+
if (method === 'single' && req.file) {
|
|
35
|
+
next();
|
|
27
36
|
return;
|
|
28
37
|
}
|
|
29
|
-
if (method === 'array' &&
|
|
30
|
-
next(
|
|
38
|
+
if (method === 'array' && req.files) {
|
|
39
|
+
next();
|
|
31
40
|
return;
|
|
32
41
|
}
|
|
33
|
-
next();
|
|
34
|
-
});
|
|
35
|
-
};
|
|
36
|
-
}
|
|
37
|
-
function getFileFilter(fileTypes) {
|
|
38
|
-
return function fileFilter(_req, file, next) {
|
|
39
|
-
if (!fileTypes.some((type) => file.mimetype.startsWith(`${type}/`))) {
|
|
40
42
|
next(invalidInputDataError);
|
|
41
|
-
|
|
42
|
-
}
|
|
43
|
-
next(null, true);
|
|
43
|
+
});
|
|
44
44
|
};
|
|
45
45
|
}
|