@wrcb/cb-common 1.0.460 → 1.0.462
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.
|
@@ -24,14 +24,13 @@ exports.uploadMedia = {
|
|
|
24
24
|
single: (fieldName) => upload.single(fieldName),
|
|
25
25
|
multiple: (fieldName, maxCount) => upload.array(fieldName, maxCount),
|
|
26
26
|
fields: (fields) => {
|
|
27
|
-
// apenas os campos esperados pelo multer
|
|
28
27
|
const multerFields = fields.map(({ name, maxCount }) => ({
|
|
29
28
|
name,
|
|
30
29
|
maxCount
|
|
31
30
|
}));
|
|
32
31
|
const middleware = upload.fields(multerFields);
|
|
33
32
|
return (req, res, next) => {
|
|
34
|
-
req._uploadFieldConfig = fields;
|
|
33
|
+
req._uploadFieldConfig = fields;
|
|
35
34
|
middleware(req, res, next);
|
|
36
35
|
};
|
|
37
36
|
},
|
|
@@ -53,17 +52,23 @@ exports.uploadMedia = {
|
|
|
53
52
|
}
|
|
54
53
|
if (!allFiles.length)
|
|
55
54
|
return next();
|
|
55
|
+
// ✅ Verificar se há mais de 5 imagens ou mais de 1 vídeo
|
|
56
56
|
if (req.files && !Array.isArray(req.files)) {
|
|
57
57
|
const imageFiles = req.files['images'] || [];
|
|
58
|
+
const videoFiles = req.files['videos'] || [];
|
|
58
59
|
if (imageFiles.length > 5) {
|
|
59
60
|
throw new badRequestError_1.BadRequestError('TooManyImages');
|
|
60
61
|
}
|
|
61
|
-
const videoFiles = req.files['videos'] || [];
|
|
62
62
|
if (videoFiles.length > 1) {
|
|
63
63
|
throw new badRequestError_1.BadRequestError('TooManyVideos');
|
|
64
64
|
}
|
|
65
65
|
}
|
|
66
|
-
//
|
|
66
|
+
// ✅ Verificar novamente via allFiles se alguém tentar burlar o `fieldname`
|
|
67
|
+
const videoCount = allFiles.filter(f => f.mimetype.startsWith('video/')).length;
|
|
68
|
+
if (videoCount > 1) {
|
|
69
|
+
throw new badRequestError_1.BadRequestError('TooManyVideos');
|
|
70
|
+
}
|
|
71
|
+
// Validação de tamanho por campo
|
|
67
72
|
const fieldConfig = req._uploadFieldConfig || [];
|
|
68
73
|
const getMaxSizeForField = (fieldName) => {
|
|
69
74
|
const field = fieldConfig.find(f => f.name === fieldName);
|
|
@@ -80,7 +85,6 @@ exports.uploadMedia = {
|
|
|
80
85
|
throw new badRequestError_1.BadRequestError(isImage ? 'ImageTooLarge' : 'VideoTooLarge');
|
|
81
86
|
}
|
|
82
87
|
}
|
|
83
|
-
// Enviar para serviço de armazenamento
|
|
84
88
|
const uploadPromises = allFiles.map((file) => __awaiter(void 0, void 0, void 0, function* () {
|
|
85
89
|
var _a;
|
|
86
90
|
const isVideo = file.mimetype.startsWith('video/');
|
|
@@ -98,7 +102,6 @@ exports.uploadMedia = {
|
|
|
98
102
|
}));
|
|
99
103
|
const results = yield Promise.all(uploadPromises);
|
|
100
104
|
req.uploadResults = results;
|
|
101
|
-
// Organizar por campo se necessário
|
|
102
105
|
if (req.files && !Array.isArray(req.files)) {
|
|
103
106
|
req.uploadResultsByField = {};
|
|
104
107
|
let index = 0;
|