1 | 'use strict';
|
2 |
|
3 | const path = require('path');
|
4 | const processMultipart = require('./processMultipart');
|
5 | const isEligibleRequest = require('./isEligibleRequest');
|
6 | const { buildOptions, debugLog } = require('./utilities');
|
7 |
|
8 | const DEFAULT_OPTIONS = {
|
9 | debug: false,
|
10 | uploadTimeout: 60000,
|
11 | fileHandler: false,
|
12 | uriDecodeFileNames: false,
|
13 | safeFileNames: false,
|
14 | preserveExtension: false,
|
15 | abortOnLimit: false,
|
16 | responseOnLimit: 'File size limit has been reached',
|
17 | limitHandler: false,
|
18 | createParentPath: false,
|
19 | parseNested: false,
|
20 | useTempFiles: false,
|
21 | tempFileDir: path.join(process.cwd(), 'tmp')
|
22 | };
|
23 |
|
24 |
|
25 |
|
26 |
|
27 |
|
28 |
|
29 | module.exports = (options) => {
|
30 | const uploadOptions = buildOptions(DEFAULT_OPTIONS, options);
|
31 | return (req, res, next) => {
|
32 | if (!isEligibleRequest(req)) {
|
33 | debugLog(uploadOptions, 'Request is not eligible for file upload!');
|
34 | return next();
|
35 | }
|
36 | processMultipart(uploadOptions, req, res, next);
|
37 | };
|
38 | };
|