module-develop-kit 1.2.1 → 1.2.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/dist/commonjs-virtual-dir/browser.js +2 -5
- package/dist/commonjs-virtual-dir/browser2.js +5 -2
- package/dist/main.d.ts +15 -3
- package/dist/main.js +33 -31
- package/dist/src/shield/file-detection.js +62 -56
- package/dist/src/shield/url-sanitize.js +21 -21
- package/dist/vendor/@tokenizer/inflate/lib/ZipHandler.js +1 -1
- package/dist/vendor/debug/src/browser.js +1 -1
- package/package.json +1 -1
package/dist/main.d.ts
CHANGED
|
@@ -2,6 +2,12 @@ import { Ref } from 'vue';
|
|
|
2
2
|
import { supportedExtensions } from 'file-type';
|
|
3
3
|
import { supportedMimeTypes } from 'file-type';
|
|
4
4
|
|
|
5
|
+
/**
|
|
6
|
+
* 支持的文件 MIME 类型配置
|
|
7
|
+
* 从 file-type 库导出,可用于UI展示或额外验证
|
|
8
|
+
*/
|
|
9
|
+
export declare const ALLOWED_FILE_MIMES: string[];
|
|
10
|
+
|
|
5
11
|
/**
|
|
6
12
|
* 支持的文件类型配置
|
|
7
13
|
* 基于 file-type 库的 supportedMimeTypes 动态生成
|
|
@@ -51,9 +57,8 @@ export declare function detectFileByExtension(file: File, _allowedExtensions: TM
|
|
|
51
57
|
|
|
52
58
|
/**
|
|
53
59
|
* 检测文件真实类型并验证 MIME 类型
|
|
54
|
-
*
|
|
55
60
|
* @param file 要检测的文件
|
|
56
|
-
* @param _allowedMimes 允许的MIME类型列表
|
|
61
|
+
* @param _allowedMimes 允许的MIME类型列表 支持单个或者数组。单个支持使用,分割,支持通配符
|
|
57
62
|
* @param options 检测选项
|
|
58
63
|
* @returns 检测结果
|
|
59
64
|
*/
|
|
@@ -334,8 +339,15 @@ export declare function isUrlSafe(url: unknown, options?: IUrlSanitizeOptions):
|
|
|
334
339
|
*/
|
|
335
340
|
export declare function isValidDocument(file: File, maxSize?: number): Promise<IFileDetectionResult>;
|
|
336
341
|
|
|
342
|
+
/**
|
|
343
|
+
* 便捷方法: 检测是否为常规支持的文件类型(基于 MIME 类型)
|
|
344
|
+
*/
|
|
345
|
+
export declare function isValidFile(file: File, maxSize?: number): Promise<IFileDetectionResult>;
|
|
346
|
+
|
|
337
347
|
/**
|
|
338
348
|
* 便捷方法: 检测是否为图片文件(基于 MIME 类型)
|
|
349
|
+
* @file 要检测的文件
|
|
350
|
+
* @maxSize 文件最大尺寸
|
|
339
351
|
*/
|
|
340
352
|
export declare function isValidImage(file: File, maxSize?: number): Promise<IFileDetectionResult>;
|
|
341
353
|
|
|
@@ -365,7 +377,7 @@ export declare interface IUrlSanitizeOptions {
|
|
|
365
377
|
*/
|
|
366
378
|
fallbackUrl?: string;
|
|
367
379
|
/**
|
|
368
|
-
* 是否严格模式,严格模式下只允许 http/https,默认
|
|
380
|
+
* 是否严格模式,严格模式下只允许 http/https,默认 true
|
|
369
381
|
*/
|
|
370
382
|
strictMode?: boolean;
|
|
371
383
|
}
|
package/dist/main.js
CHANGED
|
@@ -1,37 +1,39 @@
|
|
|
1
1
|
import { useCall as o } from "./src/outside-call/index.js";
|
|
2
|
-
import { antiReplyAttackStrategy as i, requestDataEncryption as s, responseDataEncryption as
|
|
3
|
-
import { ALLOWED_FILE_TYPES as
|
|
4
|
-
import { htmlSanitize as
|
|
5
|
-
import { startNoDebugger as
|
|
6
|
-
import { isUrlSafe as
|
|
7
|
-
import { EventBus as
|
|
8
|
-
import { CallLogger as
|
|
9
|
-
import { ECallStatus as
|
|
10
|
-
import { supportedExtensions as
|
|
2
|
+
import { antiReplyAttackStrategy as i, requestDataEncryption as s, responseDataEncryption as E } from "./src/shield/crypto/index.js";
|
|
3
|
+
import { ALLOWED_FILE_MIMES as l, ALLOWED_FILE_TYPES as n, detectFileByExtension as p, detectFileByMime as m, detectionFilesByExtension as x, detectionFilesByMime as S, isValidDocument as d, isValidFile as f, isValidImage as _, isValidVideo as y } from "./src/shield/file-detection.js";
|
|
4
|
+
import { htmlSanitize as u } from "./src/shield/html-sanitize.js";
|
|
5
|
+
import { startNoDebugger as D } from "./src/shield/no-debugger.js";
|
|
6
|
+
import { isUrlSafe as I, sanitizeUrl as L, sanitizeUrls as g } from "./src/shield/url-sanitize.js";
|
|
7
|
+
import { EventBus as V } from "./src/utils/eventBus.js";
|
|
8
|
+
import { CallLogger as C } from "./src/outside-call/utils.js";
|
|
9
|
+
import { ECallStatus as R, EMIT_EVENT_NAME as T, SIP_CODE_MESSAGE as U, SIP_ERROR_CAUSES as z } from "./src/outside-call/constants.js";
|
|
10
|
+
import { supportedExtensions as P, supportedMimeTypes as W } from "./vendor/file-type/source/index.js";
|
|
11
11
|
export {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
R as
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
U as
|
|
12
|
+
l as ALLOWED_FILE_MIMES,
|
|
13
|
+
n as ALLOWED_FILE_TYPES,
|
|
14
|
+
C as CallLogger,
|
|
15
|
+
R as ECallStatus,
|
|
16
|
+
T as EMIT_EVENT_NAME,
|
|
17
|
+
V as EventBus,
|
|
18
|
+
U as SIP_CODE_MESSAGE,
|
|
19
|
+
z as SIP_ERROR_CAUSES,
|
|
19
20
|
i as antiReplyAttackStrategy,
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
21
|
+
p as detectFileByExtension,
|
|
22
|
+
m as detectFileByMime,
|
|
23
|
+
x as detectionFilesByExtension,
|
|
24
|
+
S as detectionFilesByMime,
|
|
25
|
+
u as htmlSanitize,
|
|
26
|
+
I as isUrlSafe,
|
|
27
|
+
d as isValidDocument,
|
|
28
|
+
f as isValidFile,
|
|
29
|
+
_ as isValidImage,
|
|
30
|
+
y as isValidVideo,
|
|
29
31
|
s as requestDataEncryption,
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
32
|
+
E as responseDataEncryption,
|
|
33
|
+
L as sanitizeUrl,
|
|
34
|
+
g as sanitizeUrls,
|
|
35
|
+
D as startNoDebugger,
|
|
36
|
+
P as supportedExtensions,
|
|
37
|
+
W as supportedMimeTypes,
|
|
36
38
|
o as useCall
|
|
37
39
|
};
|
|
@@ -1,19 +1,20 @@
|
|
|
1
|
-
import { supportedMimeTypes as
|
|
2
|
-
import { supportedExtensions as
|
|
1
|
+
import { supportedMimeTypes as f, fileTypeFromStream as y } from "../../vendor/file-type/source/index.js";
|
|
2
|
+
import { supportedExtensions as L } from "../../vendor/file-type/source/index.js";
|
|
3
3
|
function d(e) {
|
|
4
4
|
const t = /* @__PURE__ */ new Set();
|
|
5
|
-
for (const
|
|
6
|
-
|
|
5
|
+
for (const i of f)
|
|
6
|
+
i.startsWith(`${e}/`) && t.add(i);
|
|
7
7
|
return t;
|
|
8
8
|
}
|
|
9
|
-
const
|
|
9
|
+
const l = {
|
|
10
10
|
// 图片类型 - 从 supportedMimeTypes 中过滤 image/*
|
|
11
11
|
image: d("image"),
|
|
12
12
|
// 文档类型 - 包含常见办公文档
|
|
13
13
|
document: /* @__PURE__ */ new Set([
|
|
14
|
-
...Array.from(
|
|
15
|
-
|
|
16
|
-
|
|
14
|
+
...Array.from(f).filter((e) => {
|
|
15
|
+
const t = e.includes("pdf") || e.includes("msword") || e.includes("officedocument") || e.includes("ms-excel") || e.includes("ms-powerpoint") || e.includes("opendocument") || e === "text/plain", i = e.includes("macroenabled");
|
|
16
|
+
return t && !i;
|
|
17
|
+
})
|
|
17
18
|
]),
|
|
18
19
|
// 视频类型 - 从 supportedMimeTypes 中过滤 video/*
|
|
19
20
|
video: d("video"),
|
|
@@ -21,7 +22,7 @@ const f = {
|
|
|
21
22
|
audio: d("audio"),
|
|
22
23
|
// 压缩文件
|
|
23
24
|
archive: /* @__PURE__ */ new Set([
|
|
24
|
-
...Array.from(
|
|
25
|
+
...Array.from(f).filter(
|
|
25
26
|
(e) => e.includes("zip") || e.includes("rar") || e.includes("7z") || e.includes("tar") || e.includes("gzip") || e.includes("compress")
|
|
26
27
|
)
|
|
27
28
|
]),
|
|
@@ -29,37 +30,37 @@ const f = {
|
|
|
29
30
|
font: d("font"),
|
|
30
31
|
// 模型文件
|
|
31
32
|
model: d("model")
|
|
32
|
-
};
|
|
33
|
-
function
|
|
34
|
-
return t.some((
|
|
35
|
-
const
|
|
36
|
-
if (!
|
|
33
|
+
}, M = Object.values(l).reduce((e, t) => (e.push(...Array.from(t)), e), []);
|
|
34
|
+
function v(e, t) {
|
|
35
|
+
return t.some((i) => {
|
|
36
|
+
const r = i.trim();
|
|
37
|
+
if (!r)
|
|
37
38
|
return !1;
|
|
38
|
-
if (
|
|
39
|
+
if (r === e)
|
|
39
40
|
return !0;
|
|
40
|
-
if (
|
|
41
|
-
const n =
|
|
41
|
+
if (r.endsWith("/*")) {
|
|
42
|
+
const n = r.slice(0, r.indexOf("/"));
|
|
42
43
|
return e.startsWith(`${n}/`);
|
|
43
44
|
}
|
|
44
45
|
return !1;
|
|
45
46
|
});
|
|
46
47
|
}
|
|
47
48
|
async function p(e, t) {
|
|
48
|
-
const { maxSize:
|
|
49
|
-
if (
|
|
49
|
+
const { maxSize: i } = t;
|
|
50
|
+
if (i && e.size > i)
|
|
50
51
|
return {
|
|
51
52
|
valid: !1,
|
|
52
|
-
error: `上传文件大小不能超过 ${(
|
|
53
|
+
error: `上传文件大小不能超过 ${(i / 1024 / 1024).toFixed(2)}MB`,
|
|
53
54
|
claimedMime: e.type
|
|
54
55
|
};
|
|
55
|
-
const
|
|
56
|
-
if (!
|
|
56
|
+
const r = await y(e.stream());
|
|
57
|
+
if (!r)
|
|
57
58
|
return {
|
|
58
59
|
valid: !1,
|
|
59
60
|
error: "无法检测文件类型,可能是不支持的格式或文件已损坏",
|
|
60
61
|
claimedMime: e.type
|
|
61
62
|
};
|
|
62
|
-
const n =
|
|
63
|
+
const n = r.mime, o = r.ext, c = e.type, s = n === c;
|
|
63
64
|
return !s && c && console.warn("文件MIME类型不匹配", {
|
|
64
65
|
claimed: c,
|
|
65
66
|
detected: n,
|
|
@@ -71,12 +72,12 @@ async function p(e, t) {
|
|
|
71
72
|
mimeMatches: s
|
|
72
73
|
};
|
|
73
74
|
}
|
|
74
|
-
async function
|
|
75
|
-
const
|
|
76
|
-
if ("valid" in
|
|
77
|
-
return
|
|
78
|
-
const { detectedMime: n, detectedExt: o, claimedMime: c, mimeMatches: s } =
|
|
79
|
-
return !n || !
|
|
75
|
+
async function a(e, t, i = {}) {
|
|
76
|
+
const r = await p(e, i);
|
|
77
|
+
if ("valid" in r && !r.valid)
|
|
78
|
+
return r;
|
|
79
|
+
const { detectedMime: n, detectedExt: o, claimedMime: c, mimeMatches: s } = r, m = Array.isArray(t) ? t : t.split(",");
|
|
80
|
+
return !n || !v(n, m) ? {
|
|
80
81
|
valid: !1,
|
|
81
82
|
error: `不支持的文件类型: ${n || "未知"}`,
|
|
82
83
|
detectedMime: n,
|
|
@@ -91,12 +92,12 @@ async function u(e, t, r = {}) {
|
|
|
91
92
|
mimeMatches: s
|
|
92
93
|
};
|
|
93
94
|
}
|
|
94
|
-
async function
|
|
95
|
-
const
|
|
96
|
-
if ("valid" in
|
|
97
|
-
return
|
|
98
|
-
const { detectedMime: n, detectedExt: o, claimedMime: c, mimeMatches: s } =
|
|
99
|
-
return !o || !m.some((
|
|
95
|
+
async function A(e, t, i = {}) {
|
|
96
|
+
const r = await p(e, i);
|
|
97
|
+
if ("valid" in r && !r.valid)
|
|
98
|
+
return r;
|
|
99
|
+
const { detectedMime: n, detectedExt: o, claimedMime: c, mimeMatches: s } = r, m = Array.isArray(t) ? t : t.split(",").map((u) => u.trim());
|
|
100
|
+
return !o || !m.some((u) => o === u || `.${o}` === u) ? {
|
|
100
101
|
valid: !1,
|
|
101
102
|
error: `不支持的文件扩展名: .${o || "未知"}`,
|
|
102
103
|
detectedMime: n,
|
|
@@ -111,33 +112,38 @@ async function v(e, t, r = {}) {
|
|
|
111
112
|
mimeMatches: s
|
|
112
113
|
};
|
|
113
114
|
}
|
|
114
|
-
function
|
|
115
|
-
return Promise.all(e.map((
|
|
115
|
+
function x(e, t, i = {}) {
|
|
116
|
+
return Promise.all(e.map((r) => a(r, t, i)));
|
|
116
117
|
}
|
|
117
|
-
function
|
|
118
|
-
return Promise.all(e.map((
|
|
118
|
+
function F(e, t, i = {}) {
|
|
119
|
+
return Promise.all(e.map((r) => A(r, t, i)));
|
|
119
120
|
}
|
|
120
|
-
function
|
|
121
|
-
const
|
|
122
|
-
return
|
|
121
|
+
function g(e, t) {
|
|
122
|
+
const i = Array.from(l.image);
|
|
123
|
+
return a(e, i, { maxSize: t });
|
|
123
124
|
}
|
|
124
125
|
function w(e, t) {
|
|
125
|
-
const
|
|
126
|
-
return
|
|
126
|
+
const i = Array.from(l.document);
|
|
127
|
+
return a(e, i, { maxSize: t });
|
|
128
|
+
}
|
|
129
|
+
function h(e, t) {
|
|
130
|
+
const i = Array.from(l.video);
|
|
131
|
+
return a(e, i, { maxSize: t });
|
|
127
132
|
}
|
|
128
|
-
function
|
|
129
|
-
|
|
130
|
-
return u(e, r, { maxSize: t });
|
|
133
|
+
function S(e, t) {
|
|
134
|
+
return a(e, M, { maxSize: t });
|
|
131
135
|
}
|
|
132
136
|
export {
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
137
|
+
M as ALLOWED_FILE_MIMES,
|
|
138
|
+
l as ALLOWED_FILE_TYPES,
|
|
139
|
+
A as detectFileByExtension,
|
|
140
|
+
a as detectFileByMime,
|
|
141
|
+
F as detectionFilesByExtension,
|
|
142
|
+
x as detectionFilesByMime,
|
|
138
143
|
w as isValidDocument,
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
144
|
+
S as isValidFile,
|
|
145
|
+
g as isValidImage,
|
|
146
|
+
h as isValidVideo,
|
|
147
|
+
L as supportedExtensions,
|
|
148
|
+
f as supportedMimeTypes
|
|
143
149
|
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
const i = ["http:", "https:", "mailto:", "tel:", "sms:", "ftp:", "ftps:"],
|
|
1
|
+
const i = ["http:", "https:", "mailto:", "tel:", "sms:", "ftp:", "ftps:"], n = [
|
|
2
2
|
// eslint-disable-next-line no-script-url
|
|
3
3
|
"javascript:",
|
|
4
4
|
"data:",
|
|
@@ -7,11 +7,11 @@ const i = ["http:", "https:", "mailto:", "tel:", "sms:", "ftp:", "ftps:"], o = [
|
|
|
7
7
|
"about:",
|
|
8
8
|
"blob:"
|
|
9
9
|
];
|
|
10
|
-
function
|
|
10
|
+
function c(t) {
|
|
11
11
|
return t.replace(/[-]/g, "").replace(/\s+/g, "").trim();
|
|
12
12
|
}
|
|
13
|
-
function
|
|
14
|
-
const
|
|
13
|
+
function a(t) {
|
|
14
|
+
const r = t.toLowerCase();
|
|
15
15
|
return [
|
|
16
16
|
/javascript:/i,
|
|
17
17
|
/data:text\/html/i,
|
|
@@ -25,35 +25,35 @@ function n(t) {
|
|
|
25
25
|
// URL 编码的 javascript
|
|
26
26
|
/\\u006a\\u0061\\u0076\\u0061/i
|
|
27
27
|
// Unicode 编码
|
|
28
|
-
].some((s) => s.test(
|
|
28
|
+
].some((s) => s.test(r) || s.test(t));
|
|
29
29
|
}
|
|
30
|
-
function
|
|
30
|
+
function l(t, r = {}) {
|
|
31
31
|
if (!t || typeof t != "string")
|
|
32
32
|
return !1;
|
|
33
|
-
const
|
|
34
|
-
if (!
|
|
33
|
+
const e = t.trim();
|
|
34
|
+
if (!e)
|
|
35
35
|
return !1;
|
|
36
|
-
if (
|
|
37
|
-
return
|
|
38
|
-
const s =
|
|
39
|
-
if (
|
|
36
|
+
if (e.startsWith("/") || e.startsWith("./") || e.startsWith("../"))
|
|
37
|
+
return r.allowRelative === !1 ? !1 : !a(e);
|
|
38
|
+
const s = c(e);
|
|
39
|
+
if (a(s))
|
|
40
40
|
return !1;
|
|
41
41
|
try {
|
|
42
|
-
const
|
|
43
|
-
return
|
|
42
|
+
const o = new URL(s, "http://example.com").protocol.toLowerCase();
|
|
43
|
+
return r.strictMode ?? !0 ? ["http:", "https:", ...r.extraSafeProtocols || []].includes(o) : n.includes(o) ? !1 : [...i, ...r.extraSafeProtocols || []].includes(o);
|
|
44
44
|
} catch {
|
|
45
45
|
return !1;
|
|
46
46
|
}
|
|
47
47
|
}
|
|
48
|
-
function f(t,
|
|
49
|
-
const
|
|
50
|
-
return
|
|
48
|
+
function f(t, r = {}) {
|
|
49
|
+
const e = r.fallbackUrl || "#";
|
|
50
|
+
return l(t, r) ? t.trim() : e;
|
|
51
51
|
}
|
|
52
|
-
function
|
|
53
|
-
return t.map((
|
|
52
|
+
function P(t, r = {}) {
|
|
53
|
+
return t.map((e) => f(e, r));
|
|
54
54
|
}
|
|
55
55
|
export {
|
|
56
|
-
|
|
56
|
+
l as isUrlSafe,
|
|
57
57
|
f as sanitizeUrl,
|
|
58
|
-
|
|
58
|
+
P as sanitizeUrls
|
|
59
59
|
};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { UINT32_LE as h, StringType as k } from "../../../token-types/lib/index.js";
|
|
2
|
-
import D from "../../../../commonjs-virtual-dir/
|
|
2
|
+
import D from "../../../../commonjs-virtual-dir/browser2.js";
|
|
3
3
|
import { Signature as c, EndOfCentralDirectoryRecordToken as L, FileHeader as E, DataDescriptor as y, LocalFileHeaderToken as S } from "./ZipToken.js";
|
|
4
4
|
function m(s) {
|
|
5
5
|
const t = new Uint8Array(h.len);
|