multermate 1.0.4 → 1.0.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.
- package/index.js +36 -27
- package/package.json +2 -9
- package/readme.md +1 -5
package/index.js
CHANGED
|
@@ -1,17 +1,7 @@
|
|
|
1
|
-
const path =
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
const multer =
|
|
6
|
-
typeof require !== "undefined"
|
|
7
|
-
? require("multer")
|
|
8
|
-
: (await import("multer")).default;
|
|
9
|
-
const { v4: uuidv4 } =
|
|
10
|
-
typeof require !== "undefined" ? require("uuid") : await import("uuid");
|
|
11
|
-
const fs =
|
|
12
|
-
typeof require !== "undefined"
|
|
13
|
-
? require("fs/promises")
|
|
14
|
-
: await import("fs/promises");
|
|
1
|
+
const path = require("path");
|
|
2
|
+
const multer = require("multer");
|
|
3
|
+
const { v4: uuidv4 } = require("uuid");
|
|
4
|
+
const fs = require("fs/promises");
|
|
15
5
|
|
|
16
6
|
// Constants for allowed MIME types
|
|
17
7
|
const ALLOWED_MIME_TYPES = {
|
|
@@ -180,29 +170,48 @@ const deleteFile = async (filePath) => {
|
|
|
180
170
|
}
|
|
181
171
|
};
|
|
182
172
|
|
|
183
|
-
|
|
173
|
+
// Export functions to configure multer and available file types
|
|
174
|
+
module.exports = {
|
|
175
|
+
/**
|
|
176
|
+
* Function to handle a single file upload.
|
|
177
|
+
*
|
|
178
|
+
* @param {object} options - Configuration options for the single file upload.
|
|
179
|
+
* @param {string} [options.destination] - Destination folder for the uploaded file.
|
|
180
|
+
* @param {string} [options.filename] - Custom filename template for the uploaded file.
|
|
181
|
+
* @param {Array<string>} [options.fileTypes] - Array of file types to allow (e.g., ['images']).
|
|
182
|
+
* @param {Array<string>} [options.customMimeTypes] - Array of custom MIME types to allow.
|
|
183
|
+
* @param {number} [options.fileSizeLimit] - Maximum file size allowed (in bytes). Default is 50MB.
|
|
184
|
+
* @param {boolean} [options.preservePath] - Preserve the full path of the uploaded file. Default is false.
|
|
185
|
+
* @returns {function} - Multer instance configured for single file upload.
|
|
186
|
+
*/
|
|
184
187
|
uploadSingle: (options = {}) => {
|
|
185
188
|
const multerInstance = configureMulter(options);
|
|
186
189
|
return multerInstance.single(options.filename || "file");
|
|
187
190
|
},
|
|
188
191
|
|
|
192
|
+
/**
|
|
193
|
+
* Function to handle multiple file uploads across multiple fields.
|
|
194
|
+
*
|
|
195
|
+
* @param {object} options - Configuration options for multiple file uploads.
|
|
196
|
+
* @param {Array<object>} options.fields - Array of field configurations for multiple file uploads.
|
|
197
|
+
* @param {string} [options.destination] - Destination folder for the uploaded files.
|
|
198
|
+
* @param {Array<string>} [options.customMimeTypes] - Array of custom MIME types to allow.
|
|
199
|
+
* @param {number} [options.fileSizeLimit] - Maximum file size allowed (in bytes). Default is 50MB.
|
|
200
|
+
* @param {boolean} [options.preservePath] - Preserve the full path of the uploaded files. Default is false.
|
|
201
|
+
* @returns {function} - Multer instance configured for multiple file uploads.
|
|
202
|
+
*/
|
|
189
203
|
uploadMultiple: (options = {}) => {
|
|
190
204
|
const multerInstance = configureMulter(options);
|
|
191
205
|
return multerInstance.fields(options.fields || []);
|
|
192
206
|
},
|
|
193
207
|
|
|
208
|
+
/**
|
|
209
|
+
* Export the allowed file types for reference.
|
|
210
|
+
*
|
|
211
|
+
* @type {Array<string>}
|
|
212
|
+
*/
|
|
194
213
|
ALLOWED_FILE_TYPES: Object.keys(ALLOWED_MIME_TYPES),
|
|
214
|
+
|
|
215
|
+
// Add the delete file utility
|
|
195
216
|
deleteFile,
|
|
196
217
|
};
|
|
197
|
-
|
|
198
|
-
// Dual export support
|
|
199
|
-
if (typeof module !== "undefined" && module.exports) {
|
|
200
|
-
module.exports = exportObject;
|
|
201
|
-
} else {
|
|
202
|
-
Object.assign(globalThis, {
|
|
203
|
-
uploadSingle: exportObject.uploadSingle,
|
|
204
|
-
uploadMultiple: exportObject.uploadMultiple,
|
|
205
|
-
ALLOWED_FILE_TYPES: exportObject.ALLOWED_FILE_TYPES,
|
|
206
|
-
deleteFile: exportObject.deleteFile,
|
|
207
|
-
});
|
|
208
|
-
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "multermate",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.5",
|
|
4
4
|
"description": "A flexible and customizable npm package for configuring Multer",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -26,12 +26,5 @@
|
|
|
26
26
|
"bugs": {
|
|
27
27
|
"url": "https://github.com/Wasim-Zaman/multermate/issues"
|
|
28
28
|
},
|
|
29
|
-
"homepage": "https://github.com/Wasim-Zaman/multermate#readme"
|
|
30
|
-
"type": "commonjs",
|
|
31
|
-
"exports": {
|
|
32
|
-
".": {
|
|
33
|
-
"require": "./index.js",
|
|
34
|
-
"import": "./index.js"
|
|
35
|
-
}
|
|
36
|
-
}
|
|
29
|
+
"homepage": "https://github.com/Wasim-Zaman/multermate#readme"
|
|
37
30
|
}
|
package/readme.md
CHANGED
|
@@ -24,11 +24,7 @@ npm install multermate
|
|
|
24
24
|
## Basic Usage
|
|
25
25
|
|
|
26
26
|
```javascript
|
|
27
|
-
// CommonJS
|
|
28
27
|
const { uploadSingle, uploadMultiple, deleteFile } = require("multermate");
|
|
29
|
-
|
|
30
|
-
// ES Modules
|
|
31
|
-
import { uploadSingle, uploadMultiple, deleteFile } from "multermate";
|
|
32
28
|
```
|
|
33
29
|
|
|
34
30
|
## Upload Configurations
|
|
@@ -252,7 +248,7 @@ Contributions are welcome! Please feel free to submit issues and pull requests.
|
|
|
252
248
|
|
|
253
249
|
## Author
|
|
254
250
|
|
|
255
|
-
|
|
251
|
+
Your Name
|
|
256
252
|
|
|
257
253
|
## Support
|
|
258
254
|
|