@flaxia/node 0.3.7 → 0.5.1
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/README.md +43 -19
- package/dist/__tests__/consent-policy.test.d.ts +2 -0
- package/dist/__tests__/consent-policy.test.d.ts.map +1 -0
- package/dist/assets/VectorStoreEngine.js +140 -85
- package/dist/assets/ai-inference.js +336 -40
- package/dist/assets/container.js +368 -260
- package/dist/assets/egress-guard.js +174 -0
- package/dist/assets/image-process.js +184 -19
- package/dist/assets/nudenet.js +2 -2
- package/dist/assets/webgpuProbe.js +357 -0
- package/dist/client/SignalingClient.d.ts +6 -0
- package/dist/client/SignalingClient.d.ts.map +1 -1
- package/dist/client/__tests__/mobile-lifecycle.test.d.ts +2 -0
- package/dist/client/__tests__/mobile-lifecycle.test.d.ts.map +1 -0
- package/dist/client/mobile-lifecycle.d.ts +20 -0
- package/dist/client/mobile-lifecycle.d.ts.map +1 -0
- package/dist/consent/ConsentUI.d.ts +44 -5
- package/dist/consent/ConsentUI.d.ts.map +1 -1
- package/dist/consent/notice.d.ts +29 -0
- package/dist/consent/notice.d.ts.map +1 -0
- package/dist/consent/storage.d.ts +91 -7
- package/dist/consent/storage.d.ts.map +1 -1
- package/dist/executor/WorkerPool.d.ts +42 -2
- package/dist/executor/WorkerPool.d.ts.map +1 -1
- package/dist/executor/__tests__/WorkerPool.swarm.test.d.ts +13 -0
- package/dist/executor/__tests__/WorkerPool.swarm.test.d.ts.map +1 -0
- package/dist/executor/__tests__/container-executor.test.d.ts +2 -0
- package/dist/executor/__tests__/container-executor.test.d.ts.map +1 -0
- package/dist/executor/__tests__/egress-guard.test.d.ts +2 -0
- package/dist/executor/__tests__/egress-guard.test.d.ts.map +1 -0
- package/dist/executor/__tests__/resourceReporter.test.d.ts +2 -0
- package/dist/executor/__tests__/resourceReporter.test.d.ts.map +1 -0
- package/dist/executor/__tests__/webgpuProbe.test.d.ts +2 -0
- package/dist/executor/__tests__/webgpuProbe.test.d.ts.map +1 -0
- package/dist/executor/container-executor.d.ts +49 -1
- package/dist/executor/container-executor.d.ts.map +1 -1
- package/dist/executor/egress-guard.d.ts +105 -0
- package/dist/executor/egress-guard.d.ts.map +1 -0
- package/dist/executor/memoryProbe.d.ts +30 -0
- package/dist/executor/memoryProbe.d.ts.map +1 -1
- package/dist/executor/resourceReporter.d.ts +15 -0
- package/dist/executor/resourceReporter.d.ts.map +1 -0
- package/dist/executor/throttle.d.ts +62 -4
- package/dist/executor/throttle.d.ts.map +1 -1
- package/dist/executor/webgpuProbe.d.ts +20 -0
- package/dist/executor/webgpuProbe.d.ts.map +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1423 -235
- package/dist/swarm/__tests__/adapter.test.d.ts +2 -0
- package/dist/swarm/__tests__/adapter.test.d.ts.map +1 -0
- package/dist/swarm/__tests__/controller.test.d.ts +2 -0
- package/dist/swarm/__tests__/controller.test.d.ts.map +1 -0
- package/dist/swarm/__tests__/defects.test.d.ts +16 -0
- package/dist/swarm/__tests__/defects.test.d.ts.map +1 -0
- package/dist/swarm/__tests__/hardening.test.d.ts +2 -0
- package/dist/swarm/__tests__/hardening.test.d.ts.map +1 -0
- package/dist/swarm/__tests__/peer-quality.test.d.ts +2 -0
- package/dist/swarm/__tests__/peer-quality.test.d.ts.map +1 -0
- package/dist/swarm/__tests__/peer-transport.test.d.ts +2 -0
- package/dist/swarm/__tests__/peer-transport.test.d.ts.map +1 -0
- package/dist/swarm/__tests__/runtime.test.d.ts +2 -0
- package/dist/swarm/__tests__/runtime.test.d.ts.map +1 -0
- package/dist/swarm/__tests__/session.test.d.ts +2 -0
- package/dist/swarm/__tests__/session.test.d.ts.map +1 -0
- package/dist/swarm/adapter.d.ts +115 -0
- package/dist/swarm/adapter.d.ts.map +1 -0
- package/dist/swarm/controller.d.ts +91 -0
- package/dist/swarm/controller.d.ts.map +1 -0
- package/dist/swarm/messages.d.ts +41 -0
- package/dist/swarm/messages.d.ts.map +1 -0
- package/dist/swarm/peer-quality.d.ts +14 -0
- package/dist/swarm/peer-quality.d.ts.map +1 -0
- package/dist/swarm/peer-transport.d.ts +81 -0
- package/dist/swarm/peer-transport.d.ts.map +1 -0
- package/dist/swarm/runtime.d.ts +20 -0
- package/dist/swarm/runtime.d.ts.map +1 -0
- package/dist/swarm/session.d.ts +73 -0
- package/dist/swarm/session.d.ts.map +1 -0
- package/dist/swarm-engine.js +7496 -0
- package/dist/vector-store/HNSWIndex.d.ts +30 -0
- package/dist/vector-store/HNSWIndex.d.ts.map +1 -1
- package/dist/vector-store/VectorStoreEngine.d.ts +43 -0
- package/dist/vector-store/VectorStoreEngine.d.ts.map +1 -1
- package/dist/vector-store/__tests__/HNSWIndex.test.d.ts +2 -0
- package/dist/vector-store/__tests__/HNSWIndex.test.d.ts.map +1 -0
- package/dist/vector-store/__tests__/VectorStoreEngine.test.d.ts +2 -0
- package/dist/vector-store/__tests__/VectorStoreEngine.test.d.ts.map +1 -0
- package/dist/worker/__tests__/main.worker.abort.test.d.ts +2 -0
- package/dist/worker/__tests__/main.worker.abort.test.d.ts.map +1 -0
- package/dist/worker/__tests__/main.worker.control.test.d.ts +2 -0
- package/dist/worker/__tests__/main.worker.control.test.d.ts.map +1 -0
- package/dist/worker.js +766 -67
- package/dist/workloads/__tests__/model-pipeline-cache.test.d.ts +2 -0
- package/dist/workloads/__tests__/model-pipeline-cache.test.d.ts.map +1 -0
- package/dist/workloads/__tests__/nudenet.test.d.ts +2 -0
- package/dist/workloads/__tests__/nudenet.test.d.ts.map +1 -0
- package/dist/workloads/ai-inference.d.ts +8 -1
- package/dist/workloads/ai-inference.d.ts.map +1 -1
- package/dist/workloads/ai-model-registry.d.ts +72 -0
- package/dist/workloads/ai-model-registry.d.ts.map +1 -0
- package/dist/workloads/container.d.ts +1 -1
- package/dist/workloads/container.d.ts.map +1 -1
- package/dist/workloads/image-process.d.ts +27 -0
- package/dist/workloads/image-process.d.ts.map +1 -1
- package/dist/workloads/model-pipeline-cache.d.ts +48 -0
- package/dist/workloads/model-pipeline-cache.d.ts.map +1 -0
- package/dist/workloads/nudenet.d.ts +8 -0
- package/dist/workloads/nudenet.d.ts.map +1 -1
- package/package.json +3 -2
- package/dist/assets/memoryProbe.js +0 -28
- package/dist/client/WebRTCPeer.d.ts +0 -8
- package/dist/client/WebRTCPeer.d.ts.map +0 -1
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
var e = 256 * 1024 * 1024, t = [443], n = [
|
|
2
|
+
".local",
|
|
3
|
+
".internal",
|
|
4
|
+
".localhost",
|
|
5
|
+
".home.arpa"
|
|
6
|
+
], r = ["localhost"];
|
|
7
|
+
function i(e) {
|
|
8
|
+
throw Error(`Egress blocked: ${e}`);
|
|
9
|
+
}
|
|
10
|
+
function a(e) {
|
|
11
|
+
(e.username || e.password) && i(`credentials in URL are not allowed (${e.protocol}//${e.hostname})`);
|
|
12
|
+
}
|
|
13
|
+
function o(e) {
|
|
14
|
+
let t = e.split(".");
|
|
15
|
+
if (t.length !== 4) return !1;
|
|
16
|
+
let n = [];
|
|
17
|
+
for (let e of t) {
|
|
18
|
+
if (!/^\d{1,3}$/.test(e)) return !1;
|
|
19
|
+
let t = Number(e);
|
|
20
|
+
if (t > 255) return !1;
|
|
21
|
+
n.push(t);
|
|
22
|
+
}
|
|
23
|
+
let [r, i, a] = n;
|
|
24
|
+
return r === 0 || r === 10 || r === 127 || r === 169 && i === 254 || r === 172 && i >= 16 && i <= 31 || r === 192 && i === 168 || r === 192 && i === 0 && a === 0 || r === 192 && i === 0 && a === 2 || r === 198 && (i === 18 || i === 19) || r === 198 && i === 51 && a === 100 || r === 203 && i === 0 && a === 113 || r === 100 && i >= 64 && i <= 127 || r >= 224;
|
|
25
|
+
}
|
|
26
|
+
function s(e) {
|
|
27
|
+
let t = e.trim().toLowerCase();
|
|
28
|
+
if (t.startsWith("[") && t.endsWith("]") && (t = t.slice(1, -1)), !t.includes(":") || t.includes("%")) return null;
|
|
29
|
+
let n = t, r = "", i = t.indexOf("::");
|
|
30
|
+
if (i !== -1) {
|
|
31
|
+
if (t.indexOf("::", i + 1) !== -1) return null;
|
|
32
|
+
n = t.slice(0, i), r = t.slice(i + 2);
|
|
33
|
+
}
|
|
34
|
+
let a = (e) => {
|
|
35
|
+
if (e === "") return [];
|
|
36
|
+
let t = [], n = e.split(":");
|
|
37
|
+
for (let e = 0; e < n.length; e++) {
|
|
38
|
+
let r = n[e];
|
|
39
|
+
if (r.includes(".")) {
|
|
40
|
+
if (e !== n.length - 1) return null;
|
|
41
|
+
let i = r.split(".");
|
|
42
|
+
if (i.length !== 4) return null;
|
|
43
|
+
let a = [];
|
|
44
|
+
for (let e of i) {
|
|
45
|
+
if (!/^\d{1,3}$/.test(e)) return null;
|
|
46
|
+
let t = Number(e);
|
|
47
|
+
if (t > 255) return null;
|
|
48
|
+
a.push(t);
|
|
49
|
+
}
|
|
50
|
+
t.push(a[0] << 8 | a[1], a[2] << 8 | a[3]);
|
|
51
|
+
continue;
|
|
52
|
+
}
|
|
53
|
+
if (!/^[0-9a-f]{1,4}$/.test(r)) return null;
|
|
54
|
+
t.push(parseInt(r, 16));
|
|
55
|
+
}
|
|
56
|
+
return t;
|
|
57
|
+
}, o = a(n), s = a(r);
|
|
58
|
+
if (o === null || s === null) return null;
|
|
59
|
+
if (i === -1) return o.length === 8 ? o : null;
|
|
60
|
+
let c = 8 - o.length - s.length;
|
|
61
|
+
return c < 1 ? null : [
|
|
62
|
+
...o,
|
|
63
|
+
...Array(c).fill(0),
|
|
64
|
+
...s
|
|
65
|
+
];
|
|
66
|
+
}
|
|
67
|
+
function c(e) {
|
|
68
|
+
let t = s(e);
|
|
69
|
+
if (!t) return !1;
|
|
70
|
+
let [n, r] = t;
|
|
71
|
+
return !!(t.every((e) => e === 0) || n === 0 && r === 0 && t.slice(2, 7).every((e) => e === 0) && t[7] === 1 || n === 0 && r === 0 && t.slice(2, 5).every((e) => e === 0) && (t[5] === 0 || t[5] === 65535) || (n & 65024) == 64512 || (n & 65472) == 65152 || (n & 65280) == 65280);
|
|
72
|
+
}
|
|
73
|
+
function l(e, t = {}) {
|
|
74
|
+
let a = e.trim().toLowerCase();
|
|
75
|
+
a || i("empty hostname"), r.includes(a) && i(`host blocked: ${a}`);
|
|
76
|
+
for (let e of n) a.endsWith(e) && i(`host blocked: ${a}`);
|
|
77
|
+
if (a.startsWith("[") || a.includes(":")) {
|
|
78
|
+
s(a) || i(`invalid IPv6 literal: ${a}`), c(a) && i(`IPv6 address blocked: ${a}`);
|
|
79
|
+
return;
|
|
80
|
+
}
|
|
81
|
+
/^\d{1,3}(\.\d{1,3}){3}$/.test(a) && o(a) && i(`IPv4 address blocked: ${a}`), /^[a-z0-9.-]+$/.test(a) || i(`host is not a plain DNS name or IP literal: ${a}`);
|
|
82
|
+
}
|
|
83
|
+
function u(e, n = {}) {
|
|
84
|
+
let r;
|
|
85
|
+
if (e instanceof URL) r = new URL(e.toString());
|
|
86
|
+
else try {
|
|
87
|
+
r = new URL(e);
|
|
88
|
+
} catch {
|
|
89
|
+
i(`invalid URL: ${String(e)}`);
|
|
90
|
+
}
|
|
91
|
+
(n.allowInsecure ? ["https:", "http:"] : ["https:"]).includes(r.protocol) || i(`protocol not allowed: ${r.protocol}`), a(r);
|
|
92
|
+
let o = n.allowedPorts ?? t;
|
|
93
|
+
return r.port && !o.includes(Number(r.port)) && i(`port not allowed: ${r.port}`), l(r.hostname, n), r;
|
|
94
|
+
}
|
|
95
|
+
function d(e) {
|
|
96
|
+
return e ? e.split(";")[0].trim().toLowerCase() : "";
|
|
97
|
+
}
|
|
98
|
+
function f(e, t) {
|
|
99
|
+
if (t.length === 0) return !1;
|
|
100
|
+
for (let n of t) {
|
|
101
|
+
let t = n.toLowerCase();
|
|
102
|
+
if (t.endsWith("/*")) {
|
|
103
|
+
if (e.startsWith(t.slice(0, -1))) return !0;
|
|
104
|
+
} else if (e === t) return !0;
|
|
105
|
+
}
|
|
106
|
+
return !1;
|
|
107
|
+
}
|
|
108
|
+
function p(e, t) {
|
|
109
|
+
try {
|
|
110
|
+
return new URL(e, t).toString();
|
|
111
|
+
} catch {
|
|
112
|
+
i(`invalid redirect location: ${e}`);
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
async function m(e, t, n) {
|
|
116
|
+
let r = Number(e.headers.get("content-length"));
|
|
117
|
+
Number.isFinite(r) && r > t && i(`response too large: ${n} declares ${r} bytes (cap ${t})`);
|
|
118
|
+
let a = e.body;
|
|
119
|
+
if (!a || typeof a.getReader != "function") {
|
|
120
|
+
let r = new Uint8Array(await e.arrayBuffer());
|
|
121
|
+
return r.byteLength > t && i(`response too large: ${n} returned ${r.byteLength} bytes (cap ${t})`), r;
|
|
122
|
+
}
|
|
123
|
+
let o = a.getReader(), s = [], c = 0, l = !1;
|
|
124
|
+
try {
|
|
125
|
+
for (;;) {
|
|
126
|
+
let { done: e, value: r } = await o.read();
|
|
127
|
+
if (e) break;
|
|
128
|
+
r && (c += r.byteLength, c > t && (l = !0, await o.cancel().catch(() => void 0), i(`response too large: ${n} exceeded ${t} bytes`)), s.push(r));
|
|
129
|
+
}
|
|
130
|
+
} finally {
|
|
131
|
+
l || o.releaseLock?.();
|
|
132
|
+
}
|
|
133
|
+
let u = new Uint8Array(c), d = 0;
|
|
134
|
+
for (let e of s) u.set(e, d), d += e.byteLength;
|
|
135
|
+
return u;
|
|
136
|
+
}
|
|
137
|
+
async function h(t, n = {}) {
|
|
138
|
+
typeof t.url != "string" && !(t.url instanceof URL) && i("url must be a string or URL"), (!Array.isArray(t.allowContentTypes) || t.allowContentTypes.length === 0) && i("no Content-Type allowlist configured");
|
|
139
|
+
let r = Math.min(Math.max(1, Math.floor(t.maxBytes ?? 8388608)), e), a = Math.max(1, Math.floor(t.timeoutMs ?? 3e4)), o = t.method ?? "GET", s = u(t.url, n), c = 0;
|
|
140
|
+
for (;;) {
|
|
141
|
+
let e;
|
|
142
|
+
try {
|
|
143
|
+
e = await fetch(s.toString(), {
|
|
144
|
+
method: o,
|
|
145
|
+
headers: t.headers,
|
|
146
|
+
redirect: "manual",
|
|
147
|
+
credentials: "omit",
|
|
148
|
+
referrerPolicy: "no-referrer",
|
|
149
|
+
signal: AbortSignal.timeout(a)
|
|
150
|
+
});
|
|
151
|
+
} catch (e) {
|
|
152
|
+
i(`request failed: ${s.toString()} (${e instanceof Error ? e.message : String(e)})`);
|
|
153
|
+
}
|
|
154
|
+
if (e.type === "opaqueredirect" || e.status >= 300 && e.status < 400) {
|
|
155
|
+
(e.status === 0 || e.type === "opaqueredirect") && i(`redirect could not be validated: ${s.toString()}`);
|
|
156
|
+
let t = e.headers.get("location");
|
|
157
|
+
t || i(`redirect without Location: ${s.toString()}`), c >= 3 && i("too many redirects (>3)"), c++, s = u(p(t, s), n);
|
|
158
|
+
continue;
|
|
159
|
+
}
|
|
160
|
+
let l = d(e.headers.get("content-type"));
|
|
161
|
+
f(l, t.allowContentTypes) || i(`content-type not allowed: ${l || "(missing)"} for ${s.toString()}`);
|
|
162
|
+
let h = e.ok && o !== "HEAD" ? await m(e, r, s.toString()) : new Uint8Array();
|
|
163
|
+
return {
|
|
164
|
+
url: s.toString(),
|
|
165
|
+
status: e.status,
|
|
166
|
+
ok: e.ok,
|
|
167
|
+
contentType: l,
|
|
168
|
+
bytes: h,
|
|
169
|
+
byteLength: h.byteLength
|
|
170
|
+
};
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
//#endregion
|
|
174
|
+
export { h as n, u as t };
|
|
@@ -1,23 +1,188 @@
|
|
|
1
1
|
//#region src/workloads/image-process.ts
|
|
2
|
-
var e =
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
2
|
+
var e = 8192, t = 32 * 1024 * 1024, n = 16 * 1024 * 1024;
|
|
3
|
+
function r(e, t) {
|
|
4
|
+
return e[t] * 16777216 + (e[t + 1] << 16) + (e[t + 2] << 8) + e[t + 3] >>> 0;
|
|
5
|
+
}
|
|
6
|
+
function i(e, t) {
|
|
7
|
+
return e[t] + e[t + 1] * 256 + e[t + 2] * 65536 + e[t + 3] * 16777216 >>> 0;
|
|
8
|
+
}
|
|
9
|
+
function a(e, t) {
|
|
10
|
+
return e[t] * 256 + e[t + 1];
|
|
11
|
+
}
|
|
12
|
+
function o(e, t, n) {
|
|
13
|
+
return t + n.length <= e.length && n.every((n, r) => e[t + r] === n);
|
|
14
|
+
}
|
|
15
|
+
function s() {
|
|
16
|
+
throw Error("image-process: unknown, truncated or inconsistent image header");
|
|
17
|
+
}
|
|
18
|
+
function c(e) {
|
|
19
|
+
if (o(e, 0, [
|
|
20
|
+
137,
|
|
21
|
+
80,
|
|
22
|
+
78,
|
|
23
|
+
71,
|
|
24
|
+
13,
|
|
25
|
+
10,
|
|
26
|
+
26,
|
|
27
|
+
10
|
|
28
|
+
])) return (e.length < 33 || r(e, 8) !== 13 || !o(e, 12, [
|
|
29
|
+
73,
|
|
30
|
+
72,
|
|
31
|
+
68,
|
|
32
|
+
82
|
|
33
|
+
]) || !(e[25] === 0 && [
|
|
34
|
+
1,
|
|
35
|
+
2,
|
|
36
|
+
4,
|
|
37
|
+
8,
|
|
38
|
+
16
|
|
39
|
+
].includes(e[24]) || e[25] === 2 && [8, 16].includes(e[24]) || e[25] === 3 && [
|
|
40
|
+
1,
|
|
41
|
+
2,
|
|
42
|
+
4,
|
|
43
|
+
8
|
|
44
|
+
].includes(e[24]) || [4, 6].includes(e[25]) && [8, 16].includes(e[24])) || e[26] !== 0 || e[27] !== 0 || e[28] > 1) && s(), {
|
|
45
|
+
width: r(e, 16),
|
|
46
|
+
height: r(e, 20),
|
|
47
|
+
format: "png"
|
|
20
48
|
};
|
|
49
|
+
if (o(e, 0, [255, 216])) {
|
|
50
|
+
let t = 2;
|
|
51
|
+
for (; t < e.length;) {
|
|
52
|
+
for (e[t++] !== 255 && s(); t < e.length && e[t] === 255;) t++;
|
|
53
|
+
t >= e.length && s();
|
|
54
|
+
let n = e[t++];
|
|
55
|
+
if ((n === 0 || n === 216 || n === 217 || n === 218) && s(), n === 1 || n >= 208 && n <= 215) continue;
|
|
56
|
+
t + 2 > e.length && s();
|
|
57
|
+
let r = a(e, t);
|
|
58
|
+
if ((r < 2 || t + r > e.length) && s(), [
|
|
59
|
+
192,
|
|
60
|
+
193,
|
|
61
|
+
194,
|
|
62
|
+
195,
|
|
63
|
+
197,
|
|
64
|
+
198,
|
|
65
|
+
199,
|
|
66
|
+
201,
|
|
67
|
+
202,
|
|
68
|
+
203,
|
|
69
|
+
205,
|
|
70
|
+
206,
|
|
71
|
+
207
|
|
72
|
+
].includes(n)) return (r < 8 || e[t + 2] === 0 || e[t + 7] === 0 || r !== 8 + e[t + 7] * 3) && s(), {
|
|
73
|
+
width: a(e, t + 5),
|
|
74
|
+
height: a(e, t + 3),
|
|
75
|
+
format: "jpeg"
|
|
76
|
+
};
|
|
77
|
+
t += r;
|
|
78
|
+
}
|
|
79
|
+
s();
|
|
80
|
+
}
|
|
81
|
+
if (o(e, 0, [
|
|
82
|
+
82,
|
|
83
|
+
73,
|
|
84
|
+
70,
|
|
85
|
+
70
|
|
86
|
+
]) && o(e, 8, [
|
|
87
|
+
87,
|
|
88
|
+
69,
|
|
89
|
+
66,
|
|
90
|
+
80
|
|
91
|
+
])) {
|
|
92
|
+
(e.length < 20 || i(e, 4) !== e.length - 8) && s();
|
|
93
|
+
let t = i(e, 16);
|
|
94
|
+
if ((t > e.length - 20 || t % 2 + t + 20 > e.length) && s(), o(e, 12, [
|
|
95
|
+
86,
|
|
96
|
+
80,
|
|
97
|
+
56,
|
|
98
|
+
88
|
|
99
|
+
])) return (t !== 10 || e[20] & 193 || e[21] !== 0 || e[22] !== 0 || e[23] !== 0) && s(), {
|
|
100
|
+
width: 1 + e[24] + (e[25] << 8) + (e[26] << 16),
|
|
101
|
+
height: 1 + e[27] + (e[28] << 8) + (e[29] << 16),
|
|
102
|
+
format: "webp"
|
|
103
|
+
};
|
|
104
|
+
if (o(e, 12, [
|
|
105
|
+
86,
|
|
106
|
+
80,
|
|
107
|
+
56,
|
|
108
|
+
76
|
|
109
|
+
])) {
|
|
110
|
+
(t < 5 || e[20] !== 47 || e[24] & 240) && s();
|
|
111
|
+
let n = i(e, 21);
|
|
112
|
+
return {
|
|
113
|
+
width: (n & 16383) + 1,
|
|
114
|
+
height: (n >>> 14 & 16383) + 1,
|
|
115
|
+
format: "webp"
|
|
116
|
+
};
|
|
117
|
+
}
|
|
118
|
+
if (o(e, 12, [
|
|
119
|
+
86,
|
|
120
|
+
80,
|
|
121
|
+
56,
|
|
122
|
+
32
|
|
123
|
+
])) return (t < 10 || e[20] & 1 || !o(e, 23, [
|
|
124
|
+
157,
|
|
125
|
+
1,
|
|
126
|
+
42
|
|
127
|
+
])) && s(), {
|
|
128
|
+
width: (e[27] << 8 | e[26]) & 16383,
|
|
129
|
+
height: (e[29] << 8 | e[28]) & 16383,
|
|
130
|
+
format: "webp"
|
|
131
|
+
};
|
|
132
|
+
s();
|
|
133
|
+
}
|
|
134
|
+
s();
|
|
135
|
+
}
|
|
136
|
+
function l({ width: n, height: r }) {
|
|
137
|
+
if (!Number.isSafeInteger(n) || !Number.isSafeInteger(r) || n < 1 || r < 1 || n > 8192 || r > 8192 || n * r > 33554432) throw Error(`image-process: source dimensions ${n}x${r} exceed image limits (${e}px side, ${t} pixels)`);
|
|
138
|
+
}
|
|
139
|
+
function u(t, n) {
|
|
140
|
+
if (t == null) return null;
|
|
141
|
+
if (typeof t != "number" || !Number.isInteger(t) || t <= 0) throw Error(`image-process: options.${n} must be a positive integer, got ${JSON.stringify(t)}`);
|
|
142
|
+
if (t > 8192) throw Error(`image-process: options.${n} ${t} exceeds the ${e}px limit`);
|
|
143
|
+
return t;
|
|
144
|
+
}
|
|
145
|
+
function d(e, n) {
|
|
146
|
+
let r = u(e.width, "width") ?? n.width, i = u(e.height, "height") ?? n.height, a = {
|
|
147
|
+
width: Math.max(1, Math.min(r, n.width)),
|
|
148
|
+
height: Math.max(1, Math.min(i, n.height))
|
|
149
|
+
};
|
|
150
|
+
if (a.width * a.height > 33554432) throw Error(`image-process: canvas ${a.width}x${a.height} exceeds the ${t} pixel limit`);
|
|
151
|
+
return a;
|
|
152
|
+
}
|
|
153
|
+
var f = async (e) => {
|
|
154
|
+
let { operation: t, imageBase64: r, mimeType: i, options: a } = e, o = performance.now();
|
|
155
|
+
if (typeof r != "string" || r.length > 22369624 || !/^[A-Za-z0-9+/]*={0,2}$/.test(r) || r.length % 4 != 0) throw Error(`image-process: invalid base64 or image exceeds ${n} byte limit`);
|
|
156
|
+
let s = r.endsWith("==") ? 2 : +!!r.endsWith("="), u = r.length / 4 * 3 - s;
|
|
157
|
+
if (u > 16777216) throw Error(`image-process: image exceeds ${n} byte limit`);
|
|
158
|
+
let f = await (await fetch(`data:${i};base64,${r}`)).blob();
|
|
159
|
+
if (f.size > 16777216) throw Error(`image-process: image exceeds ${n} byte limit`);
|
|
160
|
+
let p = c(new Uint8Array(await f.arrayBuffer()));
|
|
161
|
+
if (l(p), i !== `image/${p.format}`) throw Error(`image-process: declared MIME ${i} does not match ${p.format} image`);
|
|
162
|
+
let m = await createImageBitmap(f);
|
|
163
|
+
try {
|
|
164
|
+
if (m.width !== p.width || m.height !== p.height) throw Error("image-process: decoded image dimensions differ from image header");
|
|
165
|
+
let e = d(a, m), n = new OffscreenCanvas(e.width, e.height), r = n.getContext("2d");
|
|
166
|
+
if (!r) throw Error("Failed to get OffscreenCanvas context");
|
|
167
|
+
t === "grayscale" && (r.filter = "grayscale(100%)"), r.drawImage(m, 0, 0, n.width, n.height);
|
|
168
|
+
let s = a.outputFormat || i.split("/")[1], c = `image/${s}`, l = await n.convertToBlob({
|
|
169
|
+
type: c,
|
|
170
|
+
quality: a.quality || .8
|
|
171
|
+
}), h = new FileReader(), g = await new Promise((e, t) => {
|
|
172
|
+
h.onloadend = () => {
|
|
173
|
+
let t = h.result.split(",")[1];
|
|
174
|
+
e(t);
|
|
175
|
+
}, h.onerror = t, h.readAsDataURL(l);
|
|
176
|
+
});
|
|
177
|
+
return console.log(`[flaxia-node] image-process: done operation=${t} output=${s} size=${e.width}x${e.height} inputBytes=${u} resultBytes=${l.size} durationMs=${Math.round(performance.now() - o)}`), {
|
|
178
|
+
imageBase64: g,
|
|
179
|
+
mimeType: c,
|
|
180
|
+
originalSizeBytes: f.size,
|
|
181
|
+
resultSizeBytes: l.size
|
|
182
|
+
};
|
|
183
|
+
} finally {
|
|
184
|
+
m.close();
|
|
185
|
+
}
|
|
21
186
|
};
|
|
22
187
|
//#endregion
|
|
23
|
-
export {
|
|
188
|
+
export { f as handleImageProcess };
|
package/dist/assets/nudenet.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
[diffend] Oversized file quarantined before diffing.
|
|
2
2
|
name: package/dist/assets/nudenet.js
|
|
3
|
-
size:
|
|
4
|
-
sha256:
|
|
3
|
+
size: 70464329 bytes
|
|
4
|
+
sha256: d6b0662a4da0668cefa3583cd693e3652bec3a34a59cc459b7a66bb01a2060b0
|