@travetto/web-upload 6.0.1 → 6.0.3
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 +7 -7
- package/src/util.ts +7 -4
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@travetto/web-upload",
|
|
3
|
-
"version": "6.0.
|
|
3
|
+
"version": "6.0.3",
|
|
4
4
|
"description": "Provides integration between the travetto asset and web module.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"web",
|
|
@@ -25,14 +25,14 @@
|
|
|
25
25
|
"directory": "module/web-upload"
|
|
26
26
|
},
|
|
27
27
|
"dependencies": {
|
|
28
|
-
"@fastify/busboy": "^3.
|
|
29
|
-
"@travetto/config": "^6.0.
|
|
30
|
-
"@travetto/web": "^6.0.
|
|
31
|
-
"file-type": "^
|
|
32
|
-
"mime": "^4.0
|
|
28
|
+
"@fastify/busboy": "^3.2.0",
|
|
29
|
+
"@travetto/config": "^6.0.1",
|
|
30
|
+
"@travetto/web": "^6.0.3",
|
|
31
|
+
"file-type": "^21.0.0",
|
|
32
|
+
"mime": "^4.1.0"
|
|
33
33
|
},
|
|
34
34
|
"peerDependencies": {
|
|
35
|
-
"@travetto/test": "^6.0.
|
|
35
|
+
"@travetto/test": "^6.0.2"
|
|
36
36
|
},
|
|
37
37
|
"peerDependenciesMeta": {
|
|
38
38
|
"@travetto/test": {
|
package/src/util.ts
CHANGED
|
@@ -7,7 +7,7 @@ import { Readable, Transform } from 'node:stream';
|
|
|
7
7
|
|
|
8
8
|
import busboy from '@fastify/busboy';
|
|
9
9
|
|
|
10
|
-
import { WebRequest,
|
|
10
|
+
import { WebRequest, WebCommonUtil, WebBodyUtil, WebHeaderUtil } from '@travetto/web';
|
|
11
11
|
import { AsyncQueue, AppError, castTo, Util, BinaryUtil } from '@travetto/runtime';
|
|
12
12
|
|
|
13
13
|
import { WebUploadConfig } from './config.ts';
|
|
@@ -61,7 +61,9 @@ export class WebUploadUtil {
|
|
|
61
61
|
const bodyStream = Buffer.isBuffer(request.body) ? Readable.from(request.body) : request.body;
|
|
62
62
|
request.body = undefined;
|
|
63
63
|
|
|
64
|
-
|
|
64
|
+
const contentType = WebHeaderUtil.parseHeaderSegment(request.headers.get('Content-Type'));
|
|
65
|
+
|
|
66
|
+
if (MULTIPART.has(contentType.value)) {
|
|
65
67
|
const fileMaxes = Object.values(config.uploads ?? {}).map(x => x.maxSize).filter(x => x !== undefined);
|
|
66
68
|
const largestMax = fileMaxes.length ? Math.max(...fileMaxes) : config.maxSize;
|
|
67
69
|
const itr = new AsyncQueue<UploadItem>();
|
|
@@ -85,7 +87,8 @@ export class WebUploadUtil {
|
|
|
85
87
|
|
|
86
88
|
yield* itr;
|
|
87
89
|
} else {
|
|
88
|
-
|
|
90
|
+
const filename = WebHeaderUtil.parseHeaderSegment(request.headers.get('Content-Disposition')).parameters.filename;
|
|
91
|
+
yield { stream: bodyStream, filename, field: 'file' };
|
|
89
92
|
}
|
|
90
93
|
}
|
|
91
94
|
|
|
@@ -100,7 +103,7 @@ export class WebUploadUtil {
|
|
|
100
103
|
|
|
101
104
|
const location = path.resolve(uniqueDir, filename);
|
|
102
105
|
const remove = (): Promise<void> => fs.rm(location).catch(() => { });
|
|
103
|
-
const mimeCheck = config.matcher ??=
|
|
106
|
+
const mimeCheck = config.matcher ??= WebCommonUtil.mimeTypeMatcher(config.types);
|
|
104
107
|
|
|
105
108
|
try {
|
|
106
109
|
const target = createWriteStream(location);
|