@eggjs/multipart 5.0.0-beta.35 → 5.0.0-beta.36
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/dist/app/extend/context.d.ts +97 -93
- package/dist/app/extend/context.js +194 -271
- package/dist/app/middleware/multipart.d.ts +6 -3
- package/dist/app/middleware/multipart.js +14 -17
- package/dist/app/schedule/clean_tmpdir.d.ts +5 -2
- package/dist/app/schedule/clean_tmpdir.js +54 -51
- package/dist/app.d.ts +9 -5
- package/dist/app.js +20 -17
- package/dist/config/config.default.d.ts +87 -84
- package/dist/config/config.default.js +27 -25
- package/dist/index.d.ts +20 -16
- package/dist/index.js +24 -21
- package/dist/lib/LimitError.d.ts +7 -4
- package/dist/lib/LimitError.js +15 -12
- package/dist/lib/MultipartFileTooLargeError.d.ts +8 -5
- package/dist/lib/MultipartFileTooLargeError.js +17 -14
- package/dist/lib/utils.d.ts +8 -4
- package/dist/lib/utils.js +68 -88
- package/dist/types.d.ts +24 -22
- package/dist/types.js +1 -2
- package/package.json +25 -32
package/dist/lib/utils.js
CHANGED
|
@@ -1,91 +1,71 @@
|
|
|
1
|
-
import assert from
|
|
2
|
-
import path from
|
|
3
|
-
import bytes from
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
'.mp4',
|
|
33
|
-
'.avi',
|
|
1
|
+
import assert from "node:assert";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import bytes from "bytes";
|
|
4
|
+
|
|
5
|
+
//#region src/lib/utils.ts
|
|
6
|
+
const whitelist = [
|
|
7
|
+
".jpg",
|
|
8
|
+
".jpeg",
|
|
9
|
+
".png",
|
|
10
|
+
".gif",
|
|
11
|
+
".bmp",
|
|
12
|
+
".wbmp",
|
|
13
|
+
".webp",
|
|
14
|
+
".tif",
|
|
15
|
+
".psd",
|
|
16
|
+
".svg",
|
|
17
|
+
".js",
|
|
18
|
+
".jsx",
|
|
19
|
+
".json",
|
|
20
|
+
".css",
|
|
21
|
+
".less",
|
|
22
|
+
".html",
|
|
23
|
+
".htm",
|
|
24
|
+
".xml",
|
|
25
|
+
".zip",
|
|
26
|
+
".gz",
|
|
27
|
+
".tgz",
|
|
28
|
+
".gzip",
|
|
29
|
+
".mp3",
|
|
30
|
+
".mp4",
|
|
31
|
+
".avi"
|
|
34
32
|
];
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
}
|
|
39
|
-
return bytes(size);
|
|
33
|
+
function humanizeBytes(size) {
|
|
34
|
+
if (typeof size === "number") return size;
|
|
35
|
+
return bytes(size);
|
|
40
36
|
}
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
}
|
|
73
|
-
options.checkFile = (_fieldName, fileStream, fileName) => {
|
|
74
|
-
// just ignore, if no file
|
|
75
|
-
if (!fileStream || !fileName)
|
|
76
|
-
return;
|
|
77
|
-
try {
|
|
78
|
-
if (!checkExt(fileName)) {
|
|
79
|
-
const err = new Error('Invalid filename: ' + fileName);
|
|
80
|
-
Reflect.set(err, 'status', 400);
|
|
81
|
-
return err;
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
catch (err) {
|
|
85
|
-
err.status = 400;
|
|
86
|
-
return err;
|
|
87
|
-
}
|
|
88
|
-
};
|
|
89
|
-
return options;
|
|
37
|
+
function normalizeOptions(options) {
|
|
38
|
+
options.fileSize = humanizeBytes(options.fileSize);
|
|
39
|
+
options.fieldSize = humanizeBytes(options.fieldSize);
|
|
40
|
+
options.fieldNameSize = humanizeBytes(options.fieldNameSize);
|
|
41
|
+
options.mode = options.mode || "stream";
|
|
42
|
+
assert(["stream", "file"].includes(options.mode), `Expect mode to be 'stream' or 'file', but got '${options.mode}'`);
|
|
43
|
+
if (options.mode === "file") assert(!options.fileModeMatch, "`fileModeMatch` options only work on stream mode, please remove it");
|
|
44
|
+
if (Array.isArray(options.whitelist)) options.whitelist = options.whitelist.map((extname) => extname.toLowerCase());
|
|
45
|
+
if (Array.isArray(options.fileExtensions)) options.fileExtensions = options.fileExtensions.map((extname) => {
|
|
46
|
+
return extname.startsWith(".") || extname === "" ? extname.toLowerCase() : `.${extname.toLowerCase()}`;
|
|
47
|
+
});
|
|
48
|
+
function checkExt(fileName) {
|
|
49
|
+
if (typeof options.whitelist === "function") return options.whitelist(fileName);
|
|
50
|
+
const extname = path.extname(fileName).toLowerCase();
|
|
51
|
+
if (Array.isArray(options.whitelist)) return options.whitelist.includes(extname);
|
|
52
|
+
return whitelist.includes(extname) || options.fileExtensions.includes(extname);
|
|
53
|
+
}
|
|
54
|
+
options.checkFile = (_fieldName, fileStream, fileName) => {
|
|
55
|
+
if (!fileStream || !fileName) return;
|
|
56
|
+
try {
|
|
57
|
+
if (!checkExt(fileName)) {
|
|
58
|
+
const err = /* @__PURE__ */ new Error("Invalid filename: " + fileName);
|
|
59
|
+
Reflect.set(err, "status", 400);
|
|
60
|
+
return err;
|
|
61
|
+
}
|
|
62
|
+
} catch (err) {
|
|
63
|
+
err.status = 400;
|
|
64
|
+
return err;
|
|
65
|
+
}
|
|
66
|
+
};
|
|
67
|
+
return options;
|
|
90
68
|
}
|
|
91
|
-
|
|
69
|
+
|
|
70
|
+
//#endregion
|
|
71
|
+
export { humanizeBytes, normalizeOptions, whitelist };
|
package/dist/types.d.ts
CHANGED
|
@@ -1,22 +1,24 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
1
|
+
import { EggFile, MultipartFileStream, MultipartOptions } from "./app/extend/context.js";
|
|
2
|
+
import { MultipartConfig } from "./config/config.default.js";
|
|
3
|
+
|
|
4
|
+
//#region src/types.d.ts
|
|
5
|
+
declare module "egg" {
|
|
6
|
+
interface EggAppConfig {
|
|
7
|
+
/**
|
|
8
|
+
* multipart parser options
|
|
9
|
+
* @member Config#multipart
|
|
10
|
+
*/
|
|
11
|
+
multipart: MultipartConfig;
|
|
12
|
+
}
|
|
13
|
+
interface Request {
|
|
14
|
+
/**
|
|
15
|
+
* Files Object Array
|
|
16
|
+
*/
|
|
17
|
+
files?: EggFile[];
|
|
18
|
+
}
|
|
19
|
+
interface Context {
|
|
20
|
+
saveRequestFiles(options?: MultipartOptions): Promise<void>;
|
|
21
|
+
getFileStream(options?: MultipartOptions): Promise<MultipartFileStream>;
|
|
22
|
+
cleanupRequestFiles(files?: EggFile[]): Promise<void>;
|
|
23
|
+
}
|
|
24
|
+
}
|
package/dist/types.js
CHANGED
|
@@ -1,2 +1 @@
|
|
|
1
|
-
export {};
|
|
2
|
-
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidHlwZXMuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi9zcmMvdHlwZXMudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IiJ9
|
|
1
|
+
export { };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@eggjs/multipart",
|
|
3
|
-
"version": "5.0.0-beta.
|
|
3
|
+
"version": "5.0.0-beta.36",
|
|
4
4
|
"description": "Multipart plugin for egg",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"egg",
|
|
@@ -8,21 +8,24 @@
|
|
|
8
8
|
"eggPlugin",
|
|
9
9
|
"multipart"
|
|
10
10
|
],
|
|
11
|
-
"
|
|
12
|
-
"type": "git",
|
|
13
|
-
"url": "git+https://github.com/eggjs/egg.git",
|
|
14
|
-
"directory": "plugins/multipart"
|
|
15
|
-
},
|
|
11
|
+
"homepage": "https://github.com/eggjs/egg/tree/next/plugins/multipart#readme",
|
|
16
12
|
"bugs": {
|
|
17
13
|
"url": "https://github.com/eggjs/egg/issues"
|
|
18
14
|
},
|
|
19
|
-
"homepage": "https://github.com/eggjs/egg/tree/next/plugins/multipart#readme",
|
|
20
|
-
"author": "gxcsoccer <gxcsoccer@126.com>",
|
|
21
15
|
"license": "MIT",
|
|
22
|
-
"
|
|
23
|
-
|
|
16
|
+
"author": "gxcsoccer <gxcsoccer@126.com>",
|
|
17
|
+
"repository": {
|
|
18
|
+
"type": "git",
|
|
19
|
+
"url": "git+https://github.com/eggjs/egg.git",
|
|
20
|
+
"directory": "plugins/multipart"
|
|
24
21
|
},
|
|
22
|
+
"files": [
|
|
23
|
+
"dist"
|
|
24
|
+
],
|
|
25
25
|
"type": "module",
|
|
26
|
+
"main": "./dist/index.js",
|
|
27
|
+
"module": "./dist/index.js",
|
|
28
|
+
"types": "./dist/index.d.ts",
|
|
26
29
|
"exports": {
|
|
27
30
|
".": "./dist/index.js",
|
|
28
31
|
"./app": "./dist/app.js",
|
|
@@ -43,37 +46,27 @@
|
|
|
43
46
|
"bytes": "^3.1.2",
|
|
44
47
|
"co-busboy": "^2.0.1",
|
|
45
48
|
"dayjs": "^1.11.13",
|
|
46
|
-
"@eggjs/path-matching": "3.0.0-beta.
|
|
47
|
-
},
|
|
48
|
-
"peerDependencies": {
|
|
49
|
-
"egg": "4.1.0-beta.35"
|
|
49
|
+
"@eggjs/path-matching": "3.0.0-beta.36"
|
|
50
50
|
},
|
|
51
51
|
"devDependencies": {
|
|
52
52
|
"@types/bytes": "^3.1.5",
|
|
53
|
-
"@types/node": "^24.10.
|
|
53
|
+
"@types/node": "^24.10.2",
|
|
54
54
|
"formstream": "^1.5.1",
|
|
55
55
|
"is-type-of": "^2.2.0",
|
|
56
56
|
"stream-wormhole": "^2.0.1",
|
|
57
|
-
"tsdown": "^0.17.0",
|
|
58
57
|
"typescript": "^5.9.3",
|
|
59
58
|
"urllib": "^4.8.2",
|
|
60
|
-
"
|
|
61
|
-
"@eggjs/mock": "7.0.0-beta.
|
|
62
|
-
"
|
|
63
|
-
|
|
64
|
-
|
|
59
|
+
"@eggjs/schedule": "6.0.0-beta.36",
|
|
60
|
+
"@eggjs/mock": "7.0.0-beta.36",
|
|
61
|
+
"egg": "4.1.0-beta.36"
|
|
62
|
+
},
|
|
63
|
+
"peerDependencies": {
|
|
64
|
+
"egg": "4.1.0-beta.36"
|
|
65
|
+
},
|
|
66
|
+
"engines": {
|
|
67
|
+
"node": ">= 22.18.0"
|
|
65
68
|
},
|
|
66
|
-
"files": [
|
|
67
|
-
"dist"
|
|
68
|
-
],
|
|
69
|
-
"main": "./dist/index.js",
|
|
70
|
-
"module": "./dist/index.js",
|
|
71
|
-
"types": "./dist/index.d.ts",
|
|
72
69
|
"scripts": {
|
|
73
|
-
"
|
|
74
|
-
"typecheck": "tsc --noEmit",
|
|
75
|
-
"lint": "oxlint --type-aware",
|
|
76
|
-
"lint:fix": "npm run lint -- --fix",
|
|
77
|
-
"test": "npm run lint:fix && vitest"
|
|
70
|
+
"typecheck": "tsgo --noEmit"
|
|
78
71
|
}
|
|
79
72
|
}
|