@vulkano/core 1.23.0 → 1.23.1

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.
package/README.md CHANGED
@@ -359,6 +359,8 @@ module.exports = {
359
359
 
360
360
  const props = {
361
361
  allowed: ['jpg', 'jpeg', 'png', 'webp'],
362
+ // For custom mimetypes or mime-to-extension mapping
363
+ // mimeTypes: ['image/jpeg', 'image/png', 'image/webp'],
362
364
  maxSize: 10 * 1024 * 1024,
363
365
  lang: req.query.lang // 'en' (default) or 'es' — controls the error language
364
366
  };
package/libs/Upload.js CHANGED
@@ -20,7 +20,7 @@ function sanitizeSvg(content) {
20
20
 
21
21
  }
22
22
 
23
- const IMAGE_MIME_TYPES = ['image/jpeg', 'image/jpg', 'image/pjpeg', 'image/gif', 'image/png', 'image/webp', 'image/svg+xml'];
23
+ const IMAGE_MIME_TYPES = ['image/jpeg', 'image/jpg', 'image/pjpeg', 'image/gif', 'image/png', 'image/webp', 'image/svg+xml', 'image/heic', 'image/heif'];
24
24
  const DOCUMENT_MIME_TYPES = ['application/pdf', 'application/x-pdf', 'application/msword', 'application/vnd.openxmlformats-officedocument.wordprocessingml.document', 'application/vnd.ms-excel', 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', 'application/vnd.ms-powerpoint', 'application/vnd.openxmlformats-officedocument.presentationml.presentation', 'text/csv', 'application/vnd.ms-excel.sheet.binary.macroenabled.12'];
25
25
  const ARCHIVE_MIME_TYPES = ['application/zip', 'application/x-rar', 'application/gzip', 'text/plain', 'application/x-zip-compressed'];
26
26
  const VIDEO_MIME_TYPES = ['video/quicktime', 'video/ogg', 'video/webm', 'video/mp4', 'video/x-mp4', 'video/3gp', 'video/x-3gp', 'video/mov', 'video/x-mov', 'video/m4v', 'video/x-m4v', 'video/avi', 'video/x-avi', 'video/mpg', 'video/x-mpg'];
@@ -36,6 +36,8 @@ const MIME_EXTENSION_MAP = {
36
36
  'image/png': 'png',
37
37
  'image/webp': 'webp',
38
38
  'image/svg+xml': 'svg',
39
+ 'image/heic': 'heic',
40
+ 'image/heif': 'heif',
39
41
  'application/pdf': 'pdf',
40
42
  'application/x-pdf': 'pdf',
41
43
  'application/msword': 'doc',
@@ -84,6 +86,8 @@ module.exports = {
84
86
 
85
87
  const {
86
88
  allowed,
89
+ mimeTypes,
90
+ extensionMap,
87
91
  maxSize,
88
92
  lang
89
93
  } = props;
@@ -99,11 +103,11 @@ module.exports = {
99
103
  throw new VSError(t('upload.noPermission'), 500);
100
104
  }
101
105
 
102
- if (!Upload.isValidMimeType(file)) {
106
+ if (!Upload.isValidMimeType(file, mimeTypes)) {
103
107
  throw new VSError(t('upload.invalidMimeType', { mimetype: file.mimetype }), 400);
104
108
  }
105
109
 
106
- const ext = Upload.getExtension(file);
110
+ const ext = Upload.getExtension(file, extensionMap);
107
111
 
108
112
  if (allowed && Array.isArray(allowed) && !allowed.includes(ext)) {
109
113
  throw new VSError(t('upload.extensionNotAllowed', { ext }), 400);
@@ -245,15 +249,22 @@ module.exports = {
245
249
  /**
246
250
  * Get the lowercased file extension, falling back to mimetype lookup.
247
251
  *
252
+ * `extensionMap` (from `props.extensionMap`) lets a caller extend the
253
+ * built-in mimetype→extension fallback with types the core doesn't know
254
+ * about yet - needed for a nameless upload (e.g. a blob) whose extension
255
+ * can only be derived from its mimetype, such as
256
+ * `extensionMap: { 'image/heic': 'heic' }`.
257
+ *
248
258
  * @param {Object} file
259
+ * @param {Object} [extensionMap] - extra mimetype→extension entries, checked before the built-in map
249
260
  * @returns {string}
250
261
  */
251
- getExtension(file) {
262
+ getExtension(file, extensionMap) {
252
263
 
253
264
  let ext = (file.originalname || '').split('.').pop();
254
265
 
255
266
  if (!ext || ext === 'blob' || ext === file.originalname) {
256
- ext = MIME_EXTENSION_MAP[file.mimetype] || '';
267
+ ext = (extensionMap && extensionMap[file.mimetype]) || MIME_EXTENSION_MAP[file.mimetype] || '';
257
268
  }
258
269
 
259
270
  return ext.toLowerCase();
@@ -263,12 +274,18 @@ module.exports = {
263
274
  /**
264
275
  * Check if the file's mimetype is in the allowed list.
265
276
  *
277
+ * `mimeTypes` (from `props.mimeTypes`) lets a caller extend the built-in
278
+ * whitelist with mimetypes the core doesn't know about yet, without
279
+ * having to fork this file - e.g. `mimeTypes: ['image/heic']`.
280
+ *
266
281
  * @param {Object} file
282
+ * @param {Array} [mimeTypes] - extra mimetypes to accept, in addition to VALID_MIME_TYPES
267
283
  * @returns {boolean}
268
284
  */
269
- isValidMimeType(file) {
285
+ isValidMimeType(file, mimeTypes) {
270
286
 
271
- return VALID_MIME_TYPES.includes(file.mimetype);
287
+ const extra = Array.isArray(mimeTypes) ? mimeTypes : [];
288
+ return VALID_MIME_TYPES.includes(file.mimetype) || extra.includes(file.mimetype);
272
289
 
273
290
  },
274
291
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vulkano/core",
3
- "version": "1.23.0",
3
+ "version": "1.23.1",
4
4
  "description": "A MVC framework using Express 4",
5
5
  "license": "MIT",
6
6
  "author": "Vulkano Team",