@glodon-aiot/bot-client-sdk 3.26.0-alpha.19 → 3.26.0-alpha.20
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 +12 -2
- package/dist/es/localFiles/adapters/HostBridgeAdapter.mjs +47 -33
- package/dist/es/localFiles/errors.mjs +21 -19
- package/dist/es/localFiles/host/sandboxClient.mjs +196 -171
- package/dist/es/localFiles/preview.mjs +33 -0
- package/dist/es/localFiles/workspace/LocalWorkspace.mjs +19 -16
- package/dist/es/localFiles/workspace/WorkspaceFiles.mjs +191 -133
- package/dist/es/package.json.mjs +2 -2
- package/dist/lib/index.js +22 -22
- package/dist/src/localFiles/adapters/HostBridgeAdapter.d.ts +4 -0
- package/dist/src/localFiles/adapters/WorkspaceFileAdapter.d.ts +8 -0
- package/dist/src/localFiles/host/sandboxClient.d.ts +4 -0
- package/dist/src/localFiles/preview.d.ts +2 -0
- package/dist/src/localFiles/workspace/LocalWorkspace.d.ts +1 -0
- package/dist/src/localFiles/workspace/WorkspaceFiles.d.ts +13 -4
- package/package.json +2 -2
|
@@ -1,36 +1,36 @@
|
|
|
1
|
-
var
|
|
2
|
-
var
|
|
1
|
+
var B = Object.defineProperty, M = Object.defineProperties;
|
|
2
|
+
var U = Object.getOwnPropertyDescriptors;
|
|
3
3
|
var v = Object.getOwnPropertySymbols;
|
|
4
|
-
var
|
|
5
|
-
var
|
|
4
|
+
var _ = Object.prototype.hasOwnProperty, C = Object.prototype.propertyIsEnumerable;
|
|
5
|
+
var S = (a, t, e) => t in a ? B(a, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : a[t] = e, y = (a, t) => {
|
|
6
6
|
for (var e in t || (t = {}))
|
|
7
|
-
|
|
7
|
+
_.call(t, e) && S(a, e, t[e]);
|
|
8
8
|
if (v)
|
|
9
9
|
for (var e of v(t))
|
|
10
|
-
|
|
10
|
+
C.call(t, e) && S(a, e, t[e]);
|
|
11
11
|
return a;
|
|
12
|
-
},
|
|
13
|
-
var
|
|
14
|
-
var
|
|
15
|
-
var
|
|
12
|
+
}, N = (a, t) => M(a, U(t));
|
|
13
|
+
var w = (a, t, e) => (S(a, typeof t != "symbol" ? t + "" : t, e), e);
|
|
14
|
+
var u = (a, t, e) => new Promise((s, r) => {
|
|
15
|
+
var i = (o) => {
|
|
16
16
|
try {
|
|
17
|
-
l(e.next(
|
|
17
|
+
l(e.next(o));
|
|
18
18
|
} catch (h) {
|
|
19
|
-
|
|
19
|
+
r(h);
|
|
20
20
|
}
|
|
21
|
-
}, n = (
|
|
21
|
+
}, n = (o) => {
|
|
22
22
|
try {
|
|
23
|
-
l(e.throw(
|
|
23
|
+
l(e.throw(o));
|
|
24
24
|
} catch (h) {
|
|
25
|
-
|
|
25
|
+
r(h);
|
|
26
26
|
}
|
|
27
|
-
}, l = (
|
|
27
|
+
}, l = (o) => o.done ? s(o.value) : Promise.resolve(o.value).then(i, n);
|
|
28
28
|
l((e = e.apply(a, t)).next());
|
|
29
29
|
});
|
|
30
|
-
import { MAX_COMMAND_OUTPUT_CHARS as
|
|
30
|
+
import { MAX_COMMAND_OUTPUT_CHARS as m } from "../../builtinTools/command.mjs";
|
|
31
31
|
import { domError as f } from "../adapters/WorkspaceFileAdapter.mjs";
|
|
32
|
-
import { SANDBOX_PROTOCOL as
|
|
33
|
-
import { decodeBinaryFrame as E, MAX_BINARY_PAYLOAD as
|
|
32
|
+
import { SANDBOX_PROTOCOL as A, SANDBOX_MAX_FILE_BYTES as T } from "./protocol.mjs";
|
|
33
|
+
import { decodeBinaryFrame as E, MAX_BINARY_PAYLOAD as x, encodeBinaryFrame as O } from "./sandboxFrames.mjs";
|
|
34
34
|
const k = "沙箱已退出。";
|
|
35
35
|
function b(a) {
|
|
36
36
|
if (a instanceof Uint8Array)
|
|
@@ -38,32 +38,32 @@ function b(a) {
|
|
|
38
38
|
if (a instanceof ArrayBuffer)
|
|
39
39
|
return new Uint8Array(a);
|
|
40
40
|
}
|
|
41
|
-
function
|
|
42
|
-
const
|
|
43
|
-
if (!t && !e && !
|
|
44
|
-
return
|
|
45
|
-
let
|
|
41
|
+
function P(a, t, e, s) {
|
|
42
|
+
const r = a.length > m ? a.slice(a.length - m) : a;
|
|
43
|
+
if (!t && !e && !s && a.length <= m)
|
|
44
|
+
return r;
|
|
45
|
+
let i = `
|
|
46
46
|
…输出已截断`;
|
|
47
|
-
return e && (
|
|
47
|
+
return e && (i += `,完整输出见 ${e}`), s && (i += ",日志已截断"), r + i;
|
|
48
48
|
}
|
|
49
49
|
class R {
|
|
50
50
|
constructor(t = (e) => new WebSocket(e)) {
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
51
|
+
w(this, "notice");
|
|
52
|
+
w(this, "socket");
|
|
53
|
+
w(this, "generation", 0);
|
|
54
|
+
w(this, "authed", !1);
|
|
55
|
+
w(this, "seq", 0);
|
|
56
|
+
w(this, "calls", /* @__PURE__ */ new Map());
|
|
57
|
+
w(this, "outgoing", []);
|
|
58
58
|
this.openSocket = t;
|
|
59
59
|
}
|
|
60
60
|
get ready() {
|
|
61
61
|
const t = this.notice;
|
|
62
|
-
return (t == null ? void 0 : t.state) === "ready" && t.protocol ===
|
|
62
|
+
return (t == null ? void 0 : t.state) === "ready" && t.protocol === A && !!(t.url && t.token);
|
|
63
63
|
}
|
|
64
64
|
unavailableMessage() {
|
|
65
|
-
var t, e,
|
|
66
|
-
return ((t = this.notice) == null ? void 0 : t.state) === "starting" ? "沙箱正在启动。" : (e = this.notice) != null && e.message ? this.notice.message : ((
|
|
65
|
+
var t, e, s, r;
|
|
66
|
+
return ((t = this.notice) == null ? void 0 : t.state) === "starting" ? "沙箱正在启动。" : (e = this.notice) != null && e.message ? this.notice.message : ((s = this.notice) == null ? void 0 : s.state) === "exited" || ((r = this.notice) == null ? void 0 : r.state) === "failed" ? k : "沙箱没有就绪。";
|
|
67
67
|
}
|
|
68
68
|
apply(t) {
|
|
69
69
|
const e = this.notice;
|
|
@@ -73,145 +73,170 @@ class R {
|
|
|
73
73
|
}
|
|
74
74
|
(e == null ? void 0 : e.url) === t.url && e.token === t.token && this.socket && this.socket.readyState <= 1 || (this.failAll(f("AbortError", k)), this.stop(), this.connect(t.url, t.token));
|
|
75
75
|
}
|
|
76
|
+
/** `ws://127.0.0.1:port` 的主机和端口,文件地址拼在它前面。 */
|
|
77
|
+
httpOrigin() {
|
|
78
|
+
var e;
|
|
79
|
+
const t = (e = this.notice) == null ? void 0 : e.url;
|
|
80
|
+
return t != null && t.startsWith("ws://") ? t.slice(5).replace(/\/$/, "") : "";
|
|
81
|
+
}
|
|
76
82
|
stat(t) {
|
|
77
|
-
return
|
|
83
|
+
return u(this, null, function* () {
|
|
78
84
|
return this.invoke({
|
|
79
85
|
op: "stat",
|
|
80
86
|
path: t
|
|
81
87
|
});
|
|
82
88
|
});
|
|
83
89
|
}
|
|
90
|
+
url(t) {
|
|
91
|
+
return u(this, null, function* () {
|
|
92
|
+
const s = (yield this.invoke({
|
|
93
|
+
op: "url",
|
|
94
|
+
path: t
|
|
95
|
+
})).ticket;
|
|
96
|
+
if (typeof s != "string" || !/^[a-f0-9]{32}$/.test(s))
|
|
97
|
+
throw f("NotAllowedError", "地址无效。");
|
|
98
|
+
return s;
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
releaseUrl(t) {
|
|
102
|
+
return u(this, null, function* () {
|
|
103
|
+
yield this.invoke({
|
|
104
|
+
op: "releaseUrl",
|
|
105
|
+
ticket: t
|
|
106
|
+
});
|
|
107
|
+
});
|
|
108
|
+
}
|
|
84
109
|
list(t, e) {
|
|
85
|
-
return
|
|
110
|
+
return u(this, null, function* () {
|
|
86
111
|
return this.invoke({
|
|
87
112
|
op: "list",
|
|
88
113
|
path: t
|
|
89
114
|
}, e);
|
|
90
115
|
});
|
|
91
116
|
}
|
|
92
|
-
read(
|
|
93
|
-
return
|
|
117
|
+
read(i) {
|
|
118
|
+
return u(this, arguments, function* (t, e = 0, s = T, r) {
|
|
94
119
|
const n = this.begin({
|
|
95
120
|
op: "read",
|
|
96
121
|
path: t,
|
|
97
122
|
offset: e,
|
|
98
|
-
maxBytes:
|
|
99
|
-
},
|
|
100
|
-
let
|
|
101
|
-
for (; !
|
|
102
|
-
const d = yield this.next(n),
|
|
103
|
-
if (
|
|
104
|
-
l.push(E(
|
|
123
|
+
maxBytes: s
|
|
124
|
+
}, r), l = [];
|
|
125
|
+
let o;
|
|
126
|
+
for (; !o; ) {
|
|
127
|
+
const d = yield this.next(n), p = b(d);
|
|
128
|
+
if (p) {
|
|
129
|
+
l.push(E(p).payload);
|
|
105
130
|
continue;
|
|
106
131
|
}
|
|
107
|
-
|
|
132
|
+
o = d;
|
|
108
133
|
}
|
|
109
|
-
if (this.calls.delete(n),
|
|
110
|
-
throw f(String(
|
|
111
|
-
const h = l.reduce((d,
|
|
112
|
-
let
|
|
134
|
+
if (this.calls.delete(n), o.ok === !1)
|
|
135
|
+
throw f(String(o.name || "NotAllowedError"), String(o.message || "读取失败。"));
|
|
136
|
+
const h = l.reduce((d, p) => d + p.length, 0), c = new Uint8Array(h);
|
|
137
|
+
let g = 0;
|
|
113
138
|
return l.forEach((d) => {
|
|
114
|
-
c.set(d,
|
|
139
|
+
c.set(d, g), g += d.length;
|
|
115
140
|
}), c;
|
|
116
141
|
});
|
|
117
142
|
}
|
|
118
|
-
write(t, e,
|
|
119
|
-
return
|
|
120
|
-
const
|
|
143
|
+
write(t, e, s, r) {
|
|
144
|
+
return u(this, null, function* () {
|
|
145
|
+
const i = this.begin({
|
|
121
146
|
op: "write",
|
|
122
147
|
path: t,
|
|
123
148
|
size: e.length,
|
|
124
|
-
createDirectories:
|
|
125
|
-
},
|
|
149
|
+
createDirectories: s
|
|
150
|
+
}, r);
|
|
126
151
|
let n = 0;
|
|
127
152
|
for (; n < e.length; ) {
|
|
128
|
-
const
|
|
129
|
-
this.send(
|
|
130
|
-
const
|
|
131
|
-
if (
|
|
132
|
-
throw this.calls.delete(
|
|
133
|
-
if (
|
|
134
|
-
this.calls.delete(
|
|
153
|
+
const o = e.subarray(n, n + x), h = n + o.length;
|
|
154
|
+
this.send(O(i, n, h === e.length, o)), n = h;
|
|
155
|
+
const g = yield this.next(i);
|
|
156
|
+
if (g.ok === !1)
|
|
157
|
+
throw this.calls.delete(i), f(String(g.name || "NotAllowedError"), String(g.message || "写入失败。"));
|
|
158
|
+
if (g.op !== "ack" && g.ok === !0) {
|
|
159
|
+
this.calls.delete(i);
|
|
135
160
|
return;
|
|
136
161
|
}
|
|
137
162
|
}
|
|
138
|
-
const l = yield this.next(
|
|
139
|
-
if (this.calls.delete(
|
|
163
|
+
const l = yield this.next(i);
|
|
164
|
+
if (this.calls.delete(i), l.ok === !1)
|
|
140
165
|
throw f(String(l.name || "NotAllowedError"), String(l.message || "写入失败。"));
|
|
141
166
|
});
|
|
142
167
|
}
|
|
143
168
|
skillStatus(t, e) {
|
|
144
|
-
return
|
|
145
|
-
const
|
|
169
|
+
return u(this, null, function* () {
|
|
170
|
+
const s = yield this.invoke({
|
|
146
171
|
op: "skillStatus",
|
|
147
172
|
applicationId: t
|
|
148
173
|
}, e);
|
|
149
|
-
return Array.isArray(
|
|
174
|
+
return Array.isArray(s.skills) ? s.skills : [];
|
|
150
175
|
});
|
|
151
176
|
}
|
|
152
|
-
skillRead(t, e,
|
|
153
|
-
return
|
|
177
|
+
skillRead(t, e, s, r, i) {
|
|
178
|
+
return u(this, null, function* () {
|
|
154
179
|
const n = this.begin({
|
|
155
180
|
op: "skillRead",
|
|
156
181
|
applicationId: t,
|
|
157
182
|
skillId: e,
|
|
158
|
-
version:
|
|
159
|
-
path:
|
|
160
|
-
},
|
|
161
|
-
let
|
|
162
|
-
for (; !
|
|
163
|
-
const d = yield this.next(n),
|
|
164
|
-
if (
|
|
165
|
-
l.push(E(
|
|
183
|
+
version: s,
|
|
184
|
+
path: r
|
|
185
|
+
}, i), l = [];
|
|
186
|
+
let o;
|
|
187
|
+
for (; !o; ) {
|
|
188
|
+
const d = yield this.next(n), p = b(d);
|
|
189
|
+
if (p) {
|
|
190
|
+
l.push(E(p).payload);
|
|
166
191
|
continue;
|
|
167
192
|
}
|
|
168
|
-
|
|
193
|
+
o = d;
|
|
169
194
|
}
|
|
170
|
-
if (this.calls.delete(n),
|
|
171
|
-
throw f(String(
|
|
172
|
-
const h = l.reduce((d,
|
|
173
|
-
let
|
|
195
|
+
if (this.calls.delete(n), o.ok === !1)
|
|
196
|
+
throw f(String(o.name || "NotAllowedError"), String(o.message || "读取失败。"));
|
|
197
|
+
const h = l.reduce((d, p) => d + p.length, 0), c = new Uint8Array(h);
|
|
198
|
+
let g = 0;
|
|
174
199
|
return l.forEach((d) => {
|
|
175
|
-
c.set(d,
|
|
200
|
+
c.set(d, g), g += d.length;
|
|
176
201
|
}), c;
|
|
177
202
|
});
|
|
178
203
|
}
|
|
179
|
-
installSkill(t, e,
|
|
180
|
-
return
|
|
181
|
-
const
|
|
204
|
+
installSkill(t, e, s) {
|
|
205
|
+
return u(this, null, function* () {
|
|
206
|
+
const r = this.begin(N(y({
|
|
182
207
|
op: "installSkill"
|
|
183
208
|
}, t), {
|
|
184
209
|
size: e.length
|
|
185
|
-
}),
|
|
186
|
-
let
|
|
187
|
-
for (;
|
|
188
|
-
const l = e.subarray(
|
|
189
|
-
this.send(
|
|
190
|
-
const h = yield this.next(
|
|
210
|
+
}), s);
|
|
211
|
+
let i = 0;
|
|
212
|
+
for (; i < e.length; ) {
|
|
213
|
+
const l = e.subarray(i, i + x), o = i + l.length;
|
|
214
|
+
this.send(O(r, i, o === e.length, l)), i = o;
|
|
215
|
+
const h = yield this.next(r);
|
|
191
216
|
if (h.ok === !1)
|
|
192
|
-
throw this.calls.delete(
|
|
217
|
+
throw this.calls.delete(r), f(String(h.name || "NotAllowedError"), String(h.message || "安装失败。"));
|
|
193
218
|
if (h.op !== "ack" && h.ok === !0) {
|
|
194
|
-
this.calls.delete(
|
|
219
|
+
this.calls.delete(r);
|
|
195
220
|
return;
|
|
196
221
|
}
|
|
197
222
|
}
|
|
198
|
-
const n = yield this.next(
|
|
199
|
-
if (this.calls.delete(
|
|
223
|
+
const n = yield this.next(r);
|
|
224
|
+
if (this.calls.delete(r), n.ok === !1)
|
|
200
225
|
throw f(String(n.name || "NotAllowedError"), String(n.message || "安装失败。"));
|
|
201
226
|
});
|
|
202
227
|
}
|
|
203
|
-
skillPrune(t, e,
|
|
204
|
-
return
|
|
228
|
+
skillPrune(t, e, s, r) {
|
|
229
|
+
return u(this, null, function* () {
|
|
205
230
|
yield this.invoke({
|
|
206
231
|
op: "skillPrune",
|
|
207
232
|
applicationId: t,
|
|
208
233
|
keep: e,
|
|
209
|
-
busy:
|
|
210
|
-
},
|
|
234
|
+
busy: s
|
|
235
|
+
}, r);
|
|
211
236
|
});
|
|
212
237
|
}
|
|
213
238
|
mkdir(t) {
|
|
214
|
-
return
|
|
239
|
+
return u(this, null, function* () {
|
|
215
240
|
yield this.invoke({
|
|
216
241
|
op: "mkdir",
|
|
217
242
|
path: t
|
|
@@ -219,7 +244,7 @@ class R {
|
|
|
219
244
|
});
|
|
220
245
|
}
|
|
221
246
|
remove(t, e) {
|
|
222
|
-
return
|
|
247
|
+
return u(this, null, function* () {
|
|
223
248
|
yield this.invoke({
|
|
224
249
|
op: "remove",
|
|
225
250
|
path: t,
|
|
@@ -228,7 +253,7 @@ class R {
|
|
|
228
253
|
});
|
|
229
254
|
}
|
|
230
255
|
move(t, e) {
|
|
231
|
-
return
|
|
256
|
+
return u(this, null, function* () {
|
|
232
257
|
yield this.invoke({
|
|
233
258
|
op: "move",
|
|
234
259
|
from: t,
|
|
@@ -236,32 +261,32 @@ class R {
|
|
|
236
261
|
});
|
|
237
262
|
});
|
|
238
263
|
}
|
|
239
|
-
exec(t, e,
|
|
240
|
-
return
|
|
264
|
+
exec(t, e, s) {
|
|
265
|
+
return u(this, null, function* () {
|
|
241
266
|
var h;
|
|
242
|
-
const
|
|
267
|
+
const r = this.begin(y({}, t), e, () => {
|
|
243
268
|
this.send({
|
|
244
|
-
protocol:
|
|
245
|
-
id:
|
|
269
|
+
protocol: A,
|
|
270
|
+
id: r,
|
|
246
271
|
op: "cancel"
|
|
247
272
|
});
|
|
248
273
|
});
|
|
249
|
-
let
|
|
250
|
-
for (; this.calls.has(
|
|
251
|
-
const c = yield this.next(
|
|
274
|
+
let i = "", n = "", l = !1, o = !1;
|
|
275
|
+
for (; this.calls.has(r); ) {
|
|
276
|
+
const c = yield this.next(r);
|
|
252
277
|
if (c.op === "stdout" || c.op === "stderr") {
|
|
253
|
-
const
|
|
254
|
-
|
|
278
|
+
const p = String((h = c.text) != null ? h : "");
|
|
279
|
+
s == null || s(c.op, p), c.op === "stdout" ? (i += p, i.length > m && (l = !0), i = i.slice(-m)) : (n += p, n.length > m && (o = !0), n = n.slice(-m));
|
|
255
280
|
continue;
|
|
256
281
|
}
|
|
257
|
-
if (this.calls.delete(
|
|
282
|
+
if (this.calls.delete(r), c.ok === !1)
|
|
258
283
|
throw f(String(c.name || "NotAllowedError"), String(c.message || "命令失败。"));
|
|
259
|
-
const
|
|
284
|
+
const g = typeof c.logPath == "string" ? c.logPath : void 0, d = c.logTruncated === !0;
|
|
260
285
|
return {
|
|
261
286
|
exitCode: typeof c.exitCode == "number" ? c.exitCode : 1,
|
|
262
287
|
timedOut: c.timedOut === !0,
|
|
263
|
-
stdout:
|
|
264
|
-
stderr:
|
|
288
|
+
stdout: P(i, l, g, d),
|
|
289
|
+
stderr: P(n, o, g, d),
|
|
265
290
|
cwd: typeof c.cwd == "string" ? c.cwd : void 0
|
|
266
291
|
};
|
|
267
292
|
}
|
|
@@ -269,111 +294,111 @@ class R {
|
|
|
269
294
|
});
|
|
270
295
|
}
|
|
271
296
|
invoke(t, e) {
|
|
272
|
-
const
|
|
273
|
-
return this.next(
|
|
274
|
-
this.calls.delete(
|
|
275
|
-
const
|
|
276
|
-
if (
|
|
277
|
-
throw f(String(
|
|
278
|
-
return
|
|
297
|
+
const s = this.begin(t, e);
|
|
298
|
+
return this.next(s).then((r) => {
|
|
299
|
+
this.calls.delete(s);
|
|
300
|
+
const i = r;
|
|
301
|
+
if (i.ok === !1)
|
|
302
|
+
throw f(String(i.name || "NotAllowedError"), String(i.message || "请求失败。"));
|
|
303
|
+
return i;
|
|
279
304
|
});
|
|
280
305
|
}
|
|
281
|
-
begin(t, e,
|
|
306
|
+
begin(t, e, s) {
|
|
282
307
|
if (!this.ready)
|
|
283
308
|
throw f("NotAllowedError", this.unavailableMessage());
|
|
284
309
|
if (e != null && e.aborted)
|
|
285
310
|
throw f("AbortError");
|
|
286
|
-
const
|
|
287
|
-
let
|
|
311
|
+
const r = `sbx-${++this.seq}`;
|
|
312
|
+
let i = () => {
|
|
288
313
|
};
|
|
289
314
|
const n = {
|
|
290
315
|
messages: [],
|
|
291
316
|
waiters: [],
|
|
292
|
-
reject: (
|
|
317
|
+
reject: (o) => i(o)
|
|
293
318
|
};
|
|
294
|
-
this.calls.set(
|
|
319
|
+
this.calls.set(r, n);
|
|
295
320
|
const l = () => {
|
|
296
|
-
|
|
321
|
+
s == null || s(), n.reject(f("AbortError"));
|
|
297
322
|
};
|
|
298
323
|
return e == null || e.addEventListener("abort", l, {
|
|
299
324
|
once: !0
|
|
300
|
-
}),
|
|
301
|
-
e == null || e.removeEventListener("abort", l), this.calls.delete(
|
|
325
|
+
}), i = (o) => {
|
|
326
|
+
e == null || e.removeEventListener("abort", l), this.calls.delete(r);
|
|
302
327
|
const h = n.waiters.shift();
|
|
303
|
-
h && h(Promise.reject(
|
|
328
|
+
h && h(Promise.reject(o));
|
|
304
329
|
}, this.send(y({
|
|
305
|
-
protocol:
|
|
306
|
-
id:
|
|
307
|
-
}, t)),
|
|
330
|
+
protocol: A,
|
|
331
|
+
id: r
|
|
332
|
+
}, t)), r;
|
|
308
333
|
}
|
|
309
334
|
next(t) {
|
|
310
335
|
const e = this.calls.get(t);
|
|
311
336
|
if (!e)
|
|
312
337
|
return Promise.reject(f("AbortError", k));
|
|
313
|
-
const
|
|
314
|
-
return
|
|
315
|
-
e.waiters.push(
|
|
316
|
-
this.calls.delete(t),
|
|
338
|
+
const s = e.messages.shift();
|
|
339
|
+
return s !== void 0 ? Promise.resolve(s) : new Promise((r, i) => {
|
|
340
|
+
e.waiters.push(r), e.reject = (n) => {
|
|
341
|
+
this.calls.delete(t), i(n);
|
|
317
342
|
};
|
|
318
343
|
});
|
|
319
344
|
}
|
|
320
345
|
send(t) {
|
|
321
|
-
var
|
|
346
|
+
var s;
|
|
322
347
|
const e = () => {
|
|
323
|
-
var
|
|
324
|
-
const
|
|
325
|
-
(
|
|
348
|
+
var i;
|
|
349
|
+
const r = t instanceof Uint8Array ? t : JSON.stringify(t);
|
|
350
|
+
(i = this.socket) == null || i.send(r);
|
|
326
351
|
};
|
|
327
|
-
this.authed && ((
|
|
352
|
+
this.authed && ((s = this.socket) == null ? void 0 : s.readyState) === 1 ? e() : this.outgoing.push(e);
|
|
328
353
|
}
|
|
329
354
|
connect(t, e) {
|
|
330
|
-
const
|
|
331
|
-
this.socket =
|
|
332
|
-
|
|
333
|
-
protocol:
|
|
355
|
+
const s = ++this.generation, r = this.openSocket(t);
|
|
356
|
+
this.socket = r, this.authed = !1, r.binaryType = "arraybuffer", r.onopen = () => {
|
|
357
|
+
s === this.generation && r.send(JSON.stringify({
|
|
358
|
+
protocol: A,
|
|
334
359
|
op: "auth",
|
|
335
360
|
token: e
|
|
336
361
|
}));
|
|
337
|
-
},
|
|
338
|
-
|
|
339
|
-
},
|
|
340
|
-
|
|
341
|
-
},
|
|
362
|
+
}, r.onmessage = (i) => {
|
|
363
|
+
s === this.generation && this.onFrame(i.data);
|
|
364
|
+
}, r.onclose = () => {
|
|
365
|
+
s === this.generation && (this.authed = !1, this.failAll(f("AbortError", k)));
|
|
366
|
+
}, r.onerror = () => {
|
|
342
367
|
};
|
|
343
368
|
}
|
|
344
369
|
onFrame(t) {
|
|
345
370
|
const e = b(t);
|
|
346
371
|
if (e) {
|
|
347
|
-
const
|
|
348
|
-
this.push(
|
|
372
|
+
const r = E(e);
|
|
373
|
+
this.push(r.id, e);
|
|
349
374
|
return;
|
|
350
375
|
}
|
|
351
|
-
let
|
|
376
|
+
let s;
|
|
352
377
|
try {
|
|
353
|
-
|
|
354
|
-
} catch (
|
|
378
|
+
s = JSON.parse(String(t));
|
|
379
|
+
} catch (r) {
|
|
355
380
|
return;
|
|
356
381
|
}
|
|
357
|
-
if (
|
|
358
|
-
if (
|
|
382
|
+
if (s.op === "auth") {
|
|
383
|
+
if (s.ok === !0) {
|
|
359
384
|
this.authed = !0;
|
|
360
|
-
const
|
|
361
|
-
this.outgoing = [],
|
|
385
|
+
const r = this.outgoing;
|
|
386
|
+
this.outgoing = [], r.forEach((i) => i());
|
|
362
387
|
}
|
|
363
388
|
return;
|
|
364
389
|
}
|
|
365
|
-
if (
|
|
390
|
+
if (s.op === "bye") {
|
|
366
391
|
this.failAll(f("AbortError", k)), this.stop();
|
|
367
392
|
return;
|
|
368
393
|
}
|
|
369
|
-
typeof
|
|
394
|
+
typeof s.id == "string" && this.push(s.id, s);
|
|
370
395
|
}
|
|
371
396
|
push(t, e) {
|
|
372
|
-
const
|
|
373
|
-
if (!
|
|
397
|
+
const s = this.calls.get(t);
|
|
398
|
+
if (!s)
|
|
374
399
|
return;
|
|
375
|
-
const
|
|
376
|
-
|
|
400
|
+
const r = s.waiters.shift();
|
|
401
|
+
r ? r(e) : s.messages.push(e);
|
|
377
402
|
}
|
|
378
403
|
failAll(t) {
|
|
379
404
|
for (const e of this.calls.values())
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
const g = {
|
|
2
|
+
png: "image/png",
|
|
3
|
+
jpg: "image/jpeg",
|
|
4
|
+
jpeg: "image/jpeg",
|
|
5
|
+
gif: "image/gif",
|
|
6
|
+
webp: "image/webp",
|
|
7
|
+
bmp: "image/bmp",
|
|
8
|
+
avif: "image/avif",
|
|
9
|
+
ico: "image/x-icon",
|
|
10
|
+
svg: "image/svg+xml",
|
|
11
|
+
mp3: "audio/mpeg",
|
|
12
|
+
wav: "audio/wav",
|
|
13
|
+
ogg: "audio/ogg",
|
|
14
|
+
m4a: "audio/mp4",
|
|
15
|
+
aac: "audio/aac",
|
|
16
|
+
flac: "audio/flac",
|
|
17
|
+
mp4: "video/mp4",
|
|
18
|
+
webm: "video/webm",
|
|
19
|
+
mov: "video/quicktime",
|
|
20
|
+
m4v: "video/mp4",
|
|
21
|
+
ogv: "video/ogg",
|
|
22
|
+
pdf: "application/pdf"
|
|
23
|
+
}, m = "只能预览图片、音视频和 PDF。";
|
|
24
|
+
function p(o) {
|
|
25
|
+
var a;
|
|
26
|
+
const i = (a = o.split("/").pop()) != null ? a : "", e = i.lastIndexOf(".");
|
|
27
|
+
if (!(e <= 0))
|
|
28
|
+
return g[i.slice(e + 1).toLowerCase()];
|
|
29
|
+
}
|
|
30
|
+
export {
|
|
31
|
+
m as PREVIEW_TYPE_MESSAGE,
|
|
32
|
+
p as mediaTypeOf
|
|
33
|
+
};
|