@glodon-aiot/bot-client-sdk 3.26.0-alpha.18 → 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.
@@ -1,36 +1,36 @@
1
- var M = Object.defineProperty, O = Object.defineProperties;
2
- var _ = Object.getOwnPropertyDescriptors;
1
+ var B = Object.defineProperty, M = Object.defineProperties;
2
+ var U = Object.getOwnPropertyDescriptors;
3
3
  var v = Object.getOwnPropertySymbols;
4
- var C = Object.prototype.hasOwnProperty, T = Object.prototype.propertyIsEnumerable;
5
- var A = (a, t, e) => t in a ? M(a, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : a[t] = e, y = (a, t) => {
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
- C.call(t, e) && A(a, e, t[e]);
7
+ _.call(t, e) && S(a, e, t[e]);
8
8
  if (v)
9
9
  for (var e of v(t))
10
- T.call(t, e) && A(a, e, t[e]);
10
+ C.call(t, e) && S(a, e, t[e]);
11
11
  return a;
12
- }, x = (a, t) => O(a, _(t));
13
- var m = (a, t, e) => (A(a, typeof t != "symbol" ? t + "" : t, e), e);
14
- var p = (a, t, e) => new Promise((r, s) => {
15
- var o = (i) => {
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(i));
17
+ l(e.next(o));
18
18
  } catch (h) {
19
- s(h);
19
+ r(h);
20
20
  }
21
- }, n = (i) => {
21
+ }, n = (o) => {
22
22
  try {
23
- l(e.throw(i));
23
+ l(e.throw(o));
24
24
  } catch (h) {
25
- s(h);
25
+ r(h);
26
26
  }
27
- }, l = (i) => i.done ? r(i.value) : Promise.resolve(i.value).then(o, n);
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 w } from "../../builtinTools/command.mjs";
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 S, SANDBOX_MAX_FILE_BYTES as j } from "./protocol.mjs";
33
- import { decodeBinaryFrame as E, MAX_BINARY_PAYLOAD as N, encodeBinaryFrame as P } from "./sandboxFrames.mjs";
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 B(a, t, e, r) {
42
- const s = a.length > w ? a.slice(a.length - w) : a;
43
- if (!t && !e && !r && a.length <= w)
44
- return s;
45
- let o = `
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 && (o += `,完整输出见 ${e}`), r && (o += ",日志已截断"), s + o;
47
+ return e && (i += `,完整输出见 ${e}`), s && (i += ",日志已截断"), r + i;
48
48
  }
49
49
  class R {
50
50
  constructor(t = (e) => new WebSocket(e)) {
51
- m(this, "notice");
52
- m(this, "socket");
53
- m(this, "generation", 0);
54
- m(this, "authed", !1);
55
- m(this, "seq", 0);
56
- m(this, "calls", /* @__PURE__ */ new Map());
57
- m(this, "outgoing", []);
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 === S && !!(t.url && t.token);
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, r, s;
66
- return ((t = this.notice) == null ? void 0 : t.state) === "starting" ? "沙箱正在启动。" : (e = this.notice) != null && e.message ? this.notice.message : ((r = this.notice) == null ? void 0 : r.state) === "exited" || ((s = this.notice) == null ? void 0 : s.state) === "failed" ? k : "沙箱没有就绪。";
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 p(this, null, function* () {
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 p(this, null, function* () {
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(o) {
93
- return p(this, arguments, function* (t, e = 0, r = j, s) {
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: r
99
- }, s), l = [];
100
- let i;
101
- for (; !i; ) {
102
- const d = yield this.next(n), g = b(d);
103
- if (g) {
104
- l.push(E(g).payload);
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
- i = d;
132
+ o = d;
108
133
  }
109
- if (this.calls.delete(n), i.ok === !1)
110
- throw f(String(i.name || "NotAllowedError"), String(i.message || "读取失败。"));
111
- const h = l.reduce((d, g) => d + g.length, 0), c = new Uint8Array(h);
112
- let u = 0;
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, u), u += d.length;
139
+ c.set(d, g), g += d.length;
115
140
  }), c;
116
141
  });
117
142
  }
118
- write(t, e, r, s) {
119
- return p(this, null, function* () {
120
- const o = this.begin({
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: r
125
- }, s);
149
+ createDirectories: s
150
+ }, r);
126
151
  let n = 0;
127
152
  for (; n < e.length; ) {
128
- const i = e.subarray(n, n + N), h = n + i.length;
129
- this.send(P(o, n, h === e.length, i)), n = h;
130
- const u = yield this.next(o);
131
- if (u.ok === !1)
132
- throw this.calls.delete(o), f(String(u.name || "NotAllowedError"), String(u.message || "写入失败。"));
133
- if (u.op !== "ack" && u.ok === !0) {
134
- this.calls.delete(o);
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(o);
139
- if (this.calls.delete(o), l.ok === !1)
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 p(this, null, function* () {
145
- const r = yield this.invoke({
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(r.skills) ? r.skills : [];
174
+ return Array.isArray(s.skills) ? s.skills : [];
150
175
  });
151
176
  }
152
- skillRead(t, e, r, s, o) {
153
- return p(this, null, function* () {
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: r,
159
- path: s
160
- }, o), l = [];
161
- let i;
162
- for (; !i; ) {
163
- const d = yield this.next(n), g = b(d);
164
- if (g) {
165
- l.push(E(g).payload);
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
- i = d;
193
+ o = d;
169
194
  }
170
- if (this.calls.delete(n), i.ok === !1)
171
- throw f(String(i.name || "NotAllowedError"), String(i.message || "读取失败。"));
172
- const h = l.reduce((d, g) => d + g.length, 0), c = new Uint8Array(h);
173
- let u = 0;
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, u), u += d.length;
200
+ c.set(d, g), g += d.length;
176
201
  }), c;
177
202
  });
178
203
  }
179
- installSkill(t, e, r) {
180
- return p(this, null, function* () {
181
- const s = this.begin(x(y({
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
- }), r);
186
- let o = 0;
187
- for (; o < e.length; ) {
188
- const l = e.subarray(o, o + N), i = o + l.length;
189
- this.send(P(s, o, i === e.length, l)), o = i;
190
- const h = yield this.next(s);
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(s), f(String(h.name || "NotAllowedError"), String(h.message || "安装失败。"));
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(s);
219
+ this.calls.delete(r);
195
220
  return;
196
221
  }
197
222
  }
198
- const n = yield this.next(s);
199
- if (this.calls.delete(s), n.ok === !1)
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, r, s) {
204
- return p(this, null, function* () {
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: r
210
- }, s);
234
+ busy: s
235
+ }, r);
211
236
  });
212
237
  }
213
238
  mkdir(t) {
214
- return p(this, null, function* () {
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 p(this, null, function* () {
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 p(this, null, function* () {
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, r) {
240
- return p(this, null, function* () {
264
+ exec(t, e, s) {
265
+ return u(this, null, function* () {
241
266
  var h;
242
- const s = this.begin(y({}, t), e, () => {
267
+ const r = this.begin(y({}, t), e, () => {
243
268
  this.send({
244
- protocol: S,
245
- id: s,
269
+ protocol: A,
270
+ id: r,
246
271
  op: "cancel"
247
272
  });
248
273
  });
249
- let o = "", n = "", l = !1, i = !1;
250
- for (; this.calls.has(s); ) {
251
- const c = yield this.next(s);
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 g = String((h = c.text) != null ? h : "");
254
- r == null || r(c.op, g), c.op === "stdout" ? (o += g, o.length > w && (l = !0), o = o.slice(-w)) : (n += g, n.length > w && (i = !0), n = n.slice(-w));
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(s), c.ok === !1)
282
+ if (this.calls.delete(r), c.ok === !1)
258
283
  throw f(String(c.name || "NotAllowedError"), String(c.message || "命令失败。"));
259
- const u = typeof c.logPath == "string" ? c.logPath : void 0, d = c.logTruncated === !0;
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: B(o, l, u, d),
264
- stderr: B(n, i, u, d),
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 r = this.begin(t, e);
273
- return this.next(r).then((s) => {
274
- this.calls.delete(r);
275
- const o = s;
276
- if (o.ok === !1)
277
- throw f(String(o.name || "NotAllowedError"), String(o.message || "请求失败。"));
278
- return o;
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, r) {
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 s = `sbx-${++this.seq}`;
287
- let o = () => {
311
+ const r = `sbx-${++this.seq}`;
312
+ let i = () => {
288
313
  };
289
314
  const n = {
290
315
  messages: [],
291
316
  waiters: [],
292
- reject: (i) => o(i)
317
+ reject: (o) => i(o)
293
318
  };
294
- this.calls.set(s, n);
319
+ this.calls.set(r, n);
295
320
  const l = () => {
296
- r == null || r(), n.reject(f("AbortError"));
321
+ s == null || s(), n.reject(f("AbortError"));
297
322
  };
298
323
  return e == null || e.addEventListener("abort", l, {
299
324
  once: !0
300
- }), o = (i) => {
301
- e == null || e.removeEventListener("abort", l), this.calls.delete(s);
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(i));
328
+ h && h(Promise.reject(o));
304
329
  }, this.send(y({
305
- protocol: S,
306
- id: s
307
- }, t)), s;
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 r = e.messages.shift();
314
- return r !== void 0 ? Promise.resolve(r) : new Promise((s, o) => {
315
- e.waiters.push(s), e.reject = (n) => {
316
- this.calls.delete(t), o(n);
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 r;
346
+ var s;
322
347
  const e = () => {
323
- var o;
324
- const s = t instanceof Uint8Array ? t : JSON.stringify(t);
325
- (o = this.socket) == null || o.send(s);
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 && ((r = this.socket) == null ? void 0 : r.readyState) === 1 ? e() : this.outgoing.push(e);
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 r = ++this.generation, s = this.openSocket(t);
331
- this.socket = s, this.authed = !1, s.binaryType = "arraybuffer", s.onopen = () => {
332
- r === this.generation && s.send(JSON.stringify({
333
- protocol: S,
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
- }, s.onmessage = (o) => {
338
- r === this.generation && this.onFrame(o.data);
339
- }, s.onclose = () => {
340
- r === this.generation && (this.authed = !1, this.failAll(f("AbortError", k)));
341
- }, s.onerror = () => {
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 s = E(e);
348
- this.push(s.id, e);
372
+ const r = E(e);
373
+ this.push(r.id, e);
349
374
  return;
350
375
  }
351
- let r;
376
+ let s;
352
377
  try {
353
- r = JSON.parse(String(t));
354
- } catch (s) {
378
+ s = JSON.parse(String(t));
379
+ } catch (r) {
355
380
  return;
356
381
  }
357
- if (r.op === "auth") {
358
- if (r.ok === !0) {
382
+ if (s.op === "auth") {
383
+ if (s.ok === !0) {
359
384
  this.authed = !0;
360
- const s = this.outgoing;
361
- this.outgoing = [], s.forEach((o) => o());
385
+ const r = this.outgoing;
386
+ this.outgoing = [], r.forEach((i) => i());
362
387
  }
363
388
  return;
364
389
  }
365
- if (r.op === "bye") {
390
+ if (s.op === "bye") {
366
391
  this.failAll(f("AbortError", k)), this.stop();
367
392
  return;
368
393
  }
369
- typeof r.id == "string" && this.push(r.id, r);
394
+ typeof s.id == "string" && this.push(s.id, s);
370
395
  }
371
396
  push(t, e) {
372
- const r = this.calls.get(t);
373
- if (!r)
397
+ const s = this.calls.get(t);
398
+ if (!s)
374
399
  return;
375
- const s = r.waiters.shift();
376
- s ? s(e) : r.messages.push(e);
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
+ };