multermate 2.2.1 → 2.3.0

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "multermate",
3
- "version": "2.2.1",
3
+ "version": "2.3.0",
4
4
  "description": "A powerful and flexible file upload utility built on top of Multer with TypeScript support, comprehensive file type handling, custom error classes, and universal JavaScript module compatibility",
5
5
  "main": "index.js",
6
6
  "module": "index.mjs",
package/readme.md CHANGED
@@ -68,7 +68,7 @@ import {
68
68
  // With type definitions
69
69
  const options: UploadSingleOptions = {
70
70
  destination: "uploads/images",
71
- fileTypes: ["images"],
71
+ fileKinds: ["image"],
72
72
  fileSizeLimit: 5 * 1024 * 1024,
73
73
  };
74
74
  ```
@@ -114,11 +114,11 @@ app.post("/upload", uploadSingle(), (req, res) => {
114
114
  app.post(
115
115
  "/upload/advanced",
116
116
  uploadSingle({
117
- destination: "uploads/images",
118
- // Files are physically saved here, but req.file.path stays clean for DB
119
- absoluteDestination: "C:/data/my-app/uploads/images",
117
+ destination: "public/uploads/test",
118
+ // Physical location becomes: C:/Dev/Projects/public/uploads/test
119
+ absoluteDestination: "C:/Dev/Projects",
120
120
  filename: "profile",
121
- fileTypes: ["images"],
121
+ fileKinds: ["image"],
122
122
  fileSizeLimit: 5 * 1024 * 1024, // 5MB
123
123
  preservePath: false,
124
124
  }),
@@ -191,6 +191,27 @@ app.post(
191
191
  );
192
192
  ```
193
193
 
194
+ ### Easy File Kind Selection
195
+
196
+ Use `fileKinds` when you want simple category names instead of a long MIME list:
197
+
198
+ ```javascript
199
+ app.post(
200
+ "/upload/easy",
201
+ uploadSingle({
202
+ destination: "uploads/easy",
203
+ fileKinds: ["image"], // image | document | video | audio | mix | any
204
+ }),
205
+ (req, res) => {
206
+ res.json({ file: req.file });
207
+ }
208
+ );
209
+ ```
210
+
211
+ `mix` includes: images, videos, audio, documents, text, and archives.
212
+
213
+ `any` disables filtering (accepts all file types).
214
+
194
215
  ### Custom MIME Types
195
216
 
196
217
  ```javascript
@@ -302,12 +323,13 @@ Configures single file upload with the following options:
302
323
  | ------------------- | -------- | --------- | ------------------------------------------------------------------------------------------------ |
303
324
  | destination | string | 'uploads' | Upload directory path |
304
325
  | filename | string | 'file' | Form field name |
326
+ | fileKinds | string[] | [] | Easy categories like `image`, `document`, `video`, `mix`, `any` |
305
327
  | fileTypes | string[] | [] | Allowed file type categories (empty = all) |
306
328
  | customMimeTypes | string[] | [] | Custom MIME types |
307
329
  | fileSizeLimit | number | 50MB | Max file size in bytes |
308
330
  | preservePath | boolean | false | Preserve original path |
309
331
 
310
- `absoluteDestination` (optional): Physical absolute directory for file storage. When provided, MulterMate keeps `req.file.path` relative so it is safer to store in DB.
332
+ `absoluteDestination` (optional): Base absolute directory for physical storage. The final storage path is `absoluteDestination + destination`. MulterMate keeps `req.file.path` relative so it is safer to store in DB.
311
333
 
312
334
  ### uploadMultiple(options)
313
335
 
@@ -332,13 +354,13 @@ app.post(
332
354
  "/upload/absolute",
333
355
  uploadSingle({
334
356
  destination: "uploads/images", // This is what goes to req.file.path
335
- absoluteDestination: "D:/cdn-storage/project/images", // Physical storage directory
336
- fileTypes: ["images"],
357
+ absoluteDestination: "D:/cdn-storage/project", // Base physical storage directory
358
+ fileKinds: ["image"],
337
359
  }),
338
360
  (req, res) => {
339
361
  // Example:
340
362
  // req.file.path => "uploads/images/<generated-file-name>.jpg"
341
- // Physical file => "D:/cdn-storage/project/images/<generated-file-name>.jpg"
363
+ // Physical file => "D:/cdn-storage/project/uploads/images/<generated-file-name>.jpg"
342
364
  res.json({ file: req.file });
343
365
  }
344
366
  );
@@ -350,6 +372,7 @@ app.post(
350
372
  | ------------- | -------- | ------- | ---------------------------------------- |
351
373
  | name | string | - | Field name (required) |
352
374
  | maxCount | number | 10 | Max files per field |
375
+ | fileKinds | string[] | [] | Easy categories like `image`, `document`, `video`, `mix`, `any` |
353
376
  | fileTypes | string[] | [] | Allowed types (empty = accept all types) |
354
377
  | fileSizeLimit | number | 50MB | Max file size |
355
378
 
package/types/index.d.ts CHANGED
@@ -1,14 +1,28 @@
1
- import { NextFunction, Request, Response } from 'express';
1
+ import { NextFunction, Request, Response } from "express";
2
2
  export declare class MultermateError extends Error {
3
3
  code?: string;
4
4
  field?: string;
5
5
  storageErrors?: string[];
6
6
  constructor(message: string, code?: string, field?: string);
7
7
  }
8
+ export type UploadFileKind = "image" | "video" | "audio" | "document" | "text" | "archive" | "code" | "spreadsheet" | "presentation" | "font" | "cad" | "model" | "mix" | "any";
8
9
  export interface UploadSingleOptions {
9
10
  destination?: string;
10
11
  absoluteDestination?: string;
11
12
  filename?: string;
13
+ /**
14
+ * Easy file category selector.
15
+ *
16
+ * Example: ['image'], ['document'], ['video'], or ['mix'] for common mixed uploads.
17
+ *
18
+ * If `customMimeTypes` is provided, this option is ignored.
19
+ */
20
+ fileKinds?: UploadFileKind[];
21
+ /**
22
+ * Backward-compatible category selector.
23
+ *
24
+ * Also accepts singular aliases like `image`, `document`, `video` and `mix`.
25
+ */
12
26
  fileTypes?: string[];
13
27
  customMimeTypes?: string[];
14
28
  fileSizeLimit?: number;
@@ -17,6 +31,13 @@ export interface UploadSingleOptions {
17
31
  export interface FieldConfig {
18
32
  name: string;
19
33
  maxCount?: number;
34
+ /**
35
+ * Easy per-field file category selector.
36
+ */
37
+ fileKinds?: UploadFileKind[];
38
+ /**
39
+ * Backward-compatible per-field category selector.
40
+ */
20
41
  fileTypes?: string[];
21
42
  fileSizeLimit?: number;
22
43
  }