@aiquants/markdown-explorer 0.22.0 → 0.24.0
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/CHANGELOG.md +143 -0
- package/README.md +63 -17
- package/dist/{EditSurface-BesNcSQj.cjs → EditSurface-CRc4g0Qa.cjs} +5 -5
- package/dist/{EditSurface-DNjI8pV3.js → EditSurface-CcWEczj3.js} +333 -336
- package/dist/{ExplorerSplit-GUdzpDPg.js → ExplorerSplit-97SeIAOS.js} +81 -81
- package/dist/{ExplorerSplit-B4oNvydP.cjs → ExplorerSplit-ByxxXlgs.cjs} +1 -1
- package/dist/{MultiLayout-DtKChQ_s.cjs → MultiLayout-B_yMVDt_.cjs} +1 -1
- package/dist/{MultiLayout-BJ-s6AaD.js → MultiLayout-CnbuAlxd.js} +4 -4
- package/dist/{NativeScrollBar-D10fsk-7.js → NativeScrollBar-BXdaM3EA.js} +1 -1
- package/dist/{NativeScrollBar-DJKlPWvD.cjs → NativeScrollBar-D4a7fBOS.cjs} +1 -1
- package/dist/{TreeLayout-DQT5p2vI.js → TreeLayout-BIQBKAkV.js} +3 -3
- package/dist/{TreeLayout-C1mTmoPp.cjs → TreeLayout-C6QDpEBS.cjs} +1 -1
- package/dist/core/config.d.cts +13 -0
- package/dist/core/config.d.ts +13 -0
- package/dist/core/contracts.d.cts +29 -4
- package/dist/core/contracts.d.ts +29 -4
- package/dist/core/labels.d.cts +21 -0
- package/dist/core/labels.d.ts +21 -0
- package/dist/core/textEncoding.d.cts +4 -0
- package/dist/core/textEncoding.d.ts +4 -0
- package/dist/{dataRoute-CObbjNxG.js → dataRoute-BEvesOvN.js} +108 -99
- package/dist/dataRoute-Cv7fgCW7.cjs +1 -0
- package/dist/index-BwTVYkTR.cjs +13 -0
- package/dist/index-CeZDCyEl.js +4088 -0
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +24 -23
- package/dist/location-CasigkBk.cjs +1 -0
- package/dist/location-gXXmC7CQ.js +643 -0
- package/dist/{merge-DauzoA2W.js → merge-DqjUgcV_.js} +1 -1
- package/dist/{merge-CTkzzHtn.cjs → merge-QLktbpZY.cjs} +1 -1
- package/dist/{sanitizePolicy-gEXeavb-.cjs → sanitizePolicy-CZwOaJ92.cjs} +1 -1
- package/dist/{sanitizePolicy-BWQtWhsL.js → sanitizePolicy-gVKBhabq.js} +1 -1
- package/dist/sanitizeWorker.cjs +1 -1
- package/dist/sanitizeWorker.js +1 -1
- package/dist/server/fileSystemSource.d.cts +1 -0
- package/dist/server/fileSystemSource.d.ts +1 -0
- package/dist/server/ports.d.cts +9 -1
- package/dist/server/ports.d.ts +9 -1
- package/dist/server.cjs +1 -1
- package/dist/server.d.cts +1 -0
- package/dist/server.d.ts +1 -0
- package/dist/server.js +852 -834
- package/dist/styles/markdown-explorer.css +1 -1
- package/dist/{useSplitPersistence-Cc4tDxB4.js → useSplitPersistence-BPNjvuJi.js} +1 -1
- package/dist/{useSplitPersistence-Ba-v64n-.cjs → useSplitPersistence-Bmpb2prR.cjs} +1 -1
- package/docs/behavior/dom-hooks.md +13 -6
- package/docs/behavior/layout.md +22 -8
- package/docs/behavior/localization.md +9 -5
- package/docs/behavior/security.md +6 -4
- package/docs/behavior/url-contract.md +2 -2
- package/package.json +5 -5
- package/dist/dataRoute-BONacTPi.cjs +0 -1
- package/dist/index-0pnuyLUO.js +0 -3662
- package/dist/index-T98wklgM.cjs +0 -13
- package/dist/location-B-m9scLf.js +0 -499
- package/dist/location-BVEN_Ihk.cjs +0 -1
package/dist/server.js
CHANGED
|
@@ -1,21 +1,22 @@
|
|
|
1
|
-
import { b as
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
12
|
-
import {
|
|
13
|
-
import {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
1
|
+
import { b as Ot, c as sr, f as xe, g as ir, h as ar, s as cr, j as ur, k as dr, l as lr, E as Rt, m as ge, r as fr, n as mr, i as re, o as pr, p as wr, q as hr, t as vt, u as yr, v as gr, w as Ce, x as Er, y as br, z as Tr, A as ce, B as ee, e as Ge, C as kr, D as Sr } from "./dataRoute-BEvesOvN.js";
|
|
2
|
+
import { F as ms, M as ps, G as ws } from "./dataRoute-BEvesOvN.js";
|
|
3
|
+
import { f as $e, w as xr, g as Or, r as Rr, i as vr, h as _r, p as Ar, j as Nr, k as Ir, l as Pr, N as Mr } from "./location-gXXmC7CQ.js";
|
|
4
|
+
import { m as ys } from "./location-gXXmC7CQ.js";
|
|
5
|
+
import { createHash as Lr, createHmac as $r } from "node:crypto";
|
|
6
|
+
import { createLinkCardHandler as jr } from "@aiquants/markdown/server";
|
|
7
|
+
import { crossOriginRefusal as _t, NO_CROSS_ORIGIN_NAVIGATION as At } from "@aiquants/request-isolation";
|
|
8
|
+
import { data as Ye, redirect as zr } from "react-router";
|
|
9
|
+
import { existsSync as Dr, statSync as Cr, realpathSync as Hr, constants as we } from "node:fs";
|
|
10
|
+
import { extname as Br, isAbsolute as We, relative as Ke, sep as Ve, join as Ze, resolve as Fr } from "node:path";
|
|
11
|
+
import { fileURLToPath as _e } from "node:url";
|
|
12
|
+
import { Worker as Ur } from "node:worker_threads";
|
|
13
|
+
import { open as Nt, lstat as It, realpath as Xr, readdir as Jr } from "node:fs/promises";
|
|
14
|
+
import { Readable as Gr } from "node:stream";
|
|
15
|
+
const Qe = Object.freeze({ kind: "anonymous" }), cs = Object.freeze({
|
|
16
|
+
authenticate: async () => ({ status: "signed-in", principal: Qe }),
|
|
17
|
+
principalKey: () => Qe.kind,
|
|
17
18
|
signedOutPage: (e, t) => new Response(null, { status: 401, headers: t })
|
|
18
|
-
}),
|
|
19
|
+
}), Yr = "application/octet-stream", Pt = "application/pdf", Wr = /* @__PURE__ */ new Set([
|
|
19
20
|
"image/png",
|
|
20
21
|
"image/apng",
|
|
21
22
|
"image/jpeg",
|
|
@@ -41,566 +42,575 @@ const Ke = Object.freeze({ kind: "anonymous" }), ts = Object.freeze({
|
|
|
41
42
|
"video/webm",
|
|
42
43
|
"video/ogg",
|
|
43
44
|
"video/quicktime",
|
|
44
|
-
|
|
45
|
-
]),
|
|
45
|
+
Pt
|
|
46
|
+
]), Mt = "default-src 'none'; media-src 'self'; style-src 'unsafe-inline'", Lt = `${Mt}; sandbox`, Kr = `${Mt}; sandbox allow-same-origin`, qe = /^[!#$%&'*+\-.^_`|~0-9A-Za-z]+$/u, Vr = /^[\t\n\r ]+|[\t\n\r ]+$/gu, je = /^[\t ]+|[\t ]+$/gu, Zr = (e) => {
|
|
46
47
|
const t = [];
|
|
47
48
|
let r = "", n = 0;
|
|
48
49
|
for (; ; ) {
|
|
49
50
|
for (; n < e.length && e[n] !== '"' && e[n] !== ","; )
|
|
50
51
|
r += e[n], n += 1;
|
|
51
52
|
if (n < e.length && e[n] === '"') {
|
|
52
|
-
const
|
|
53
|
+
const a = n;
|
|
53
54
|
for (n += 1; n < e.length && e[n] !== '"'; )
|
|
54
55
|
n += e[n] === "\\" ? 2 : 1;
|
|
55
|
-
if (n = Math.min(n + 1, e.length), r += e.slice(
|
|
56
|
+
if (n = Math.min(n + 1, e.length), r += e.slice(a, n), n < e.length) continue;
|
|
56
57
|
}
|
|
57
|
-
if (t.push(r.replace(
|
|
58
|
+
if (t.push(r.replace(je, "")), r = "", n >= e.length) return t;
|
|
58
59
|
n += 1;
|
|
59
60
|
}
|
|
60
|
-
},
|
|
61
|
-
const t = e.replace(
|
|
61
|
+
}, Qr = (e) => {
|
|
62
|
+
const t = e.replace(Vr, ""), r = t.indexOf("/");
|
|
62
63
|
if (r < 0) return null;
|
|
63
|
-
const n = t.slice(0, r),
|
|
64
|
-
return
|
|
65
|
-
},
|
|
64
|
+
const n = t.slice(0, r), a = t.indexOf(";", r + 1), s = t.slice(r + 1, a < 0 ? t.length : a).replace(/[\t\n\r ]+$/u, "");
|
|
65
|
+
return qe.test(n) && qe.test(s) ? `${n}/${s}`.toLowerCase() : null;
|
|
66
|
+
}, qr = (e) => {
|
|
66
67
|
let t = null;
|
|
67
|
-
for (const r of
|
|
68
|
-
const n =
|
|
68
|
+
for (const r of Zr(e)) {
|
|
69
|
+
const n = Qr(r);
|
|
69
70
|
n !== null && n !== "*/*" && (t = n);
|
|
70
71
|
}
|
|
71
72
|
return t;
|
|
72
|
-
},
|
|
73
|
+
}, en = /['()*]/gu, $t = (e) => encodeURIComponent(e).replace(en, (t) => `%${t.charCodeAt(0).toString(16).toUpperCase()}`), tn = Object.freeze({
|
|
73
74
|
"Cache-Control": "private, max-age=60, stale-while-revalidate=600, no-transform",
|
|
74
75
|
Vary: "Cookie"
|
|
75
|
-
}),
|
|
76
|
-
const r =
|
|
76
|
+
}), rn = (e, t) => {
|
|
77
|
+
const r = qr(e), n = r !== null && Wr.has(r), a = n && (r.startsWith("audio/") || r.startsWith("video/"));
|
|
77
78
|
return {
|
|
78
|
-
contentType: r === null ?
|
|
79
|
+
contentType: r === null ? Yr : r,
|
|
79
80
|
inline: n,
|
|
80
81
|
headers: {
|
|
81
82
|
"X-Content-Type-Options": "nosniff",
|
|
82
|
-
"Content-Disposition": `${n ? "inline" : "attachment"}; filename*=UTF-8''${
|
|
83
|
-
...r ===
|
|
83
|
+
"Content-Disposition": `${n ? "inline" : "attachment"}; filename*=UTF-8''${$t(t)}`,
|
|
84
|
+
...r === Pt ? {} : { "Content-Security-Policy": a ? Kr : Lt },
|
|
84
85
|
"Cross-Origin-Resource-Policy": "same-origin"
|
|
85
86
|
}
|
|
86
87
|
};
|
|
87
|
-
},
|
|
88
|
-
contentType:
|
|
88
|
+
}, nn = "text/plain; charset=utf-8", on = (e) => ({
|
|
89
|
+
contentType: nn,
|
|
89
90
|
inline: !0,
|
|
90
91
|
headers: {
|
|
91
92
|
"X-Content-Type-Options": "nosniff",
|
|
92
|
-
"Content-Disposition": `inline; filename*=UTF-8''${
|
|
93
|
-
"Content-Security-Policy":
|
|
93
|
+
"Content-Disposition": `inline; filename*=UTF-8''${$t(e)}`,
|
|
94
|
+
"Content-Security-Policy": Lt,
|
|
94
95
|
"Cross-Origin-Resource-Policy": "same-origin"
|
|
95
96
|
}
|
|
96
|
-
}),
|
|
97
|
+
}), sn = /^bytes=(?:(\d+)-(\d*)|-(\d+))$/iu, be = Object.freeze({ kind: "whole" }), et = Object.freeze({ kind: "unsatisfiable" }), an = (e, t, r) => {
|
|
97
98
|
const n = e.get("Range");
|
|
98
|
-
if (n === null) return
|
|
99
|
-
const
|
|
100
|
-
if (
|
|
101
|
-
const
|
|
102
|
-
if (
|
|
103
|
-
const [, c, m,
|
|
104
|
-
if (
|
|
105
|
-
const y = Number(
|
|
106
|
-
if (y === 0) return
|
|
107
|
-
const
|
|
108
|
-
return { kind: "partial", range: { offset:
|
|
99
|
+
if (n === null) return be;
|
|
100
|
+
const a = e.get("If-Range");
|
|
101
|
+
if (a !== null && a !== r) return be;
|
|
102
|
+
const s = sn.exec(n);
|
|
103
|
+
if (s === null) return be;
|
|
104
|
+
const [, c, m, f] = s;
|
|
105
|
+
if (f !== void 0) {
|
|
106
|
+
const y = Number(f);
|
|
107
|
+
if (y === 0) return et;
|
|
108
|
+
const T = Math.max(0, t - y);
|
|
109
|
+
return { kind: "partial", range: { offset: T, length: t - T } };
|
|
109
110
|
}
|
|
110
|
-
const
|
|
111
|
-
return
|
|
112
|
-
},
|
|
111
|
+
const S = Number(c), h = m === "" ? Number.POSITIVE_INFINITY : Number(m);
|
|
112
|
+
return h < S ? be : S >= t ? et : { kind: "partial", range: { offset: S, length: Math.min(h, t - 1) - S + 1 } };
|
|
113
|
+
}, tt = "W/", cn = (e) => {
|
|
113
114
|
const t = [];
|
|
114
115
|
let r = 0, n = !1;
|
|
115
|
-
for (let
|
|
116
|
-
e[
|
|
117
|
-
return t.push(e.slice(r).replace(
|
|
118
|
-
},
|
|
116
|
+
for (let a = 0; a < e.length; a += 1)
|
|
117
|
+
e[a] === '"' ? n = !n : e[a] === "," && !n && (t.push(e.slice(r, a).replace(je, "")), r = a + 1);
|
|
118
|
+
return t.push(e.slice(r).replace(je, "")), t;
|
|
119
|
+
}, rt = (e) => e.startsWith(tt) ? e.slice(tt.length) : e, un = (e, t) => {
|
|
119
120
|
if (e === null) return !1;
|
|
120
|
-
const r =
|
|
121
|
+
const r = cn(e);
|
|
121
122
|
if (r.length === 1 && r[0] === "*") return !0;
|
|
122
|
-
const n =
|
|
123
|
-
return r.some((
|
|
124
|
-
},
|
|
123
|
+
const n = rt(t);
|
|
124
|
+
return r.some((a) => rt(a) === n);
|
|
125
|
+
}, dn = (e, t) => {
|
|
125
126
|
let r = t;
|
|
126
127
|
return e.pipeThrough(
|
|
127
128
|
new TransformStream({
|
|
128
|
-
transform: (n,
|
|
129
|
-
const
|
|
130
|
-
r -=
|
|
129
|
+
transform: (n, a) => {
|
|
130
|
+
const s = n.byteLength > r ? n.subarray(0, r) : n;
|
|
131
|
+
r -= s.byteLength, a.enqueue(s), r === 0 && a.terminate();
|
|
131
132
|
},
|
|
132
133
|
flush: (n) => {
|
|
133
134
|
r > 0 && n.error(new RangeError("[markdown-explorer] the asset ended before its declared length"));
|
|
134
135
|
}
|
|
135
136
|
})
|
|
136
137
|
);
|
|
137
|
-
},
|
|
138
|
+
}, Ae = async (e, t, r, n, a) => {
|
|
138
139
|
if (n !== null && r.set("Content-Length", String(n)), e.method.toUpperCase() === "HEAD") return new Response(null, { status: t, headers: r });
|
|
139
|
-
const
|
|
140
|
-
return new Response(n === null ?
|
|
141
|
-
},
|
|
140
|
+
const s = await a();
|
|
141
|
+
return new Response(n === null ? s : dn(s, n), { status: t, headers: r });
|
|
142
|
+
}, ln = (e, t) => {
|
|
142
143
|
const r = new Headers(e);
|
|
143
|
-
for (const [n,
|
|
144
|
+
for (const [n, a] of Object.entries({ "Accept-Ranges": "bytes", "Content-Range": `bytes */${t}`, "Cache-Control": "private, no-store", "X-Content-Type-Options": "nosniff" })) r.set(n, a);
|
|
144
145
|
return new Response(null, { status: 416, headers: r });
|
|
145
|
-
},
|
|
146
|
-
const
|
|
147
|
-
for (const [
|
|
148
|
-
if (
|
|
149
|
-
if (c.set("Content-Type",
|
|
146
|
+
}, fn = async (e, t, r, n) => {
|
|
147
|
+
const a = `"${t.version}"`, s = n === "text" ? on(t.name) : rn(t.contentType, t.name), c = new Headers(r);
|
|
148
|
+
for (const [S, h] of Object.entries({ ...s.headers, ...tn, ETag: a })) c.set(S, h);
|
|
149
|
+
if (un(e.headers.get("If-None-Match"), a)) return new Response(null, { status: 304, headers: c });
|
|
150
|
+
if (c.set("Content-Type", s.contentType), t.size === null) return Ae(e, 200, c, null, () => t.open(null));
|
|
150
151
|
if (t.size === 0)
|
|
151
152
|
return c.set("Content-Length", "0"), new Response(null, { status: 200, headers: c });
|
|
152
153
|
c.set("Accept-Ranges", "bytes");
|
|
153
|
-
const m =
|
|
154
|
-
if (m.kind === "unsatisfiable") return
|
|
155
|
-
if (m.kind === "whole") return
|
|
156
|
-
const { range:
|
|
157
|
-
return c.set("Content-Range", `bytes ${
|
|
158
|
-
},
|
|
154
|
+
const m = an(e.headers, t.size, a);
|
|
155
|
+
if (m.kind === "unsatisfiable") return ln(r, t.size);
|
|
156
|
+
if (m.kind === "whole") return Ae(e, 200, c, t.size, () => t.open(null));
|
|
157
|
+
const { range: f } = m;
|
|
158
|
+
return c.set("Content-Range", `bytes ${f.offset}-${f.offset + f.length - 1}/${t.size}`), Ae(e, 206, c, f.length, () => t.open(f));
|
|
159
|
+
}, mn = Object.freeze({
|
|
159
160
|
"Cache-Control": "private, no-store",
|
|
160
161
|
"Referrer-Policy": "no-referrer"
|
|
161
|
-
}),
|
|
162
|
+
}), pn = (e, t) => {
|
|
162
163
|
const r = new Headers(t);
|
|
163
|
-
for (const [n,
|
|
164
|
+
for (const [n, a] of Object.entries(mn)) r.set(n, a);
|
|
164
165
|
return r.set("Location", e), new Response(null, { status: 302, headers: r });
|
|
165
|
-
},
|
|
166
|
+
}, Ne = (e, t) => {
|
|
166
167
|
const r = new AbortController(), n = t(AbortSignal.any([e.signal, r.signal]));
|
|
167
|
-
return new Promise((
|
|
168
|
-
let
|
|
168
|
+
return new Promise((a) => {
|
|
169
|
+
let s;
|
|
169
170
|
const c = setTimeout(() => {
|
|
170
|
-
|
|
171
|
+
a(e.late), s = setTimeout(() => r.abort(), e.handOverMs);
|
|
171
172
|
}, e.timeoutMs), m = () => {
|
|
172
|
-
clearTimeout(c), clearTimeout(
|
|
173
|
+
clearTimeout(c), clearTimeout(s);
|
|
173
174
|
};
|
|
174
175
|
n.then(
|
|
175
|
-
(
|
|
176
|
-
m(),
|
|
176
|
+
(f) => {
|
|
177
|
+
m(), a(f);
|
|
177
178
|
},
|
|
178
179
|
() => {
|
|
179
|
-
m(),
|
|
180
|
+
m(), a(e.late);
|
|
180
181
|
}
|
|
181
182
|
);
|
|
182
183
|
});
|
|
183
|
-
},
|
|
184
|
+
}, wn = Object.freeze({
|
|
184
185
|
error: (e, t) => {
|
|
185
186
|
console.error(e, t);
|
|
186
187
|
}
|
|
187
|
-
}),
|
|
188
|
-
class
|
|
188
|
+
}), jt = /* @__PURE__ */ Symbol.for("@aiquants/markdown-explorer:ExplorerError");
|
|
189
|
+
class Oe extends Error {
|
|
189
190
|
reason;
|
|
190
191
|
code;
|
|
191
192
|
constructor(t, r = {}) {
|
|
192
|
-
if (!
|
|
193
|
-
if (r.code !== void 0 && !
|
|
194
|
-
super(`[markdown-explorer] ${t}`, r.cause === void 0 ? void 0 : { cause: r.cause }), this.name = "ExplorerError", this.reason = t, this.code = r.code, Object.defineProperty(this,
|
|
193
|
+
if (!Ot(t)) throw new RangeError(`[markdown-explorer] ExplorerError needs a failure reason; got ${JSON.stringify(t)}`);
|
|
194
|
+
if (r.code !== void 0 && !sr(r.code)) throw new RangeError(`[markdown-explorer] an ExplorerError code must be 1 to 64 lowercase letters, digits or hyphens; got ${JSON.stringify(r.code)}`);
|
|
195
|
+
super(`[markdown-explorer] ${t}`, r.cause === void 0 ? void 0 : { cause: r.cause }), this.name = "ExplorerError", this.reason = t, this.code = r.code, Object.defineProperty(this, jt, { value: !0 });
|
|
195
196
|
}
|
|
196
197
|
}
|
|
197
|
-
const
|
|
198
|
+
const hn = (e) => e instanceof Error && Object.hasOwn(e, jt) && Ot(e.reason), yn = (e) => typeof e == "object" && e !== null && e.name === "AbortError", He = (e, t, r) => {
|
|
198
199
|
try {
|
|
199
200
|
e.error(t, r);
|
|
200
201
|
} catch (n) {
|
|
201
202
|
console.error("[markdown-explorer] the logger threw while reporting a failure", { operation: r.operation, error: n });
|
|
202
203
|
}
|
|
203
|
-
},
|
|
204
|
+
}, ie = (e, t) => He(e, `[markdown-explorer] ${t.operation} failed`, t), gn = (e, t) => He(e, `[markdown-explorer] ${t.operation} left out an entry`, t), Ie = (e, t) => He(e, `[markdown-explorer] ${t.operation} refused a path the deny rules match`, { ...t, error: new RangeError("[markdown-explorer] the path matches a deny rule") }), nt = (e, t) => {
|
|
204
205
|
e === null || typeof e != "object" && typeof e != "function" || Promise.resolve(e).then(void 0, t);
|
|
205
|
-
},
|
|
206
|
+
}, Y = (e, t, r, n) => hn(e) ? xe(e.reason, e.code) : (yn(e) || r.aborted || ie(n, { ...t, error: e }), { reason: "failed" }), ot = 2 * 1024 * 1024, st = 256 * 1024 * 1024, En = async (e, t) => {
|
|
206
207
|
const r = e.getReader(), n = new Uint8Array(t);
|
|
207
|
-
let
|
|
208
|
-
for (;
|
|
209
|
-
const { done:
|
|
210
|
-
if (
|
|
211
|
-
const m = c.subarray(0, t -
|
|
212
|
-
n.set(m,
|
|
208
|
+
let a = 0;
|
|
209
|
+
for (; a < t; ) {
|
|
210
|
+
const { done: s, value: c } = await r.read();
|
|
211
|
+
if (s) return n.subarray(0, a);
|
|
212
|
+
const m = c.subarray(0, t - a);
|
|
213
|
+
n.set(m, a), a += m.byteLength;
|
|
213
214
|
}
|
|
214
215
|
return r.cancel().catch(() => {
|
|
215
216
|
}), n;
|
|
216
|
-
},
|
|
217
|
+
}, bn = async (e, t, r) => {
|
|
217
218
|
if (e.size === 0) return { text: "", truncated: !1 };
|
|
218
|
-
const
|
|
219
|
-
if (e.size !== null &&
|
|
220
|
-
const
|
|
221
|
-
return
|
|
222
|
-
},
|
|
219
|
+
const n = e.size !== null && e.size > t, a = e.size === null ? t + 1 : Math.min(e.size, t), s = await En(await e.open(n ? { offset: 0, length: t } : null), a);
|
|
220
|
+
if (e.size !== null && s.byteLength < a) throw new RangeError("[markdown-explorer] the file ended before the length its asset port reported");
|
|
221
|
+
const c = n || s.byteLength > t, m = c ? s.subarray(0, t) : s, f = $e(m, !c, r);
|
|
222
|
+
return f.includes("\0") ? null : { text: f, truncated: c };
|
|
223
|
+
}, it = (e, t) => {
|
|
223
224
|
if (!Number.isSafeInteger(t) || t <= 0) throw new RangeError(`[markdown-explorer] a cache ${e} must be a positive integer; got ${String(t)}`);
|
|
224
|
-
},
|
|
225
|
-
|
|
225
|
+
}, zt = (e, t) => {
|
|
226
|
+
it("capacity", e), t !== void 0 && it("weight budget", t.max);
|
|
226
227
|
const r = /* @__PURE__ */ new Map();
|
|
227
228
|
let n = 0;
|
|
228
|
-
const
|
|
229
|
-
const c = r.get(
|
|
230
|
-
c !== void 0 && (r.delete(
|
|
229
|
+
const a = (s) => {
|
|
230
|
+
const c = r.get(s);
|
|
231
|
+
c !== void 0 && (r.delete(s), n -= c.weight);
|
|
231
232
|
};
|
|
232
233
|
return {
|
|
233
|
-
get: (
|
|
234
|
-
const c = r.get(
|
|
234
|
+
get: (s) => {
|
|
235
|
+
const c = r.get(s);
|
|
235
236
|
if (c !== void 0)
|
|
236
|
-
return r.delete(
|
|
237
|
+
return r.delete(s), r.set(s, c), c.value;
|
|
237
238
|
},
|
|
238
|
-
set: (
|
|
239
|
-
|
|
240
|
-
const m = t === void 0 ? 0 : t.of(
|
|
239
|
+
set: (s, c) => {
|
|
240
|
+
a(s);
|
|
241
|
+
const m = t === void 0 ? 0 : t.of(s, c);
|
|
241
242
|
if (!(t !== void 0 && m > t.max)) {
|
|
242
|
-
r.set(
|
|
243
|
-
for (const
|
|
243
|
+
r.set(s, { value: c, weight: m }), n += m;
|
|
244
|
+
for (const f of r.keys()) {
|
|
244
245
|
if (r.size <= e && (t === void 0 || n <= t.max)) break;
|
|
245
|
-
|
|
246
|
+
a(f);
|
|
246
247
|
}
|
|
247
248
|
}
|
|
248
249
|
},
|
|
249
|
-
delete:
|
|
250
|
+
delete: a,
|
|
250
251
|
size: () => r.size,
|
|
251
252
|
weight: () => n
|
|
252
253
|
};
|
|
253
|
-
},
|
|
254
|
+
}, Dt = (e) => Math.max(1, e - 1), Tn = 2147483647, at = Object.freeze({ status: "aborted" }), le = (e, t, r) => {
|
|
254
255
|
const n = (e.get(t) ?? 0) + r;
|
|
255
256
|
n === 0 ? e.delete(t) : e.set(t, n);
|
|
256
|
-
},
|
|
257
|
+
}, me = (e, t, r) => {
|
|
257
258
|
if (!Number.isSafeInteger(t) || t <= 0 || t > r) throw new RangeError(`[markdown-explorer] a worker pool's ${e} must be an integer in 1..${String(r)}; got ${String(t)}`);
|
|
258
|
-
},
|
|
259
|
-
|
|
260
|
-
const c = Object.freeze({ maxOldGenerationSizeMb:
|
|
261
|
-
let
|
|
262
|
-
const v = (
|
|
263
|
-
const { job:
|
|
264
|
-
|
|
265
|
-
},
|
|
266
|
-
const [g] =
|
|
259
|
+
}, kn = (e) => e !== null && typeof e == "object" && e.ready === !0 && !("id" in e), Sn = (e, t) => e !== null && typeof e == "object" && e.id === t && "output" in e, xn = ({ url: e, size: t, deadlineMs: r, jobsPerScope: n, maxQueuedJobs: a, heapLimits: s }) => {
|
|
260
|
+
me("size", t, Number.MAX_SAFE_INTEGER), me("deadline", r, Tn), me("jobsPerScope", n, Number.MAX_SAFE_INTEGER), me("maxQueuedJobs", a, Number.MAX_SAFE_INTEGER), me("maxOldGenerationSizeMb", s.maxOldGenerationSizeMb, Number.MAX_SAFE_INTEGER), me("maxYoungGenerationSizeMb", s.maxYoungGenerationSizeMb, Number.MAX_SAFE_INTEGER);
|
|
261
|
+
const c = Object.freeze({ maxOldGenerationSizeMb: s.maxOldGenerationSizeMb, maxYoungGenerationSizeMb: s.maxYoungGenerationSizeMb }), m = /* @__PURE__ */ new Set(), f = [], S = /* @__PURE__ */ new Map(), h = /* @__PURE__ */ new Map(), y = Dt(t);
|
|
262
|
+
let T = 0;
|
|
263
|
+
const v = (w, g) => {
|
|
264
|
+
const { job: M } = w;
|
|
265
|
+
w.timer !== null && clearTimeout(w.timer), w.timer = null, w.job = null, w.sent = !1, M !== null && (le(S, M.scope, -1), le(h, M.scope, -1), M.settle(g));
|
|
266
|
+
}, z = (w) => {
|
|
267
|
+
const [g] = f.splice(w, 1);
|
|
267
268
|
g?.detach();
|
|
268
|
-
},
|
|
269
|
-
let
|
|
270
|
-
for (const [
|
|
271
|
-
const
|
|
272
|
-
(
|
|
269
|
+
}, x = () => {
|
|
270
|
+
let w = -1, g = y, M = Number.POSITIVE_INFINITY;
|
|
271
|
+
for (const [U, E] of f.entries()) {
|
|
272
|
+
const _ = S.get(E.scope) ?? 0, N = h.get(E.scope) ?? 0;
|
|
273
|
+
(_ < g || _ === g && w >= 0 && N < M) && (w = U, g = _, M = N);
|
|
273
274
|
}
|
|
274
|
-
return
|
|
275
|
-
},
|
|
276
|
-
m.has(
|
|
275
|
+
return w;
|
|
276
|
+
}, O = (w, g) => {
|
|
277
|
+
m.has(w) && (m.delete(w), v(w, g), w.worker.terminate().catch(() => {
|
|
277
278
|
}), F());
|
|
278
|
-
}, D = (
|
|
279
|
-
|
|
280
|
-
|
|
279
|
+
}, D = (w) => {
|
|
280
|
+
w.timer = setTimeout(() => {
|
|
281
|
+
O(w, { status: "timeout" });
|
|
281
282
|
}, r);
|
|
282
|
-
},
|
|
283
|
-
|
|
283
|
+
}, R = (w, g) => w.sent ? { status: "crashed", error: g } : { status: "unavailable", error: g }, I = (w, g) => {
|
|
284
|
+
w.sent = !0, D(w);
|
|
284
285
|
try {
|
|
285
|
-
|
|
286
|
-
} catch (
|
|
287
|
-
v(
|
|
286
|
+
w.worker.postMessage({ id: g.id, input: g.input });
|
|
287
|
+
} catch (M) {
|
|
288
|
+
v(w, { status: "crashed", error: M }), w.worker.unref();
|
|
288
289
|
}
|
|
289
290
|
}, C = () => {
|
|
290
|
-
const
|
|
291
|
-
return
|
|
292
|
-
|
|
293
|
-
}, r),
|
|
294
|
-
if (!
|
|
295
|
-
|
|
291
|
+
const w = { worker: new Ur(e, { resourceLimits: c }), job: null, sent: !1, timer: null, ready: !1 };
|
|
292
|
+
return w.worker.unref(), w.timer = setTimeout(() => {
|
|
293
|
+
O(w, { status: "unavailable", error: new Error(`[markdown-explorer] a worker did not start within ${String(r)} ms`) });
|
|
294
|
+
}, r), w.worker.on("message", (g) => {
|
|
295
|
+
if (!w.ready && kn(g)) {
|
|
296
|
+
w.ready = !0, w.timer !== null && clearTimeout(w.timer), w.timer = null, w.job === null ? w.worker.unref() : I(w, w.job), w.job === null && F();
|
|
296
297
|
return;
|
|
297
298
|
}
|
|
298
|
-
const { job:
|
|
299
|
-
if (
|
|
300
|
-
|
|
299
|
+
const { job: M } = w;
|
|
300
|
+
if (M === null || !Sn(g, M.id)) {
|
|
301
|
+
O(w, R(w, new Error("[markdown-explorer] a worker sent a message that answers no job")));
|
|
301
302
|
return;
|
|
302
303
|
}
|
|
303
|
-
v(
|
|
304
|
-
}),
|
|
305
|
-
|
|
306
|
-
}),
|
|
307
|
-
|
|
308
|
-
}),
|
|
309
|
-
|
|
310
|
-
}), m.add(
|
|
304
|
+
v(w, { status: "done", output: g.output }), w.worker.unref(), F();
|
|
305
|
+
}), w.worker.on("error", (g) => {
|
|
306
|
+
O(w, R(w, g));
|
|
307
|
+
}), w.worker.on("messageerror", (g) => {
|
|
308
|
+
O(w, R(w, g));
|
|
309
|
+
}), w.worker.on("exit", (g) => {
|
|
310
|
+
O(w, R(w, new Error(`[markdown-explorer] a worker exited with code ${String(g)}`)));
|
|
311
|
+
}), m.add(w), w;
|
|
311
312
|
}, F = () => {
|
|
312
313
|
for (; ; ) {
|
|
313
|
-
const
|
|
314
|
+
const w = x(), g = f[w];
|
|
314
315
|
if (g === void 0) return;
|
|
315
|
-
let
|
|
316
|
-
for (const
|
|
317
|
-
if (
|
|
318
|
-
|
|
316
|
+
let M;
|
|
317
|
+
for (const E of m)
|
|
318
|
+
if (E.job === null) {
|
|
319
|
+
M = E;
|
|
319
320
|
break;
|
|
320
321
|
}
|
|
321
|
-
if (
|
|
322
|
+
if (M === void 0 && m.size < t)
|
|
322
323
|
try {
|
|
323
|
-
|
|
324
|
-
} catch (
|
|
325
|
-
|
|
324
|
+
M = C();
|
|
325
|
+
} catch (E) {
|
|
326
|
+
z(w), le(h, g.scope, -1), g.settle({ status: "unavailable", error: E });
|
|
326
327
|
continue;
|
|
327
328
|
}
|
|
328
|
-
if (
|
|
329
|
-
|
|
330
|
-
const
|
|
331
|
-
|
|
329
|
+
if (M === void 0) return;
|
|
330
|
+
z(w), le(S, g.scope, 1);
|
|
331
|
+
const U = M;
|
|
332
|
+
U.job = g, U.worker.ref(), U.ready && I(U, g);
|
|
332
333
|
}
|
|
333
334
|
};
|
|
334
335
|
return {
|
|
335
|
-
run: (
|
|
336
|
-
if (
|
|
337
|
-
|
|
336
|
+
run: (w, { scope: g, signal: M }) => new Promise((U) => {
|
|
337
|
+
if (M.aborted) {
|
|
338
|
+
U(at);
|
|
338
339
|
return;
|
|
339
340
|
}
|
|
340
|
-
if ((
|
|
341
|
-
|
|
341
|
+
if ((h.get(g) ?? 0) >= n) {
|
|
342
|
+
U({ status: "refused", limit: "scope" });
|
|
342
343
|
return;
|
|
343
344
|
}
|
|
344
|
-
|
|
345
|
-
const
|
|
345
|
+
T += 1;
|
|
346
|
+
const E = { id: T, input: w, scope: g, settle: U, detach: () => {
|
|
346
347
|
} };
|
|
347
|
-
|
|
348
|
-
const
|
|
349
|
-
if (
|
|
350
|
-
if (
|
|
351
|
-
|
|
348
|
+
f.push(E), le(h, g, 1), F();
|
|
349
|
+
const _ = f.indexOf(E);
|
|
350
|
+
if (_ < 0) return;
|
|
351
|
+
if (f.length > a) {
|
|
352
|
+
z(_), le(h, g, -1), U({ status: "refused", limit: "queue" });
|
|
352
353
|
return;
|
|
353
354
|
}
|
|
354
|
-
const
|
|
355
|
-
const
|
|
356
|
-
|
|
355
|
+
const N = () => {
|
|
356
|
+
const $ = f.indexOf(E);
|
|
357
|
+
$ < 0 || (z($), le(h, g, -1), U(at));
|
|
357
358
|
};
|
|
358
|
-
|
|
359
|
-
|
|
359
|
+
M.addEventListener("abort", N, { once: !0 }), E.detach = () => {
|
|
360
|
+
M.removeEventListener("abort", N);
|
|
360
361
|
};
|
|
361
362
|
}),
|
|
362
363
|
workers: () => m.size
|
|
363
364
|
};
|
|
364
|
-
},
|
|
365
|
+
}, Be = 1024 * 1024, On = 3e4, Rn = 4 * Be, vn = 64 * Be, _n = 3, An = 2, Nn = (e, t) => e + Dt(t) + _n, In = 4, Pn = 32, Mn = 512, Ln = 64, $n = 4096, jn = 32, ct = 4096, zn = 4, Ct = ({ workerHeapMb: e, maxHtmlBytes: t }) => Math.floor(((e - Ln) * Be - t * jn) / $n), Dn = ({ maxHtmlBytes: e }) => e, Cn = ({ maxHtmlBytes: e }) => zn * e, Hn = 1024, Bn = 2147483647, Fn = 64, Un = 2 ** 29, Xn = 1024 * 1024, Jn = 64, ut = Object.freeze({ status: "rejected", reason: "too-large", cause: null }), Pe = Object.freeze({ status: "rejected", reason: "failed", cause: null }), fe = (e, t, r, n) => {
|
|
365
366
|
if (t === void 0) return r;
|
|
366
367
|
if (typeof t != "number") throw new TypeError(`[markdown-explorer] sanitizer.${e} must be a number; got ${typeof t}`);
|
|
367
368
|
if (!Number.isSafeInteger(t) || t <= 0 || t > n) throw new RangeError(`[markdown-explorer] sanitizer.${e} must be an integer in 1..${String(n)}; got ${String(t)}`);
|
|
368
369
|
return t;
|
|
369
|
-
},
|
|
370
|
+
}, Gn = (e, t) => {
|
|
370
371
|
if (e !== void 0 && (e === null || typeof e != "object")) throw new TypeError("[markdown-explorer] sanitizer must be an object of { workers, deadlineMs, maxHtmlBytes, cacheBytes, workerHeapMb, jobsPerScope, maxQueuedJobs }");
|
|
371
|
-
const { workers: r, deadlineMs: n, maxHtmlBytes:
|
|
372
|
-
workers:
|
|
373
|
-
deadlineMs:
|
|
374
|
-
maxHtmlBytes:
|
|
375
|
-
cacheBytes:
|
|
376
|
-
workerHeapMb:
|
|
377
|
-
jobsPerScope:
|
|
378
|
-
maxQueuedJobs:
|
|
372
|
+
const { workers: r, deadlineMs: n, maxHtmlBytes: a, cacheBytes: s, workerHeapMb: c, jobsPerScope: m, maxQueuedJobs: f } = e ?? {}, S = fe("workers", r, An, Fn), h = fe("jobsPerScope", m, Nn(t, S), Number.MAX_SAFE_INTEGER), y = Object.freeze({
|
|
373
|
+
workers: S,
|
|
374
|
+
deadlineMs: fe("deadlineMs", n, On, Bn),
|
|
375
|
+
maxHtmlBytes: fe("maxHtmlBytes", a, Rn, Un),
|
|
376
|
+
cacheBytes: fe("cacheBytes", s, vn, Number.MAX_SAFE_INTEGER),
|
|
377
|
+
workerHeapMb: fe("workerHeapMb", c, Mn, Xn),
|
|
378
|
+
jobsPerScope: h,
|
|
379
|
+
maxQueuedJobs: fe("maxQueuedJobs", f, In * h, Number.MAX_SAFE_INTEGER)
|
|
379
380
|
});
|
|
380
381
|
if (y.jobsPerScope < t)
|
|
381
382
|
throw new RangeError(`[markdown-explorer] sanitizer.jobsPerScope must be at least multiView.maxPanels (${String(t)}), because a page sends the document of every panel to the sanitizer at once for one reader; got ${String(y.jobsPerScope)}`);
|
|
382
383
|
if (y.maxQueuedJobs < t)
|
|
383
384
|
throw new RangeError(`[markdown-explorer] sanitizer.maxQueuedJobs must be at least multiView.maxPanels (${String(t)}), because a reader whose page finds every worker busy waits with the document of every panel; got ${String(y.maxQueuedJobs)}`);
|
|
384
|
-
if (
|
|
385
|
+
if (Ct(y) < ct)
|
|
385
386
|
throw new RangeError(
|
|
386
|
-
`[markdown-explorer] sanitizer.workerHeapMb (${String(y.workerHeapMb)} MiB) must leave room for ${String(
|
|
387
|
+
`[markdown-explorer] sanitizer.workerHeapMb (${String(y.workerHeapMb)} MiB) must leave room for ${String(ct)} parsed nodes beside HTML of sanitizer.maxHtmlBytes (${String(y.maxHtmlBytes)} bytes); raise workerHeapMb or lower maxHtmlBytes`
|
|
387
388
|
);
|
|
388
389
|
return y;
|
|
389
|
-
},
|
|
390
|
-
const e = import.meta.url, t = new URL(`./sanitizeWorker${
|
|
391
|
-
if (!
|
|
390
|
+
}, Yn = () => {
|
|
391
|
+
const e = import.meta.url, t = new URL(`./sanitizeWorker${Br(_e(e))}`, e);
|
|
392
|
+
if (!Dr(_e(t))) throw new Error(`[markdown-explorer] the HTML sanitizer worker is missing: ${_e(t)}`);
|
|
392
393
|
return t;
|
|
393
|
-
},
|
|
394
|
+
}, dt = /* @__PURE__ */ new Map(), Wn = (e, t) => {
|
|
394
395
|
const r = [e.href, t.workers, t.deadlineMs, t.workerHeapMb, t.jobsPerScope, t.maxQueuedJobs].map(String).join("\0");
|
|
395
|
-
let n =
|
|
396
|
-
return n === void 0 && (n =
|
|
396
|
+
let n = dt.get(r);
|
|
397
|
+
return n === void 0 && (n = xn({
|
|
397
398
|
url: e,
|
|
398
399
|
size: t.workers,
|
|
399
400
|
deadlineMs: t.deadlineMs,
|
|
400
401
|
jobsPerScope: t.jobsPerScope,
|
|
401
402
|
maxQueuedJobs: t.maxQueuedJobs,
|
|
402
|
-
heapLimits: { maxOldGenerationSizeMb: t.workerHeapMb, maxYoungGenerationSizeMb:
|
|
403
|
-
}),
|
|
404
|
-
},
|
|
403
|
+
heapLimits: { maxOldGenerationSizeMb: t.workerHeapMb, maxYoungGenerationSizeMb: Pn }
|
|
404
|
+
}), dt.set(r, n)), n;
|
|
405
|
+
}, Kn = (e) => {
|
|
405
406
|
if (e === null || typeof e != "object") return !1;
|
|
406
407
|
const { status: t, html: r, message: n } = e;
|
|
407
408
|
return t === "sanitized" && typeof r == "string" || t === "too-large" || t === "error" && typeof n == "string";
|
|
408
|
-
},
|
|
409
|
-
const
|
|
409
|
+
}, Vn = (e) => e instanceof Error && e.code === "ERR_WORKER_OUT_OF_MEMORY", Zn = ({ iframeHosts: e, dataPath: t, options: r, pool: n }) => {
|
|
410
|
+
const a = Object.freeze([...e]), s = Ct(r), c = Dn(r), m = Cn(r), f = zt(Hn, {
|
|
410
411
|
max: r.cacheBytes,
|
|
411
|
-
of: (
|
|
412
|
-
}),
|
|
413
|
-
|
|
414
|
-
const
|
|
415
|
-
|
|
416
|
-
},
|
|
417
|
-
const
|
|
418
|
-
if (
|
|
419
|
-
const C =
|
|
412
|
+
of: (x, O) => 2 * x.length + (O.status === "sanitized" ? 2 * O.html.length : Jn)
|
|
413
|
+
}), S = /* @__PURE__ */ new Map(), h = /* @__PURE__ */ new Map(), y = (x) => {
|
|
414
|
+
S.get(x.key) === x && S.delete(x.key);
|
|
415
|
+
const O = h.get(x.hash);
|
|
416
|
+
O?.delete(x), O?.size === 0 && h.delete(x.hash);
|
|
417
|
+
}, T = async (x, O, D) => {
|
|
418
|
+
const R = await n.run({ html: x, iframeHosts: a, dataPath: t, maxNodes: s, maxAttributeChars: c, maxSanitizedChars: m }, { scope: O, signal: D });
|
|
419
|
+
if (R.status === "refused") {
|
|
420
|
+
const C = R.limit === "scope" ? `its reader already has ${String(r.jobsPerScope)} documents being sanitized or waiting` : `${String(r.maxQueuedJobs)} documents are already waiting`;
|
|
420
421
|
return { outcome: { status: "rejected", reason: "failed", cause: new Error(`[markdown-explorer] the HTML sanitizer refused a document: ${C}`) }, lasting: !1 };
|
|
421
422
|
}
|
|
422
|
-
if (
|
|
423
|
-
if (
|
|
424
|
-
if (
|
|
425
|
-
if (
|
|
426
|
-
return { outcome: { status: "rejected", reason: "too-large", cause: new Error(`[markdown-explorer] the HTML sanitizer ran out of its ${String(r.workerHeapMb)} MiB worker heap`, { cause:
|
|
427
|
-
if (
|
|
428
|
-
const { output:
|
|
429
|
-
return
|
|
430
|
-
}, v = (
|
|
431
|
-
let
|
|
423
|
+
if (R.status === "aborted") return { outcome: Pe, lasting: !1 };
|
|
424
|
+
if (R.status === "timeout") return { outcome: { status: "rejected", reason: "too-large", cause: new Error(`[markdown-explorer] the HTML sanitizer did not finish within ${String(r.deadlineMs)} ms`) }, lasting: !0 };
|
|
425
|
+
if (R.status === "unavailable") return { outcome: { status: "rejected", reason: "failed", cause: new Error("[markdown-explorer] the HTML sanitizer worker could not start", { cause: R.error }) }, lasting: !1 };
|
|
426
|
+
if (R.status === "crashed" && Vn(R.error))
|
|
427
|
+
return { outcome: { status: "rejected", reason: "too-large", cause: new Error(`[markdown-explorer] the HTML sanitizer ran out of its ${String(r.workerHeapMb)} MiB worker heap`, { cause: R.error }) }, lasting: !0 };
|
|
428
|
+
if (R.status === "crashed") return { outcome: { status: "rejected", reason: "failed", cause: new Error("[markdown-explorer] the HTML sanitizer worker failed", { cause: R.error }) }, lasting: !0 };
|
|
429
|
+
const { output: I } = R;
|
|
430
|
+
return Kn(I) ? I.status === "too-large" ? { outcome: ut, lasting: !0 } : I.status === "error" ? { outcome: { status: "rejected", reason: "failed", cause: new Error(`[markdown-explorer] the HTML sanitizer failed: ${I.message}`) }, lasting: !0 } : I.html.length > m ? { outcome: { status: "rejected", reason: "too-large", cause: new Error(`[markdown-explorer] the HTML sanitizer's output of ${String(I.html.length)} characters exceeds its limit of ${String(m)}`) }, lasting: !0 } : { outcome: { status: "sanitized", html: I.html }, lasting: !0 } : { outcome: { status: "rejected", reason: "failed", cause: new Error("[markdown-explorer] the HTML sanitizer worker answered something that is not an outcome") }, lasting: !0 };
|
|
431
|
+
}, v = (x, O, D, R) => {
|
|
432
|
+
let I = () => {
|
|
432
433
|
};
|
|
433
434
|
const C = new Promise((g) => {
|
|
434
|
-
|
|
435
|
-
}), F = { hash:
|
|
436
|
-
|
|
437
|
-
const
|
|
438
|
-
return
|
|
439
|
-
if (y(F), F.answer(g), !
|
|
440
|
-
const
|
|
441
|
-
|
|
442
|
-
for (const
|
|
443
|
-
y(
|
|
435
|
+
I = g;
|
|
436
|
+
}), F = { hash: O, key: D, outcome: C, answer: I, controller: new AbortController(), waiters: 0 };
|
|
437
|
+
S.set(D, F);
|
|
438
|
+
const w = h.get(O);
|
|
439
|
+
return w === void 0 ? h.set(O, /* @__PURE__ */ new Set([F])) : w.add(F), T(x, R, F.controller.signal).catch((g) => ({ outcome: { status: "rejected", reason: "failed", cause: g instanceof Error ? g : new Error(String(g)) }, lasting: !0 })).then(({ outcome: g, lasting: M }) => {
|
|
440
|
+
if (y(F), F.answer(g), !M) return;
|
|
441
|
+
const U = f.get(O), E = U ?? (g.status === "rejected" ? { ...g, cause: null } : g);
|
|
442
|
+
U === void 0 && f.set(O, E);
|
|
443
|
+
for (const _ of h.get(O) ?? [])
|
|
444
|
+
y(_), _.answer(E), _.controller.abort();
|
|
444
445
|
}), F;
|
|
445
|
-
},
|
|
446
|
-
|
|
447
|
-
const
|
|
448
|
-
|
|
446
|
+
}, z = (x, O) => new Promise((D) => {
|
|
447
|
+
x.waiters += 1;
|
|
448
|
+
const R = () => {
|
|
449
|
+
x.waiters -= 1, D(Pe), !(x.waiters > 0) && (y(x), x.controller.abort());
|
|
449
450
|
};
|
|
450
|
-
|
|
451
|
-
|
|
451
|
+
O.addEventListener("abort", R, { once: !0 }), x.outcome.then((I) => {
|
|
452
|
+
O.removeEventListener("abort", R), D(I);
|
|
452
453
|
});
|
|
453
454
|
});
|
|
454
|
-
return (
|
|
455
|
-
if (
|
|
456
|
-
const
|
|
457
|
-
if (
|
|
458
|
-
if (D.aborted) return Promise.resolve(
|
|
459
|
-
const C = `${
|
|
460
|
-
return
|
|
455
|
+
return (x, { scope: O, signal: D }) => {
|
|
456
|
+
if (x.length > r.maxHtmlBytes || Buffer.byteLength(x, "utf8") > r.maxHtmlBytes) return Promise.resolve(ut);
|
|
457
|
+
const R = Lr("sha256").update(x, "utf8").digest("base64"), I = f.get(R);
|
|
458
|
+
if (I !== void 0) return Promise.resolve(I);
|
|
459
|
+
if (D.aborted) return Promise.resolve(Pe);
|
|
460
|
+
const C = `${R}\0${O}`, F = S.get(C);
|
|
461
|
+
return z(F === void 0 ? v(x, R, C, O) : F, D);
|
|
461
462
|
};
|
|
462
|
-
},
|
|
463
|
-
const
|
|
464
|
-
const
|
|
465
|
-
const
|
|
466
|
-
return !(v.superseded ||
|
|
463
|
+
}, Re = (e) => ({ result: e, json: JSON.stringify(e) }), Me = Object.freeze(Re(Object.freeze({ status: "error", failure: Object.freeze({ reason: "failed" }) }))), Qn = (e) => e.status === "ok" && e.entries.length > 0, qn = ({ ttlMs: e, maxEntries: t, maxBytes: r, now: n }) => {
|
|
464
|
+
const a = zt(t, { max: r, of: (h, y) => 2 * y.tree.json.length }), s = /* @__PURE__ */ new Map(), c = /* @__PURE__ */ new Map(), m = (h, y) => {
|
|
465
|
+
const T = new AbortController(), v = { waiters: 0, superseded: !1, started: !1, loadTree: y }, z = c.get(h), x = (C, F) => {
|
|
466
|
+
const w = Re(C);
|
|
467
|
+
return !(v.superseded || T.signal.aborted) && Qn(C) && a.set(h, { tree: w, loadedAt: F }), w;
|
|
467
468
|
}, D = (async () => {
|
|
468
|
-
if (
|
|
469
|
+
if (z !== void 0 && await z, T.signal.aborted) return Me;
|
|
469
470
|
const C = n();
|
|
470
|
-
return v.started = !0,
|
|
471
|
+
return v.started = !0, x(await v.loadTree(T.signal, C), C);
|
|
471
472
|
})().finally(() => {
|
|
472
|
-
|
|
473
|
-
}),
|
|
474
|
-
|
|
475
|
-
const
|
|
473
|
+
s.get(h) === R && s.delete(h);
|
|
474
|
+
}), R = { promise: D, controller: T, state: v };
|
|
475
|
+
s.set(h, R);
|
|
476
|
+
const I = D.then(
|
|
476
477
|
() => {
|
|
477
478
|
},
|
|
478
479
|
() => {
|
|
479
480
|
}
|
|
480
481
|
);
|
|
481
|
-
return c.set(
|
|
482
|
-
c.get(
|
|
483
|
-
}),
|
|
484
|
-
},
|
|
482
|
+
return c.set(h, I), I.then(() => {
|
|
483
|
+
c.get(h) === I && c.delete(h);
|
|
484
|
+
}), R;
|
|
485
|
+
}, f = (h, y, T) => {
|
|
485
486
|
y.state.waiters += 1;
|
|
486
487
|
const v = () => {
|
|
487
|
-
y.state.waiters -= 1, !(y.state.waiters > 0) && (
|
|
488
|
+
y.state.waiters -= 1, !(y.state.waiters > 0) && (s.get(h) === y && s.delete(h), y.controller.abort());
|
|
488
489
|
};
|
|
489
|
-
return
|
|
490
|
-
|
|
490
|
+
return T.addEventListener("abort", v, { once: !0 }), y.promise.finally(() => {
|
|
491
|
+
T.removeEventListener("abort", v);
|
|
491
492
|
});
|
|
492
|
-
},
|
|
493
|
-
|
|
494
|
-
const y =
|
|
495
|
-
y?.state.started && (y.state.superseded = !0,
|
|
493
|
+
}, S = (h) => {
|
|
494
|
+
a.delete(h);
|
|
495
|
+
const y = s.get(h);
|
|
496
|
+
y?.state.started && (y.state.superseded = !0, s.delete(h));
|
|
496
497
|
};
|
|
497
498
|
return {
|
|
498
|
-
load: (
|
|
499
|
-
if (y.aborted) return Promise.resolve(
|
|
500
|
-
const v =
|
|
499
|
+
load: (h, y, T) => {
|
|
500
|
+
if (y.aborted) return Promise.resolve(Me);
|
|
501
|
+
const v = a.get(h);
|
|
501
502
|
if (v !== void 0) {
|
|
502
503
|
if (n() - v.loadedAt < e) return Promise.resolve(v.tree);
|
|
503
|
-
|
|
504
|
+
a.delete(h);
|
|
504
505
|
}
|
|
505
|
-
const
|
|
506
|
-
return h
|
|
506
|
+
const z = s.get(h);
|
|
507
|
+
return f(h, z === void 0 ? m(h, T) : z, y);
|
|
507
508
|
},
|
|
508
|
-
refresh: (
|
|
509
|
-
if (y.aborted) return Promise.resolve(
|
|
510
|
-
|
|
511
|
-
const v =
|
|
512
|
-
return v === void 0 ? h
|
|
509
|
+
refresh: (h, y, T) => {
|
|
510
|
+
if (y.aborted) return Promise.resolve(Me);
|
|
511
|
+
S(h);
|
|
512
|
+
const v = s.get(h);
|
|
513
|
+
return v === void 0 ? f(h, m(h, T), y) : (v.state.loadTree = T, f(h, v, y));
|
|
513
514
|
},
|
|
514
|
-
forget:
|
|
515
|
+
forget: S
|
|
515
516
|
};
|
|
516
|
-
},
|
|
517
|
-
load: (t, r, n) => n(r, e()).then(
|
|
518
|
-
refresh: (t, r, n) => n(r, e()).then(
|
|
517
|
+
}, eo = (e) => ({
|
|
518
|
+
load: (t, r, n) => n(r, e()).then(Re),
|
|
519
|
+
refresh: (t, r, n) => n(r, e()).then(Re),
|
|
519
520
|
forget: () => {
|
|
520
521
|
}
|
|
521
|
-
}),
|
|
522
|
+
}), k = (e) => {
|
|
522
523
|
throw new TypeError(`[markdown-explorer] ${e}`);
|
|
523
|
-
},
|
|
524
|
+
}, to = (e) => {
|
|
524
525
|
if (e === null || typeof e != "object") return null;
|
|
525
526
|
const { name: t, path: r } = e;
|
|
526
|
-
return typeof t != "string" || typeof r != "string" ? null : t === "" ? { path: r, reason: "an empty name" } :
|
|
527
|
-
},
|
|
527
|
+
return typeof t != "string" || typeof r != "string" ? null : t === "" ? { path: r, reason: "an empty name" } : re(r) ? null : { path: r, reason: "a path the browser cannot address (empty, too long, a lone surrogate, a control character or a backslash)" };
|
|
528
|
+
}, ro = (e, t, r, n) => {
|
|
528
529
|
if (e === null) return null;
|
|
529
530
|
if (!Array.isArray(e)) throw new TypeError(`[markdown-explorer] a source's ancestors must be null or an array of folder paths; got ${typeof e}`);
|
|
530
|
-
const
|
|
531
|
-
for (const
|
|
532
|
-
if (typeof
|
|
533
|
-
if (r.deniesPath(
|
|
534
|
-
if (!n(
|
|
535
|
-
if (
|
|
536
|
-
if (
|
|
537
|
-
|
|
531
|
+
const a = /* @__PURE__ */ new Set();
|
|
532
|
+
for (const s of e) {
|
|
533
|
+
if (typeof s != "string" || !re(s)) throw new TypeError("[markdown-explorer] a source's ancestors held a path the explorer does not accept");
|
|
534
|
+
if (r.deniesPath(s)) throw new TypeError("[markdown-explorer] a source's ancestors held a denied path");
|
|
535
|
+
if (!n(s)) throw new TypeError("[markdown-explorer] a source's ancestors held a path outside the source's boundary");
|
|
536
|
+
if (s === t) throw new TypeError("[markdown-explorer] a source's ancestors held the document itself");
|
|
537
|
+
if (a.has(s)) throw new TypeError("[markdown-explorer] a source's ancestors held a path twice");
|
|
538
|
+
a.add(s);
|
|
538
539
|
}
|
|
539
|
-
return Object.freeze([...
|
|
540
|
-
},
|
|
541
|
-
const
|
|
542
|
-
if (!Array.isArray(
|
|
543
|
-
const
|
|
544
|
-
for (const
|
|
545
|
-
const y = m(
|
|
546
|
-
y !== null &&
|
|
540
|
+
return Object.freeze([...a]);
|
|
541
|
+
}, no = (e, t, r, n, a) => {
|
|
542
|
+
const s = /* @__PURE__ */ new Set(), c = (f) => {
|
|
543
|
+
if (!Array.isArray(f)) return k("a source returned entries that are not an array");
|
|
544
|
+
const S = [];
|
|
545
|
+
for (const h of f) {
|
|
546
|
+
const y = m(h);
|
|
547
|
+
y !== null && S.push(y);
|
|
547
548
|
}
|
|
548
|
-
return
|
|
549
|
-
}, m = (
|
|
550
|
-
const
|
|
551
|
-
if (
|
|
552
|
-
return n(
|
|
553
|
-
const
|
|
554
|
-
if (
|
|
555
|
-
const y =
|
|
556
|
-
if (
|
|
557
|
-
const { name:
|
|
558
|
-
if (t.deniesName(
|
|
559
|
-
if (!
|
|
549
|
+
return S;
|
|
550
|
+
}, m = (f) => {
|
|
551
|
+
const S = to(f);
|
|
552
|
+
if (S !== null)
|
|
553
|
+
return n(S), null;
|
|
554
|
+
const h = wr(f);
|
|
555
|
+
if (h !== null) return k(h);
|
|
556
|
+
const y = f;
|
|
557
|
+
if (s.has(y)) return k("a source returned entries that contain themselves");
|
|
558
|
+
const { name: T, path: v, type: z, mimeType: x, modifiedAt: O, children: D, lazy: R } = y;
|
|
559
|
+
if (t.deniesName(T) || t.deniesPath(v)) return null;
|
|
560
|
+
if (!a(v))
|
|
560
561
|
return n({ path: v, reason: "a path outside the source's boundary" }), null;
|
|
561
|
-
const
|
|
562
|
-
if (
|
|
563
|
-
if (
|
|
564
|
-
return r ? { ...
|
|
565
|
-
if (D === void 0) return { ...
|
|
566
|
-
|
|
562
|
+
const I = { name: T, path: v, ...x === void 0 ? {} : { mimeType: x }, ...O === void 0 ? {} : { modifiedAt: O } };
|
|
563
|
+
if (z === "file") return { ...I, type: z };
|
|
564
|
+
if (R === !0)
|
|
565
|
+
return r ? { ...I, type: z, lazy: !0, children: [] } : k("a lazy directory came from a source without a children function");
|
|
566
|
+
if (D === void 0) return { ...I, type: z };
|
|
567
|
+
s.add(y);
|
|
567
568
|
const C = c(D);
|
|
568
|
-
return
|
|
569
|
+
return s.delete(y), { ...I, type: z, children: C };
|
|
569
570
|
};
|
|
570
571
|
return c(e);
|
|
571
|
-
},
|
|
572
|
+
}, oo = /^[\x21\x23-\x7E]{1,256}$/u, Ht = (e) => typeof e == "string" && oo.test(e), so = /* @__PURE__ */ new Set(["text", "image", "media", "spreadsheet", "file"]), io = (e) => typeof e == "string" && so.has(e), ao = (e, t, r) => {
|
|
572
573
|
if (e !== null && typeof e == "object") {
|
|
573
|
-
const
|
|
574
|
-
if (
|
|
575
|
-
if (Object.hasOwn(
|
|
576
|
-
if (typeof
|
|
577
|
-
if (!
|
|
578
|
-
const m = t(
|
|
574
|
+
const s = e, { kind: c } = s;
|
|
575
|
+
if (io(c)) {
|
|
576
|
+
if (Object.hasOwn(s, "url")) return k(`a ${c} document carries its version, not a url`);
|
|
577
|
+
if (typeof s.name != "string") return k("a document needs a name string");
|
|
578
|
+
if (!Ht(s.version)) return k(`a ${c} document needs a version of 1 to 256 visible ASCII characters other than '"'`);
|
|
579
|
+
const m = t(s.version);
|
|
579
580
|
switch (c) {
|
|
580
|
-
case "image":
|
|
581
|
+
case "image": {
|
|
582
|
+
const { imageType: f } = s;
|
|
583
|
+
return dr(f) ? { kind: c, name: s.name, url: m, imageType: f } : k(`unknown image type ${typeof f == "string" ? JSON.stringify(f.slice(0, 64)) : typeof f}`);
|
|
584
|
+
}
|
|
581
585
|
case "file":
|
|
582
|
-
return { kind: c, name:
|
|
586
|
+
return { kind: c, name: s.name, url: m };
|
|
583
587
|
case "media": {
|
|
584
|
-
const { mediaType:
|
|
585
|
-
return
|
|
588
|
+
const { mediaType: f } = s;
|
|
589
|
+
return ur(f) ? { kind: c, name: s.name, url: m, mediaType: f } : k(`unknown media type ${typeof f == "string" ? JSON.stringify(f.slice(0, 64)) : typeof f}`);
|
|
586
590
|
}
|
|
587
591
|
case "text":
|
|
588
|
-
return typeof
|
|
592
|
+
return typeof s.text != "string" || typeof s.truncated != "boolean" ? k("a text document needs text and truncated") : { kind: c, name: s.name, text: s.text, truncated: s.truncated, url: m };
|
|
593
|
+
case "spreadsheet": {
|
|
594
|
+
const f = cr(s);
|
|
595
|
+
if (f !== null) return k(f);
|
|
596
|
+
const { format: S, firstSheetOnly: h, edit: y } = s;
|
|
597
|
+
return { kind: c, name: s.name, url: m, format: S, firstSheetOnly: h, edit: uo(y) };
|
|
598
|
+
}
|
|
589
599
|
}
|
|
590
600
|
}
|
|
591
601
|
}
|
|
592
|
-
const n =
|
|
593
|
-
if (n !== null) return
|
|
594
|
-
const
|
|
595
|
-
switch (
|
|
602
|
+
const n = lr(e);
|
|
603
|
+
if (n !== null) return k(n);
|
|
604
|
+
const a = e;
|
|
605
|
+
switch (a.kind) {
|
|
596
606
|
case "failure": {
|
|
597
|
-
const { reason:
|
|
598
|
-
return { kind: "failure", failure:
|
|
607
|
+
const { reason: s, code: c } = a.failure;
|
|
608
|
+
return { kind: "failure", failure: xe(s, c) };
|
|
599
609
|
}
|
|
600
610
|
case "markdown":
|
|
601
|
-
return
|
|
611
|
+
return a.headings.length > Rt ? { kind: "failure", failure: xe("too-large") } : (a.edit?.kind === "inline" || a.edit?.kind === "draft") && !r ? k(`a markdown document offers ${a.edit.kind} editing, but the server has no edit ports`) : { kind: "unsanitized-markdown", name: a.name, html: a.htmlContent, headings: a.headings.map(({ text: s, depth: c, id: m }) => ({ text: s, depth: c, id: m })), edit: co(a.edit) };
|
|
602
612
|
}
|
|
603
|
-
},
|
|
613
|
+
}, co = (e) => {
|
|
604
614
|
if (e === null) return null;
|
|
605
615
|
switch (e.kind) {
|
|
606
616
|
case "inline":
|
|
@@ -610,514 +620,514 @@ const ln = (e) => e instanceof Error && Object.hasOwn(e, Pt) && Tt(e.reason), fn
|
|
|
610
620
|
case "external":
|
|
611
621
|
return { kind: "external", href: e.href };
|
|
612
622
|
}
|
|
613
|
-
},
|
|
614
|
-
if (e === null || typeof e != "object") return
|
|
623
|
+
}, uo = (e) => e === null ? null : { kind: "external", href: e.href }, ve = (e, t, r) => typeof e != "string" ? k(`${r} needs a text string`) : e.includes("\0") ? k(`${r} holds NUL, which no text editor can keep`) : new TextEncoder().encode(e).byteLength > t ? k(`${r} is over editMaxBytes (${t} bytes); refuse a longer source with ExplorerError "too-large"`) : e, Bt = (e) => pr(e.href) ? { kind: "grant", href: e.href } : k("a grant needs a root-relative href"), lo = (e, t) => {
|
|
624
|
+
if (e === null || typeof e != "object") return k("an edit source must be an object");
|
|
615
625
|
const r = e;
|
|
616
|
-
return r.kind === "grant" ?
|
|
617
|
-
},
|
|
618
|
-
if (e === null || typeof e != "object") return
|
|
626
|
+
return r.kind === "grant" ? Bt(r) : r.kind === "draft" ? { kind: "draft", text: ve(r.text, t, "a draft source") } : r.kind !== "edit" ? k(`an edit source's kind must be "edit", "draft" or "grant"`) : ge(r.version) ? typeof r.history != "boolean" ? k("an edit source needs history") : { kind: "edit", text: ve(r.text, t, "an edit source"), version: r.version, history: r.history } : k("an edit source needs a version of 1 to 1024 characters");
|
|
627
|
+
}, fo = (e, t) => {
|
|
628
|
+
if (e === null || typeof e != "object") return k("a save result must be an object");
|
|
619
629
|
const r = e;
|
|
620
630
|
switch (r.kind) {
|
|
621
631
|
case "grant":
|
|
622
|
-
return
|
|
632
|
+
return Bt(r);
|
|
623
633
|
case "saved":
|
|
624
|
-
return
|
|
634
|
+
return ge(r.version) ? { kind: "saved", version: r.version } : k("a saved result needs a version of 1 to 1024 characters");
|
|
625
635
|
case "conflict":
|
|
626
|
-
return
|
|
636
|
+
return ge(r.version) ? { kind: "conflict", version: r.version, text: ve(r.text, t, "a conflict's current text") } : k("a conflict needs the current version of 1 to 1024 characters");
|
|
627
637
|
default:
|
|
628
|
-
return
|
|
638
|
+
return k(`a save result's kind must be "saved", "conflict" or "grant"`);
|
|
629
639
|
}
|
|
630
|
-
},
|
|
631
|
-
if (e === null || typeof e != "object") return
|
|
640
|
+
}, mo = (e) => {
|
|
641
|
+
if (e === null || typeof e != "object") return k("a preview must be an object");
|
|
632
642
|
const { htmlContent: t, headings: r } = e;
|
|
633
|
-
if (typeof t != "string" || !Array.isArray(r)) return
|
|
634
|
-
if (r.length >
|
|
643
|
+
if (typeof t != "string" || !Array.isArray(r)) return k("a preview needs htmlContent and headings");
|
|
644
|
+
if (r.length > Rt) return { kind: "failure", failure: xe("too-large") };
|
|
635
645
|
for (const n of r) {
|
|
636
|
-
const
|
|
637
|
-
if (
|
|
646
|
+
const a = mr(n);
|
|
647
|
+
if (a !== null) return k(a);
|
|
638
648
|
}
|
|
639
|
-
return { html: t, headings: r.map(({ text: n, depth:
|
|
640
|
-
},
|
|
641
|
-
if (!Array.isArray(e)) return
|
|
649
|
+
return { html: t, headings: r.map(({ text: n, depth: a, id: s }) => ({ text: n, depth: a, id: s })) };
|
|
650
|
+
}, po = (e) => {
|
|
651
|
+
if (!Array.isArray(e)) return k("revisions must be an array");
|
|
642
652
|
const t = /* @__PURE__ */ new Set();
|
|
643
653
|
return e.map((r) => {
|
|
644
|
-
const n =
|
|
645
|
-
if (n !== null) return
|
|
646
|
-
const { id:
|
|
647
|
-
return t.has(
|
|
654
|
+
const n = fr(r);
|
|
655
|
+
if (n !== null) return k(n);
|
|
656
|
+
const { id: a, modifiedAt: s, size: c, author: m, kept: f, current: S } = r;
|
|
657
|
+
return t.has(a) ? k(`two revisions share the id ${JSON.stringify(a.slice(0, 64))}`) : (t.add(a), { id: a, modifiedAt: s, size: c, author: m, kept: f, current: S });
|
|
648
658
|
});
|
|
649
|
-
},
|
|
650
|
-
if (e === null || typeof e != "object") return
|
|
651
|
-
const { name: t, contentType: r, size: n, version:
|
|
652
|
-
return c !== void 0 ?
|
|
653
|
-
},
|
|
654
|
-
if (e === null || typeof e != "object" || e.kind !== "redirect") return
|
|
659
|
+
}, wo = (e, t) => ve(e, t, "a revision"), ze = (e) => {
|
|
660
|
+
if (e === null || typeof e != "object") return k("an asset file must be an object");
|
|
661
|
+
const { name: t, contentType: r, size: n, version: a, open: s, kind: c } = e;
|
|
662
|
+
return c !== void 0 ? k(c === "redirect" ? "an asset redirect answers only a request for the stored file (options.redirect), never one that reads the bytes" : 'an asset file has no kind (the only kind is "redirect")') : typeof t != "string" || t === "" ? k("an asset file needs a non-empty name") : typeof r != "string" ? k("an asset file needs a contentType string ('' when unknown)") : n !== null && !(typeof n == "number" && Number.isSafeInteger(n) && n >= 0) ? k("an asset file's size must be null or a non-negative safe integer") : Ht(a) ? typeof s != "function" ? k("an asset file needs an open function") : Object.freeze({ name: t, contentType: r, size: n, version: a, open: s }) : k(`an asset file needs a version of 1 to 256 visible ASCII characters other than '"'`);
|
|
663
|
+
}, ho = (e) => {
|
|
664
|
+
if (e === null || typeof e != "object" || e.kind !== "redirect") return ze(e);
|
|
655
665
|
const { url: t } = e;
|
|
656
|
-
if (typeof t != "string" || !URL.canParse(t)) return
|
|
666
|
+
if (typeof t != "string" || !URL.canParse(t)) return k("an asset redirect needs an absolute https URL");
|
|
657
667
|
const r = new URL(t);
|
|
658
|
-
return r.protocol !== "https:" || r.username !== "" || r.password !== "" ?
|
|
659
|
-
},
|
|
660
|
-
if (t === null || typeof t != "object") return
|
|
661
|
-
const { id: r, tone: n, title:
|
|
662
|
-
if (typeof r != "string" || r === "" || typeof
|
|
663
|
-
if (!
|
|
664
|
-
if (
|
|
665
|
-
const
|
|
666
|
-
if (c === void 0) return
|
|
667
|
-
if (c === null || typeof c != "object") return
|
|
668
|
-
const { label:
|
|
669
|
-
return typeof
|
|
670
|
-
}) :
|
|
668
|
+
return r.protocol !== "https:" || r.username !== "" || r.password !== "" ? k("an asset redirect's URL must be https and carry no credentials") : Object.freeze({ kind: "redirect", url: r.href });
|
|
669
|
+
}, yo = (e) => Array.isArray(e) ? e.map((t) => {
|
|
670
|
+
if (t === null || typeof t != "object") return k("a notice must be an object");
|
|
671
|
+
const { id: r, tone: n, title: a, body: s, action: c } = t;
|
|
672
|
+
if (typeof r != "string" || r === "" || typeof a != "string") return k("a notice needs an id and a title");
|
|
673
|
+
if (!ir(n)) return k(`unknown notice tone ${typeof n == "string" ? JSON.stringify(n.slice(0, 64)) : typeof n}`);
|
|
674
|
+
if (s !== void 0 && typeof s != "string") return k("a notice body must be a string");
|
|
675
|
+
const f = { id: r, tone: n, title: a, ...s === void 0 ? {} : { body: s } };
|
|
676
|
+
if (c === void 0) return f;
|
|
677
|
+
if (c === null || typeof c != "object") return k("a notice action must be an object");
|
|
678
|
+
const { label: S, href: h } = c;
|
|
679
|
+
return typeof S != "string" || !ar(h, hr) ? k("a notice action needs a label and an http(s), mailto or relative href") : { ...f, action: { label: S, href: h } };
|
|
680
|
+
}) : k("notices must be an array"), go = 4e3, Te = Object.freeze({ ttlMs: 3e5, maxEntries: 64, maxBytes: 64 * 1024 * 1024 }), lt = 32, Ft = "private, no-store", Eo = Object.freeze({
|
|
671
681
|
"Content-Type": "application/json; charset=utf-8",
|
|
672
|
-
"Cache-Control":
|
|
682
|
+
"Cache-Control": Ft,
|
|
673
683
|
"X-Content-Type-Options": "nosniff",
|
|
674
684
|
"Content-Security-Policy": "default-src 'none'; frame-ancestors 'none'; sandbox",
|
|
675
685
|
"Cross-Origin-Resource-Policy": "same-origin"
|
|
676
|
-
}),
|
|
686
|
+
}), bo = 22, To = 2147483647, Le = Object.freeze([]), ko = Object.freeze({ status: "ok", source: null, ancestors: null }), ft = Object.freeze(["contains", "confirm"]), mt = Object.freeze({ readOnly: !1 }), So = Object.freeze({ readOnly: !0 }), Q = (e, t, r) => {
|
|
677
687
|
if (!(r && t === void 0) && typeof t != "function")
|
|
678
688
|
throw new TypeError(`[markdown-explorer] ${e} must be a function; got ${typeof t}`);
|
|
679
|
-
},
|
|
689
|
+
}, pe = (e, t, r) => {
|
|
680
690
|
if (typeof t != "number") throw new TypeError(`[markdown-explorer] ${e} must be a number; got ${typeof t}`);
|
|
681
691
|
if (!Number.isSafeInteger(t) || t <= 0 || t > r) throw new RangeError(`[markdown-explorer] ${e} must be an integer in 1..${String(r)}; got ${String(t)}`);
|
|
682
692
|
return t;
|
|
683
|
-
},
|
|
693
|
+
}, xo = (e) => {
|
|
684
694
|
if (e === null || typeof e != "object" || !Object.isFrozen(e)) throw new TypeError("[markdown-explorer] config must be the value returned by defineExplorerConfig");
|
|
685
695
|
return Rr(e);
|
|
686
|
-
},
|
|
696
|
+
}, pt = (e) => {
|
|
687
697
|
try {
|
|
688
698
|
return new Headers(e);
|
|
689
699
|
} catch {
|
|
690
700
|
throw new TypeError("[markdown-explorer] authenticate returned headers that are not a valid headers init (their values are not logged)");
|
|
691
701
|
}
|
|
692
|
-
},
|
|
702
|
+
}, wt = (e) => e instanceof Response ? new TypeError(`[markdown-explorer] authenticate threw a Response (status ${String(e.status)}), which a data request does not follow`) : e, Oo = (e) => {
|
|
693
703
|
if (typeof e != "string") throw new TypeError(`[markdown-explorer] scopeSecret must be a string; got ${typeof e}`);
|
|
694
|
-
if (e.length <
|
|
704
|
+
if (e.length < lt) throw new RangeError(`[markdown-explorer] scopeSecret must have at least ${String(lt)} characters; got ${String(e.length)}`);
|
|
695
705
|
return e;
|
|
696
|
-
},
|
|
706
|
+
}, Ro = (e, t) => {
|
|
697
707
|
if (!Ir(t)) throw new TypeError(`[markdown-explorer] ${e}.boundary must be a plain object { contains, confirm? }`);
|
|
698
708
|
for (const r of Object.keys(t))
|
|
699
|
-
if (!
|
|
700
|
-
|
|
701
|
-
},
|
|
709
|
+
if (!ft.includes(r)) throw new RangeError(`[markdown-explorer] ${e}.boundary.${r} is not an option; expected ${ft.join(", ")}`);
|
|
710
|
+
Q(`${e}.boundary.contains`, t.contains, !1), Q(`${e}.boundary.confirm`, t.confirm, !0);
|
|
711
|
+
}, vo = (e) => {
|
|
702
712
|
if (!Array.isArray(e)) throw new TypeError("[markdown-explorer] sources must be an array");
|
|
703
713
|
const t = e;
|
|
704
714
|
if (t.length === 0) throw new RangeError("[markdown-explorer] sources must hold at least one source");
|
|
705
715
|
const r = /* @__PURE__ */ new Set();
|
|
706
|
-
for (const [n,
|
|
707
|
-
if (
|
|
708
|
-
const { id:
|
|
709
|
-
if (!vr(
|
|
710
|
-
throw new RangeError(`[markdown-explorer] sources[${String(n)}].id must use lowercase letters, digits and "-" and start with a letter or digit; got ${typeof
|
|
711
|
-
const
|
|
712
|
-
if (r.has(
|
|
713
|
-
if (r.add(
|
|
714
|
-
if (typeof c == "string" && c.trim() === "") throw new RangeError(`[markdown-explorer] ${
|
|
715
|
-
if (
|
|
716
|
+
for (const [n, a] of t.entries()) {
|
|
717
|
+
if (a === null || typeof a != "object") throw new TypeError(`[markdown-explorer] sources[${String(n)}] must be an object`);
|
|
718
|
+
const { id: s, label: c, boundary: m, tree: f, children: S, ancestors: h, cacheScope: y } = a;
|
|
719
|
+
if (!vr(s))
|
|
720
|
+
throw new RangeError(`[markdown-explorer] sources[${String(n)}].id must use lowercase letters, digits and "-" and start with a letter or digit; got ${typeof s == "string" ? JSON.stringify(s) : typeof s}`);
|
|
721
|
+
const T = `source ${JSON.stringify(s)}`;
|
|
722
|
+
if (r.has(s)) throw new RangeError(`[markdown-explorer] source ids must be unique; ${JSON.stringify(s)} repeats at sources[${String(n)}]`);
|
|
723
|
+
if (r.add(s), typeof c != "string" && typeof c != "function") throw new TypeError(`[markdown-explorer] ${T}.label must be a string or a function`);
|
|
724
|
+
if (typeof c == "string" && c.trim() === "") throw new RangeError(`[markdown-explorer] ${T}.label must not be blank`);
|
|
725
|
+
if (Ro(T, m), Q(`${T}.tree`, f, !1), Q(`${T}.children`, S, !0), Q(`${T}.ancestors`, h, !0), y !== void 0 && y !== "principal" && y !== "shared") throw new RangeError(`[markdown-explorer] ${T}.cacheScope must be "principal" or "shared"; got ${JSON.stringify(y)}`);
|
|
716
726
|
}
|
|
717
727
|
return t;
|
|
718
|
-
},
|
|
728
|
+
}, _o = (e) => {
|
|
719
729
|
if (e === !1) return !1;
|
|
720
|
-
if (e === void 0) return
|
|
730
|
+
if (e === void 0) return Te;
|
|
721
731
|
if (e === null || typeof e != "object") throw new TypeError("[markdown-explorer] treeCache must be { ttlMs, maxEntries, maxBytes } or false");
|
|
722
732
|
const { ttlMs: t, maxEntries: r, maxBytes: n } = e;
|
|
723
733
|
return {
|
|
724
|
-
ttlMs: t === void 0 ?
|
|
725
|
-
maxEntries: r === void 0 ?
|
|
726
|
-
maxBytes: n === void 0 ?
|
|
734
|
+
ttlMs: t === void 0 ? Te.ttlMs : pe("treeCache.ttlMs", t, Number.MAX_SAFE_INTEGER),
|
|
735
|
+
maxEntries: r === void 0 ? Te.maxEntries : pe("treeCache.maxEntries", r, Number.MAX_SAFE_INTEGER),
|
|
736
|
+
maxBytes: n === void 0 ? Te.maxBytes : pe("treeCache.maxBytes", n, Number.MAX_SAFE_INTEGER)
|
|
727
737
|
};
|
|
728
|
-
},
|
|
738
|
+
}, ht = (e) => {
|
|
729
739
|
if (e === null || typeof e != "object") throw new TypeError("[markdown-explorer] authenticate must resolve to { status, ... }");
|
|
730
740
|
const { status: t } = e;
|
|
731
741
|
if (t !== "signed-in" && t !== "signed-out" && t !== "forbidden") throw new TypeError(`[markdown-explorer] authenticate resolved to an unknown status ${JSON.stringify(t)}`);
|
|
732
742
|
return e;
|
|
733
|
-
},
|
|
743
|
+
}, yt = (e, t) => {
|
|
734
744
|
if (!(t instanceof Response)) throw new TypeError(`[markdown-explorer] ${e} must return a Response`);
|
|
735
745
|
return t;
|
|
736
|
-
},
|
|
746
|
+
}, gt = (e, t) => {
|
|
737
747
|
if (typeof t != "string" || t === "") throw new TypeError("[markdown-explorer] principalKey must return a non-empty string");
|
|
738
|
-
return
|
|
739
|
-
},
|
|
748
|
+
return $r("sha256", e).update(t, "utf8").digest("base64url").slice(0, bo);
|
|
749
|
+
}, Ao = (e) => e.view === "multi" ? e.docs : e.doc === null ? [] : [e.doc], ue = (e, t) => {
|
|
740
750
|
const r = e.getAll(t), [n] = r;
|
|
741
751
|
return r.length === 1 && n !== void 0 && n !== "" ? n : null;
|
|
742
|
-
},
|
|
743
|
-
const
|
|
744
|
-
for (const [
|
|
745
|
-
return new Response(t, { status: e, headers:
|
|
746
|
-
},
|
|
747
|
-
const r =
|
|
748
|
-
return r.includes(e.method.toUpperCase()) ? null :
|
|
749
|
-
},
|
|
750
|
-
const [r, ...n] = (e.headers.get("Content-Type") ?? "").split(";").map((
|
|
751
|
-
if (r !==
|
|
752
|
-
const
|
|
753
|
-
if (Number.isFinite(
|
|
752
|
+
}, Z = (e, t, r, n = {}) => {
|
|
753
|
+
const a = new Headers(r);
|
|
754
|
+
for (const [s, c] of Object.entries({ ...Eo, ...n })) a.set(s, c);
|
|
755
|
+
return new Response(t, { status: e, headers: a });
|
|
756
|
+
}, L = (e, t, r) => Z(gr[e.reason], JSON.stringify({ failure: e }), t, r), No = /* @__PURE__ */ new Set(["refresh", "save", "preview"]), Io = /* @__PURE__ */ new Set(["edit", "save", "preview", "revisions", "revision"]), Et = (e, t) => {
|
|
757
|
+
const r = No.has(t) ? ["POST"] : ["GET", "HEAD"];
|
|
758
|
+
return r.includes(e.method.toUpperCase()) ? null : Z(405, JSON.stringify({ failure: { reason: "invalid" } }), void 0, { Allow: r.join(", ") });
|
|
759
|
+
}, bt = (e) => e.headers.get(Ce) === Er && _t(e, At) === void 0, Po = (e) => e.headers.get(Ce) === br && _t(e, At) === void 0, Mo = async (e, t) => {
|
|
760
|
+
const [r, ...n] = (e.headers.get("Content-Type") ?? "").split(";").map((T) => T.trim().toLowerCase()), a = n.find((T) => T.startsWith("charset="));
|
|
761
|
+
if (r !== Sr || a !== void 0 && a !== "charset=utf-8") return { status: "error", failure: { reason: "invalid" } };
|
|
762
|
+
const s = Number(e.headers.get("Content-Length") ?? "0");
|
|
763
|
+
if (Number.isFinite(s) && s > t) return { status: "error", failure: { reason: "too-large" } };
|
|
754
764
|
if (e.body === null) return { status: "ok", text: "" };
|
|
755
765
|
const c = e.body.getReader(), m = [];
|
|
756
|
-
let
|
|
766
|
+
let f = 0;
|
|
757
767
|
for (; ; ) {
|
|
758
|
-
const { done:
|
|
759
|
-
if (
|
|
760
|
-
if (
|
|
768
|
+
const { done: T, value: v } = await c.read();
|
|
769
|
+
if (T) break;
|
|
770
|
+
if (f += v.byteLength, f > t)
|
|
761
771
|
return await c.cancel(), { status: "error", failure: { reason: "too-large" } };
|
|
762
772
|
m.push(v);
|
|
763
773
|
}
|
|
764
|
-
const
|
|
765
|
-
let
|
|
766
|
-
for (const
|
|
767
|
-
|
|
774
|
+
const S = new Uint8Array(f);
|
|
775
|
+
let h = 0;
|
|
776
|
+
for (const T of m)
|
|
777
|
+
S.set(T, h), h += T.byteLength;
|
|
768
778
|
let y;
|
|
769
779
|
try {
|
|
770
|
-
y = new TextDecoder("utf-8", { fatal: !0 }).decode(
|
|
780
|
+
y = new TextDecoder("utf-8", { fatal: !0 }).decode(S);
|
|
771
781
|
} catch {
|
|
772
782
|
return { status: "error", failure: { reason: "invalid" } };
|
|
773
783
|
}
|
|
774
784
|
return y.includes("\0") ? { status: "error", failure: { reason: "invalid" } } : { status: "ok", text: y };
|
|
775
|
-
},
|
|
785
|
+
}, Lo = (e) => {
|
|
776
786
|
if (e === void 0) return;
|
|
777
787
|
if (e === null || typeof e != "object") throw new TypeError("[markdown-explorer] edit must be an object of the editor's ports");
|
|
778
788
|
const t = e;
|
|
779
|
-
for (const r of ["source", "save", "preview", "revisions", "revision"])
|
|
789
|
+
for (const r of ["source", "save", "preview", "revisions", "revision"]) Q(`edit.${r}`, t[r], !1);
|
|
780
790
|
return e;
|
|
781
|
-
},
|
|
782
|
-
const n = new Headers(),
|
|
783
|
-
for (const
|
|
784
|
-
for (const [c, m] of
|
|
791
|
+
}, $o = ({ parentHeaders: e, loaderHeaders: t, errorHeaders: r }) => {
|
|
792
|
+
const n = new Headers(), a = r === void 0 ? [e, t] : [e, t, r];
|
|
793
|
+
for (const s of a)
|
|
794
|
+
for (const [c, m] of s)
|
|
785
795
|
c !== "set-cookie" && n.set(c, m);
|
|
786
796
|
return n;
|
|
787
|
-
},
|
|
797
|
+
}, us = (e) => {
|
|
788
798
|
if (e === null || typeof e != "object") throw new TypeError("[markdown-explorer] the server configuration must be an object");
|
|
789
|
-
const t =
|
|
790
|
-
|
|
791
|
-
const n =
|
|
799
|
+
const t = xo(e.config), r = Oo(e.scopeSecret);
|
|
800
|
+
Q("authenticate", e.authenticate, !1), Q("principalKey", e.principalKey, !1), Q("document", e.document, !1), Q("asset", e.asset, !1), Q("signedOutPage", e.signedOutPage, !1), Q("forbiddenPage", e.forbiddenPage, !0), Q("notices", e.notices, !0), Q("onTreeRefreshed", e.onTreeRefreshed, !0);
|
|
801
|
+
const n = vo(e.sources), a = xr(
|
|
792
802
|
t,
|
|
793
803
|
n.map((o) => o.id)
|
|
794
|
-
),
|
|
795
|
-
if (
|
|
804
|
+
), s = e.logger;
|
|
805
|
+
if (s !== void 0 && (s === null || typeof s != "object" || typeof s.error != "function"))
|
|
796
806
|
throw new TypeError("[markdown-explorer] logger must be an object with an error function");
|
|
797
|
-
const c = e.logger === void 0 ?
|
|
798
|
-
if (
|
|
799
|
-
const y = e.editMaxBytes === void 0 ?
|
|
807
|
+
const c = e.logger === void 0 ? wn : e.logger, m = vt(e.deny), f = e.deferredTimeoutMs === void 0 ? go : pe("deferredTimeoutMs", e.deferredTimeoutMs, To), S = e.textMaxBytes === void 0 ? ot : pe("textMaxBytes", e.textMaxBytes, st), h = Lo(e.edit);
|
|
808
|
+
if (h === void 0 && e.editMaxBytes !== void 0) throw new TypeError("[markdown-explorer] editMaxBytes needs the edit ports");
|
|
809
|
+
const y = e.editMaxBytes === void 0 ? ot : pe("editMaxBytes", e.editMaxBytes, st), T = _o(e.treeCache), v = () => Date.now(), z = T === !1 ? eo(v) : qn({ ...T, now: v }), x = Gn(e.sanitizer, t.multiView.maxPanels), O = Zn({ iframeHosts: t.iframeHosts, dataPath: t.dataPath, options: x, pool: Wn(Yn(), x) }), D = new Map(n.map((o) => [o.id, o])), R = Or(t), { authenticate: I, principalKey: C, signedOutPage: F, forbiddenPage: w, onTreeRefreshed: g } = e, M = (o, u) => {
|
|
800
810
|
if (typeof o.label == "string") return o.label;
|
|
801
|
-
const
|
|
802
|
-
if (typeof
|
|
803
|
-
return
|
|
804
|
-
},
|
|
805
|
-
const
|
|
811
|
+
const i = o.label(u);
|
|
812
|
+
if (typeof i != "string" || i.trim() === "") throw new TypeError(`[markdown-explorer] the label of source ${JSON.stringify(o.id)} must be a non-blank string`);
|
|
813
|
+
return i;
|
|
814
|
+
}, U = (o, u) => o.cacheScope === "shared" ? o.id : `${o.id}\0${u}`, E = (o, u) => {
|
|
815
|
+
const i = (l) => ie(c, { operation: "boundary", sourceId: o.id, path: u, error: l });
|
|
806
816
|
let d;
|
|
807
817
|
try {
|
|
808
818
|
d = o.boundary.contains(u);
|
|
809
819
|
} catch (l) {
|
|
810
|
-
return
|
|
820
|
+
return i(l), !1;
|
|
811
821
|
}
|
|
812
|
-
return typeof d == "boolean" ? d : (
|
|
813
|
-
},
|
|
822
|
+
return typeof d == "boolean" ? d : (nt(d, i), i(new TypeError(`[markdown-explorer] boundary.contains of source ${JSON.stringify(o.id)} must return a boolean; got ${typeof d}`)), !1);
|
|
823
|
+
}, _ = async (o, u, i) => {
|
|
814
824
|
const { confirm: d } = o.boundary;
|
|
815
|
-
if (d === void 0) return { status: "inside", readPath:
|
|
825
|
+
if (d === void 0) return { status: "inside", readPath: i };
|
|
816
826
|
let l;
|
|
817
827
|
try {
|
|
818
|
-
l = await d(u,
|
|
819
|
-
} catch (
|
|
820
|
-
return { status: "error", failure:
|
|
828
|
+
l = await d(u, i);
|
|
829
|
+
} catch (j) {
|
|
830
|
+
return { status: "error", failure: Y(j, { operation: "boundary", sourceId: o.id, path: i }, u.signal, c) };
|
|
821
831
|
}
|
|
822
|
-
const
|
|
823
|
-
if (l === null || typeof l != "object") return
|
|
824
|
-
const { inside: b, readPath:
|
|
825
|
-
return b === !1 ? { status: "outside" } : b !== !0 || typeof
|
|
826
|
-
},
|
|
827
|
-
const
|
|
828
|
-
if (
|
|
829
|
-
if (
|
|
832
|
+
const p = (j) => (ie(c, { operation: "boundary", sourceId: o.id, path: i, error: new TypeError(`[markdown-explorer] boundary.confirm of source ${JSON.stringify(o.id)} ${j}`) }), { status: "outside" });
|
|
833
|
+
if (l === null || typeof l != "object") return p(`must resolve to { inside, readPath? }; got ${l === null ? "null" : typeof l}`);
|
|
834
|
+
const { inside: b, readPath: A } = l;
|
|
835
|
+
return b === !1 ? { status: "outside" } : b !== !0 || typeof A != "string" ? p("must resolve to { inside: false } or { inside: true, readPath: string }") : !re(A) || m.deniesPath(A) ? (ie(c, { operation: "boundary", sourceId: o.id, path: i, error: new RangeError(`[markdown-explorer] boundary.confirm of source ${JSON.stringify(o.id)} answered a readPath the explorer does not serve (unacceptable or denied)`) }), { status: "error", failure: { reason: "failed" } }) : { status: "inside", readPath: A };
|
|
836
|
+
}, N = async (o, u) => {
|
|
837
|
+
const i = n.filter((l) => E(l, u));
|
|
838
|
+
if (i.length === 0) return { status: "error", failure: { reason: "forbidden" } };
|
|
839
|
+
if (i.some((l) => l.boundary.confirm === void 0)) return { status: "inside", readPath: u };
|
|
830
840
|
let d = null;
|
|
831
|
-
for (const l of
|
|
832
|
-
const
|
|
833
|
-
if (
|
|
834
|
-
|
|
841
|
+
for (const l of i) {
|
|
842
|
+
const p = await _(l, o, u);
|
|
843
|
+
if (p.status === "inside") return p;
|
|
844
|
+
p.status === "error" && d === null && (d = p.failure);
|
|
835
845
|
}
|
|
836
846
|
return { status: "error", failure: d === null ? { reason: "forbidden" } : d };
|
|
837
|
-
},
|
|
838
|
-
const d = ({ path: l, reason:
|
|
847
|
+
}, $ = (o, u, i) => {
|
|
848
|
+
const d = ({ path: l, reason: p }) => gn(c, { operation: i.operation, sourceId: i.sourceId, path: l, error: new TypeError(`[markdown-explorer] an entry with ${p} was left out`) });
|
|
839
849
|
try {
|
|
840
|
-
return { status: "ok", entries:
|
|
850
|
+
return { status: "ok", entries: no(o, m, u.children !== void 0, d, (l) => E(u, l)) };
|
|
841
851
|
} catch (l) {
|
|
842
|
-
return
|
|
852
|
+
return ie(c, { ...i, error: l }), { status: "error", failure: { reason: "failed" } };
|
|
843
853
|
}
|
|
844
|
-
},
|
|
854
|
+
}, X = async (o, u, i) => {
|
|
845
855
|
let d;
|
|
846
856
|
try {
|
|
847
857
|
d = await o.tree(u);
|
|
848
|
-
} catch (
|
|
849
|
-
return { status: "error", failure:
|
|
858
|
+
} catch (p) {
|
|
859
|
+
return { status: "error", failure: Y(p, { operation: "tree", sourceId: o.id }, u.signal, c) };
|
|
850
860
|
}
|
|
851
|
-
const l =
|
|
852
|
-
return l.status === "ok" ? { status: "ok", entries: l.entries, loadedAt:
|
|
853
|
-
},
|
|
861
|
+
const l = $(d, o, { operation: "tree", sourceId: o.id });
|
|
862
|
+
return l.status === "ok" ? { status: "ok", entries: l.entries, loadedAt: i } : l;
|
|
863
|
+
}, G = (o, u, i, d) => (l, p) => X(o, { principal: u, request: i, signal: l, refresh: d }, p), P = (o, u, i, d, l) => z.load(U(o, i), l, G(o, u, d, !1)), W = (o, u, i, d) => z.refresh(U(o, i), d.signal, G(o, u, d, !0)), K = (o, u) => {
|
|
854
864
|
if (g === void 0) return;
|
|
855
|
-
const
|
|
865
|
+
const i = (d) => ie(c, { operation: "refresh", sourceId: o.id, error: d });
|
|
856
866
|
try {
|
|
857
|
-
|
|
867
|
+
nt(g(u), i);
|
|
858
868
|
} catch (d) {
|
|
859
|
-
|
|
869
|
+
i(d);
|
|
860
870
|
}
|
|
861
|
-
},
|
|
862
|
-
if (m.deniesPath(d) || !
|
|
863
|
-
const l = await
|
|
871
|
+
}, J = async (o, u, i, d) => {
|
|
872
|
+
if (m.deniesPath(d) || !E(o, d)) return { status: "error", failure: { reason: "forbidden" } };
|
|
873
|
+
const l = await _(o, i, d);
|
|
864
874
|
if (l.status === "outside") return { status: "error", failure: { reason: "forbidden" } };
|
|
865
875
|
if (l.status === "error") return { status: "error", failure: l.failure };
|
|
866
|
-
let
|
|
876
|
+
let p;
|
|
867
877
|
try {
|
|
868
|
-
|
|
878
|
+
p = await u(i, d, l.readPath);
|
|
869
879
|
} catch (b) {
|
|
870
|
-
return { status: "error", failure:
|
|
880
|
+
return { status: "error", failure: Y(b, { operation: "children", sourceId: o.id, path: d }, i.signal, c) };
|
|
871
881
|
}
|
|
872
|
-
return
|
|
873
|
-
},
|
|
874
|
-
const l = await
|
|
882
|
+
return $(p, o, { operation: "children", sourceId: o.id, path: d });
|
|
883
|
+
}, ae = async (o, u, i, d) => {
|
|
884
|
+
const l = await _(o, i, d);
|
|
875
885
|
if (l.status === "outside") return { status: "ok", ancestors: null };
|
|
876
886
|
if (l.status === "error") return { status: "error", failure: l.failure };
|
|
877
|
-
let
|
|
887
|
+
let p;
|
|
878
888
|
try {
|
|
879
|
-
|
|
889
|
+
p = await u(i, d, l.readPath, { maxDepth: t.revealDocument.maxDepth });
|
|
880
890
|
} catch (b) {
|
|
881
|
-
return { status: "error", failure:
|
|
891
|
+
return { status: "error", failure: Y(b, { operation: "ancestors", sourceId: o.id, path: d }, i.signal, c) };
|
|
882
892
|
}
|
|
883
|
-
if (Array.isArray(
|
|
893
|
+
if (Array.isArray(p) && p.length > t.revealDocument.maxDepth) return { status: "ok", ancestors: null };
|
|
884
894
|
try {
|
|
885
|
-
return { status: "ok", ancestors:
|
|
895
|
+
return { status: "ok", ancestors: ro(p, d, m, (b) => E(o, b)) };
|
|
886
896
|
} catch (b) {
|
|
887
|
-
return
|
|
897
|
+
return ie(c, { operation: "ancestors", sourceId: o.id, path: d, error: b }), { status: "error", failure: { reason: "failed" } };
|
|
888
898
|
}
|
|
889
|
-
},
|
|
890
|
-
if (m.deniesPath(
|
|
899
|
+
}, H = async (o, u, i, d) => m.deniesPath(d) ? { status: "error", failure: { reason: "forbidden" } } : E(o, d) ? ae(o, u, i, d) : { status: "ok", ancestors: null }, te = async (o, u, i) => {
|
|
900
|
+
if (m.deniesPath(i)) return { status: "error", failure: { reason: "forbidden" } };
|
|
891
901
|
for (const d of [o, ...n.filter((l) => l !== o)]) {
|
|
892
902
|
if (u.signal.aborted) break;
|
|
893
903
|
const l = d.ancestors;
|
|
894
|
-
if (l === void 0 || !
|
|
895
|
-
const
|
|
896
|
-
if (
|
|
904
|
+
if (l === void 0 || !E(d, i)) continue;
|
|
905
|
+
const p = await ae(d, l, u, i);
|
|
906
|
+
if (p.status === "ok" && p.ancestors !== null) return { status: "ok", source: d.id, ancestors: p.ancestors };
|
|
897
907
|
}
|
|
898
|
-
return
|
|
899
|
-
},
|
|
900
|
-
if (m.deniesPath(
|
|
901
|
-
const d = await
|
|
908
|
+
return ko;
|
|
909
|
+
}, q = async (o, u, i) => {
|
|
910
|
+
if (m.deniesPath(i)) return ee("forbidden");
|
|
911
|
+
const d = await N(o, i);
|
|
902
912
|
if (d.status === "error") return { kind: "failure", failure: d.failure };
|
|
903
913
|
let l;
|
|
904
914
|
try {
|
|
905
|
-
l = await e.document(o,
|
|
906
|
-
} catch (
|
|
907
|
-
return { kind: "failure", failure:
|
|
915
|
+
l = await e.document(o, i, d.readPath);
|
|
916
|
+
} catch (A) {
|
|
917
|
+
return { kind: "failure", failure: Y(A, { operation: "document", path: i }, o.signal, c) };
|
|
908
918
|
}
|
|
909
|
-
let
|
|
919
|
+
let p;
|
|
910
920
|
try {
|
|
911
|
-
|
|
912
|
-
} catch (
|
|
913
|
-
return
|
|
921
|
+
p = ao(l, (A) => Ge(t.dataPath, i, A), h !== void 0);
|
|
922
|
+
} catch (A) {
|
|
923
|
+
return ie(c, { operation: "document", path: i, error: A }), ee("failed");
|
|
914
924
|
}
|
|
915
|
-
if (
|
|
916
|
-
const b = await
|
|
917
|
-
return b.status === "sanitized" ? { kind: "markdown", name:
|
|
918
|
-
},
|
|
919
|
-
if (e.notices === void 0) return
|
|
925
|
+
if (p.kind !== "unsanitized-markdown") return p;
|
|
926
|
+
const b = await O(p.html, { scope: u, signal: o.signal });
|
|
927
|
+
return b.status === "sanitized" ? { kind: "markdown", name: p.name, htmlContent: b.html, headings: p.headings, edit: p.edit } : (b.cause !== null && ie(c, { operation: "document", path: i, error: b.cause }), ee(b.reason));
|
|
928
|
+
}, ne = async (o) => {
|
|
929
|
+
if (e.notices === void 0) return Le;
|
|
920
930
|
try {
|
|
921
|
-
return
|
|
931
|
+
return yo(await e.notices(o));
|
|
922
932
|
} catch (u) {
|
|
923
|
-
return
|
|
933
|
+
return Y(u, { operation: "notices" }, o.signal, c), Le;
|
|
924
934
|
}
|
|
925
|
-
},
|
|
926
|
-
const d =
|
|
927
|
-
if (d === null || !
|
|
928
|
-
const l =
|
|
929
|
-
if (l === null) return
|
|
935
|
+
}, de = async (o, u, i) => {
|
|
936
|
+
const d = ue(u, ce.path);
|
|
937
|
+
if (d === null || !re(d)) return L({ reason: "invalid" }, i);
|
|
938
|
+
const l = kr(u);
|
|
939
|
+
if (l === null) return L({ reason: "invalid" }, i);
|
|
930
940
|
if (m.deniesPath(d))
|
|
931
|
-
return
|
|
932
|
-
const
|
|
933
|
-
if (
|
|
941
|
+
return Ie(c, { operation: "asset", path: d }), L({ reason: "forbidden" }, i);
|
|
942
|
+
const p = await N(o, d);
|
|
943
|
+
if (p.status === "error") return L(p.failure, i);
|
|
934
944
|
try {
|
|
935
|
-
const b = l === "file",
|
|
936
|
-
return "kind" in
|
|
945
|
+
const b = l === "file", A = await e.asset(o, d, p.readPath, { redirect: b }), j = b ? ho(A) : ze(A);
|
|
946
|
+
return "kind" in j ? pn(j.url, i) : await fn(o.request, j, i, l);
|
|
937
947
|
} catch (b) {
|
|
938
|
-
return
|
|
948
|
+
return L(Y(b, { operation: "asset", path: d }, o.signal, c), i);
|
|
939
949
|
}
|
|
940
|
-
},
|
|
950
|
+
}, Ee = async (o, u) => {
|
|
941
951
|
if (m.deniesPath(u))
|
|
942
|
-
return
|
|
943
|
-
const
|
|
944
|
-
if (
|
|
952
|
+
return Ie(c, { operation: "text", path: u }), ee("forbidden");
|
|
953
|
+
const i = await N(o, u);
|
|
954
|
+
if (i.status === "error") return { kind: "failure", failure: i.failure };
|
|
945
955
|
try {
|
|
946
|
-
const d =
|
|
947
|
-
return l === null ?
|
|
956
|
+
const d = ze(await e.asset(o, u, i.readPath, { redirect: !1 })), l = await bn(d, S, t.legacyTextEncoding);
|
|
957
|
+
return l === null ? ee("unsupported") : { kind: "text", name: d.name, text: l.text, truncated: l.truncated, url: Ge(t.dataPath, u, d.version) };
|
|
948
958
|
} catch (d) {
|
|
949
|
-
return { kind: "failure", failure:
|
|
959
|
+
return { kind: "failure", failure: Y(d, { operation: "text", path: u }, o.signal, c) };
|
|
950
960
|
}
|
|
951
|
-
},
|
|
952
|
-
const d = await
|
|
961
|
+
}, he = async (o, u, i) => m.deniesPath(i) ? (Ie(c, { operation: u, path: i }), { status: "error", failure: { reason: "forbidden" } }) : N(o, i), Kt = async (o, u, i) => {
|
|
962
|
+
const d = await he(u, "edit", i);
|
|
953
963
|
if (d.status === "error") return { kind: "failure", failure: d.failure };
|
|
954
964
|
try {
|
|
955
|
-
return
|
|
965
|
+
return lo(await o.source(u, i, d.readPath), y);
|
|
956
966
|
} catch (l) {
|
|
957
|
-
return { kind: "failure", failure:
|
|
967
|
+
return { kind: "failure", failure: Y(l, { operation: "edit", path: i }, u.signal, c) };
|
|
958
968
|
}
|
|
959
|
-
},
|
|
960
|
-
const
|
|
961
|
-
if (
|
|
969
|
+
}, Vt = async (o, u, i, d, l) => {
|
|
970
|
+
const p = await he(u, "save", i);
|
|
971
|
+
if (p.status === "error") return { kind: "failure", failure: p.failure };
|
|
962
972
|
try {
|
|
963
|
-
return
|
|
973
|
+
return fo(await o.save(u, i, p.readPath, { text: l, baseVersion: d }), y);
|
|
964
974
|
} catch (b) {
|
|
965
|
-
return { kind: "failure", failure:
|
|
975
|
+
return { kind: "failure", failure: Y(b, { operation: "save", path: i }, u.signal, c) };
|
|
966
976
|
}
|
|
967
|
-
},
|
|
968
|
-
const
|
|
969
|
-
if (
|
|
977
|
+
}, Zt = async (o, u, i, d, l) => {
|
|
978
|
+
const p = await he(u, "preview", d);
|
|
979
|
+
if (p.status === "error") return { kind: "failure", failure: p.failure };
|
|
970
980
|
let b;
|
|
971
981
|
try {
|
|
972
|
-
b =
|
|
973
|
-
} catch (
|
|
974
|
-
return { kind: "failure", failure:
|
|
982
|
+
b = mo(await o.preview(u, d, p.readPath, l));
|
|
983
|
+
} catch (j) {
|
|
984
|
+
return { kind: "failure", failure: Y(j, { operation: "preview", path: d }, u.signal, c) };
|
|
975
985
|
}
|
|
976
|
-
if ("kind" in b) return b.kind === "failure" ? b :
|
|
977
|
-
const
|
|
978
|
-
return
|
|
979
|
-
},
|
|
980
|
-
const d = await
|
|
986
|
+
if ("kind" in b) return b.kind === "failure" ? b : ee("failed");
|
|
987
|
+
const A = await O(b.html, { scope: i, signal: u.signal });
|
|
988
|
+
return A.status === "sanitized" ? { kind: "preview", htmlContent: A.html, headings: b.headings } : (A.cause !== null && ie(c, { operation: "preview", path: d, error: A.cause }), ee(A.reason));
|
|
989
|
+
}, Qt = async (o, u, i) => {
|
|
990
|
+
const d = await he(u, "revisions", i);
|
|
981
991
|
if (d.status === "error") return { kind: "failure", failure: d.failure };
|
|
982
992
|
try {
|
|
983
|
-
return { kind: "revisions", revisions:
|
|
993
|
+
return { kind: "revisions", revisions: po(await o.revisions(u, i, d.readPath)) };
|
|
984
994
|
} catch (l) {
|
|
985
|
-
return { kind: "failure", failure:
|
|
995
|
+
return { kind: "failure", failure: Y(l, { operation: "revisions", path: i }, u.signal, c) };
|
|
986
996
|
}
|
|
987
|
-
},
|
|
988
|
-
const l = await
|
|
997
|
+
}, qt = async (o, u, i, d) => {
|
|
998
|
+
const l = await he(u, "revision", i);
|
|
989
999
|
if (l.status === "error") return { kind: "failure", failure: l.failure };
|
|
990
1000
|
try {
|
|
991
|
-
return { kind: "revision", id: d, text:
|
|
992
|
-
} catch (
|
|
993
|
-
return { kind: "failure", failure:
|
|
1001
|
+
return { kind: "revision", id: d, text: wo(await o.revision(u, i, l.readPath, d), y) };
|
|
1002
|
+
} catch (p) {
|
|
1003
|
+
return { kind: "failure", failure: Y(p, { operation: "revision", path: i }, u.signal, c) };
|
|
994
1004
|
}
|
|
995
|
-
},
|
|
996
|
-
const b =
|
|
997
|
-
if (b === null || !
|
|
998
|
-
if (u === "edit") return
|
|
999
|
-
if (u === "revisions") return
|
|
1005
|
+
}, er = async (o, u, i, d, l, p) => {
|
|
1006
|
+
const b = ue(l, ce.path);
|
|
1007
|
+
if (b === null || !re(b)) return L({ reason: "invalid" }, p);
|
|
1008
|
+
if (u === "edit") return Z(200, JSON.stringify(await Kt(o, i, b)), p);
|
|
1009
|
+
if (u === "revisions") return Z(200, JSON.stringify(await Qt(o, i, b)), p);
|
|
1000
1010
|
if (u === "revision") {
|
|
1001
|
-
const
|
|
1002
|
-
return
|
|
1011
|
+
const oe = ue(l, ce.revision);
|
|
1012
|
+
return ge(oe) ? Z(200, JSON.stringify(await qt(o, i, b, oe)), p) : L({ reason: "invalid" }, p);
|
|
1003
1013
|
}
|
|
1004
|
-
const
|
|
1005
|
-
if (u === "save" && !
|
|
1006
|
-
const
|
|
1007
|
-
return
|
|
1008
|
-
},
|
|
1009
|
-
const d =
|
|
1010
|
-
if (l.set("Cache-Control",
|
|
1011
|
-
if (d.status === "forbidden") throw
|
|
1012
|
-
const
|
|
1013
|
-
if (
|
|
1014
|
-
const { location: b } =
|
|
1015
|
-
if (
|
|
1016
|
-
const
|
|
1017
|
-
scope:
|
|
1018
|
-
sources: n.map((B) => ({ id: B.id, label:
|
|
1019
|
-
settings: Ar(Nr(o.headers.get("Cookie"), t.settingsCookie),
|
|
1014
|
+
const A = ue(l, ce.base);
|
|
1015
|
+
if (u === "save" && !ge(A)) return L({ reason: "invalid" }, p);
|
|
1016
|
+
const j = await Mo(i.request, y);
|
|
1017
|
+
return j.status === "error" ? L(j.failure, p) : u === "preview" ? Z(200, JSON.stringify(await Zt(o, i, d, b, j.text)), p) : Z(200, JSON.stringify(await Vt(o, i, b, A, j.text)), p);
|
|
1018
|
+
}, tr = async ({ request: o, url: u, params: i }) => {
|
|
1019
|
+
const d = ht(await I(o, mt)), l = pt(d.headers);
|
|
1020
|
+
if (l.set("Cache-Control", Ft), d.status === "signed-out") throw yt("signedOutPage", F(o, l));
|
|
1021
|
+
if (d.status === "forbidden") throw w === void 0 ? Ye(null, { status: 403, headers: l }) : yt("forbiddenPage", w(o, l));
|
|
1022
|
+
const p = _r(a, i["*"], u.searchParams);
|
|
1023
|
+
if (p.kind === "redirect") throw zr(p.href, { headers: l });
|
|
1024
|
+
const { location: b } = p, { principal: A } = d, j = gt(r, C(A)), oe = D.get(b.source);
|
|
1025
|
+
if (oe === void 0) throw new RangeError(`[markdown-explorer] no source for ${JSON.stringify(b.source)}`);
|
|
1026
|
+
const ye = { signal: o.signal, timeoutMs: f, late: null, handOverMs: f }, se = {
|
|
1027
|
+
scope: j,
|
|
1028
|
+
sources: n.map((B) => ({ id: B.id, label: M(B, A) })),
|
|
1029
|
+
settings: Ar(Nr(o.headers.get("Cookie"), t.settingsCookie), R),
|
|
1020
1030
|
tree: b.view === "single" ? null : {
|
|
1021
1031
|
sourceId: b.source,
|
|
1022
|
-
result:
|
|
1032
|
+
result: Ne(ye, (B) => P(oe, A, j, o, B).then((V) => V.result))
|
|
1023
1033
|
},
|
|
1024
|
-
documents:
|
|
1025
|
-
notices:
|
|
1034
|
+
documents: Ao(b).map((B) => ({ path: B, document: Ne(ye, (V) => q({ principal: A, request: o, signal: V, refresh: !1 }, j, B)) })),
|
|
1035
|
+
notices: Ne({ signal: o.signal, timeoutMs: f, late: Le, handOverMs: 0 }, (B) => ne({ principal: A, request: o, signal: B, refresh: !1 }))
|
|
1026
1036
|
};
|
|
1027
|
-
return
|
|
1028
|
-
},
|
|
1029
|
-
const
|
|
1030
|
-
return { authentication:
|
|
1031
|
-
},
|
|
1037
|
+
return Ye(se, { headers: l });
|
|
1038
|
+
}, Fe = async (o, u) => {
|
|
1039
|
+
const i = ht(await I(o, u));
|
|
1040
|
+
return { authentication: i, headers: pt(i.headers) };
|
|
1041
|
+
}, rr = async (o, u, i) => {
|
|
1032
1042
|
let d;
|
|
1033
1043
|
try {
|
|
1034
|
-
d = await
|
|
1035
|
-
} catch (
|
|
1036
|
-
return
|
|
1044
|
+
d = await Fe(u, mt);
|
|
1045
|
+
} catch (V) {
|
|
1046
|
+
return L(Y(wt(V), { operation: "authenticate" }, u.signal, c));
|
|
1037
1047
|
}
|
|
1038
|
-
const { authentication: l, headers:
|
|
1039
|
-
if (l.status === "signed-out") return
|
|
1040
|
-
if (l.status === "forbidden") return
|
|
1048
|
+
const { authentication: l, headers: p } = d;
|
|
1049
|
+
if (l.status === "signed-out") return L({ reason: "unauthorized" }, p);
|
|
1050
|
+
if (l.status === "forbidden") return L({ reason: "forbidden" }, p);
|
|
1041
1051
|
const { principal: b } = l;
|
|
1042
|
-
if (o === "asset") return
|
|
1043
|
-
const
|
|
1044
|
-
|
|
1045
|
-
const
|
|
1052
|
+
if (o === "asset") return de({ principal: b, request: u, signal: u.signal, refresh: !1 }, i, p);
|
|
1053
|
+
const A = gt(r, C(b));
|
|
1054
|
+
p.set(Tr, A);
|
|
1055
|
+
const j = { principal: b, request: u, signal: u.signal, refresh: !1 }, oe = () => L({ reason: "invalid" }, p);
|
|
1046
1056
|
if (o === "document") {
|
|
1047
|
-
const
|
|
1048
|
-
if (
|
|
1049
|
-
const
|
|
1050
|
-
return
|
|
1057
|
+
const V = ue(i, ce.path);
|
|
1058
|
+
if (V === null || !re(V)) return oe();
|
|
1059
|
+
const Je = u.headers.has(Ce);
|
|
1060
|
+
return Je && !bt(u) ? L({ reason: "forbidden" }, p) : Z(200, JSON.stringify(await q({ ...j, refresh: Je }, A, V)), p);
|
|
1051
1061
|
}
|
|
1052
1062
|
if (o === "text") {
|
|
1053
|
-
const
|
|
1054
|
-
return
|
|
1063
|
+
const V = ue(i, ce.path);
|
|
1064
|
+
return V === null || !re(V) ? oe() : Z(200, JSON.stringify(await Ee(j, V)), p);
|
|
1055
1065
|
}
|
|
1056
1066
|
if (o === "edit" || o === "save" || o === "preview" || o === "revisions" || o === "revision")
|
|
1057
|
-
return
|
|
1058
|
-
const
|
|
1059
|
-
if (
|
|
1060
|
-
const B = D.get(
|
|
1061
|
-
if (B === void 0) return
|
|
1062
|
-
if (o === "tree") return
|
|
1067
|
+
return h === void 0 ? L({ reason: "not-found" }, p) : er(h, o, j, A, i, p);
|
|
1068
|
+
const ye = ue(i, ce.source), se = ue(i, ce.path);
|
|
1069
|
+
if (ye === null || (o === "children" || o === "ancestors" || o === "reveal") && (se === null || !re(se))) return oe();
|
|
1070
|
+
const B = D.get(ye);
|
|
1071
|
+
if (B === void 0) return L({ reason: "not-found" }, p);
|
|
1072
|
+
if (o === "tree") return Z(200, (await P(B, b, A, u, u.signal)).json, p);
|
|
1063
1073
|
if (o === "refresh") {
|
|
1064
|
-
const
|
|
1065
|
-
return u.signal.aborted ||
|
|
1074
|
+
const V = await W(B, b, A, u);
|
|
1075
|
+
return u.signal.aborted || K(B, U(B, A)), Z(200, V.json, p);
|
|
1066
1076
|
}
|
|
1067
|
-
return o === "ancestors" ? B.ancestors === void 0 ||
|
|
1068
|
-
},
|
|
1069
|
-
const { authentication: u, headers:
|
|
1070
|
-
if (!
|
|
1077
|
+
return o === "ancestors" ? B.ancestors === void 0 || se === null ? L({ reason: "not-found" }, p) : Z(200, JSON.stringify(await H(B, B.ancestors, j, se)), p) : o === "reveal" ? se === null ? oe() : Z(200, JSON.stringify(await te(B, j, se)), p) : B.children === void 0 || se === null ? L({ reason: "not-found" }, p) : Z(200, JSON.stringify(await J(B, B.children, j, se)), p);
|
|
1078
|
+
}, nr = async (o) => {
|
|
1079
|
+
const { authentication: u, headers: i } = await Fe(o, So);
|
|
1080
|
+
if (!i.keys().next().done) throw new TypeError("[markdown-explorer] authenticate returned headers in read-only mode; a read-only authentication must only read the session (none was forwarded)");
|
|
1071
1081
|
return u.status === "signed-in";
|
|
1072
|
-
},
|
|
1082
|
+
}, Ue = t.embeds.linkCardEndpoint === null ? null : jr({ authorize: nr }), or = async (o, u) => {
|
|
1073
1083
|
try {
|
|
1074
1084
|
return await o(u);
|
|
1075
|
-
} catch (
|
|
1076
|
-
return
|
|
1085
|
+
} catch (i) {
|
|
1086
|
+
return L(Y(wt(i), { operation: "authenticate" }, u.signal, c));
|
|
1077
1087
|
}
|
|
1078
|
-
},
|
|
1079
|
-
if (new URL(o.url).pathname.endsWith(".data")) return
|
|
1080
|
-
if (!
|
|
1081
|
-
if (
|
|
1082
|
-
if (
|
|
1083
|
-
const l =
|
|
1084
|
-
return l !== null ? l :
|
|
1088
|
+
}, Xe = async (o, u, i) => {
|
|
1089
|
+
if (new URL(o.url).pathname.endsWith(".data")) return L({ reason: "not-found" });
|
|
1090
|
+
if (!yr(i)) return L({ reason: "not-found" });
|
|
1091
|
+
if (i === "link-card") {
|
|
1092
|
+
if (Ue === null) return L({ reason: "not-found" });
|
|
1093
|
+
const l = Et(o, i);
|
|
1094
|
+
return l !== null ? l : or(Ue, o);
|
|
1085
1095
|
}
|
|
1086
|
-
if (
|
|
1087
|
-
const d =
|
|
1096
|
+
if (Io.has(i) && h === void 0) return L({ reason: "not-found" });
|
|
1097
|
+
const d = Et(o, i);
|
|
1088
1098
|
if (d !== null) return d;
|
|
1089
|
-
if (
|
|
1090
|
-
if ((
|
|
1099
|
+
if (i === "refresh" && !bt(o)) return L({ reason: "forbidden" });
|
|
1100
|
+
if ((i === "save" || i === "preview") && !Po(o)) return L({ reason: "forbidden" });
|
|
1091
1101
|
try {
|
|
1092
|
-
return await
|
|
1102
|
+
return await rr(i, o, u.searchParams);
|
|
1093
1103
|
} catch (l) {
|
|
1094
|
-
return
|
|
1104
|
+
return L(Y(l, { operation: i }, o.signal, c));
|
|
1095
1105
|
}
|
|
1096
1106
|
};
|
|
1097
1107
|
return Object.freeze({
|
|
1098
|
-
loader:
|
|
1099
|
-
headers:
|
|
1100
|
-
dataLoader: ({ request: o, url: u, params:
|
|
1101
|
-
dataAction: ({ request: o, url: u, params:
|
|
1108
|
+
loader: tr,
|
|
1109
|
+
headers: $o,
|
|
1110
|
+
dataLoader: ({ request: o, url: u, params: i }) => Xe(o, u, i["*"]),
|
|
1111
|
+
dataAction: ({ request: o, url: u, params: i }) => Xe(o, u, i["*"]),
|
|
1102
1112
|
forgetTree: (o) => {
|
|
1103
1113
|
if (typeof o != "string") throw new TypeError(`[markdown-explorer] forgetTree needs the string key onTreeRefreshed received; got ${typeof o}`);
|
|
1104
|
-
|
|
1114
|
+
z.forget(o);
|
|
1105
1115
|
}
|
|
1106
1116
|
});
|
|
1107
|
-
},
|
|
1117
|
+
}, ke = Object.freeze({ maxEntries: 2e4, maxDocumentBytes: 2 * 1024 * 1024, textPreviewBytes: 8 * 1024, walkConcurrency: 8 }), jo = /* @__PURE__ */ new Set(["md", "markdown", "mdx"]), Tt = "image/svg+xml", Ut = new Map([
|
|
1108
1118
|
...[
|
|
1109
1119
|
["png", "image/png"],
|
|
1110
1120
|
["jpg", "image/jpeg"],
|
|
1111
1121
|
["jpeg", "image/jpeg"],
|
|
1112
1122
|
["gif", "image/gif"],
|
|
1113
|
-
["svg",
|
|
1123
|
+
["svg", Tt],
|
|
1114
1124
|
["webp", "image/webp"],
|
|
1115
1125
|
["ico", "image/x-icon"],
|
|
1116
1126
|
["bmp", "image/bmp"],
|
|
1117
1127
|
["tif", "image/tiff"],
|
|
1118
1128
|
["tiff", "image/tiff"],
|
|
1119
1129
|
["avif", "image/avif"]
|
|
1120
|
-
].map(([e, t]) => [e, { kind: "image", contentType: t }]),
|
|
1130
|
+
].map(([e, t]) => [e, { kind: "image", imageType: t === Tt ? "svg" : "raster", contentType: t }]),
|
|
1121
1131
|
...[
|
|
1122
1132
|
["mp4", "video/mp4"],
|
|
1123
1133
|
["m4v", "video/mp4"],
|
|
@@ -1139,12 +1149,14 @@ const ln = (e) => e instanceof Error && Object.hasOwn(e, Pt) && Tt(e.reason), fn
|
|
|
1139
1149
|
["wma", "audio/x-ms-wma"]
|
|
1140
1150
|
].map(([e, t]) => [e, { kind: "media", mediaType: "audio", contentType: t }]),
|
|
1141
1151
|
["pdf", { kind: "media", mediaType: "pdf", contentType: "application/pdf" }]
|
|
1142
|
-
]),
|
|
1152
|
+
]), zo = /* @__PURE__ */ new Map([
|
|
1153
|
+
["csv", "csv"],
|
|
1154
|
+
["tsv", "tsv"],
|
|
1155
|
+
["tab", "tsv"]
|
|
1156
|
+
]), Do = /* @__PURE__ */ new Set([
|
|
1143
1157
|
"txt",
|
|
1144
1158
|
"text",
|
|
1145
1159
|
"log",
|
|
1146
|
-
"csv",
|
|
1147
|
-
"tsv",
|
|
1148
1160
|
"json",
|
|
1149
1161
|
"jsonc",
|
|
1150
1162
|
"json5",
|
|
@@ -1264,7 +1276,7 @@ const ln = (e) => e instanceof Error && Object.hasOwn(e, Pt) && Tt(e.reason), fn
|
|
|
1264
1276
|
"eslintrc",
|
|
1265
1277
|
"babelrc",
|
|
1266
1278
|
"mailmap"
|
|
1267
|
-
]),
|
|
1279
|
+
]), Co = /* @__PURE__ */ new Set([
|
|
1268
1280
|
"readme",
|
|
1269
1281
|
"license",
|
|
1270
1282
|
"licence",
|
|
@@ -1285,17 +1297,19 @@ const ln = (e) => e instanceof Error && Object.hasOwn(e, Pt) && Tt(e.reason), fn
|
|
|
1285
1297
|
"jenkinsfile",
|
|
1286
1298
|
"brewfile",
|
|
1287
1299
|
"codeowners"
|
|
1288
|
-
]),
|
|
1300
|
+
]), Xt = typeof we.O_NOFOLLOW == "number" ? we.O_NOFOLLOW : 0, Jt = typeof we.O_NONBLOCK == "number" ? we.O_NONBLOCK : 0, kt = (e) => `${e.size}-${e.mtimeNs}`, Ho = (e) => e !== "" && e !== "." && e !== ".." && !e.includes(":") && !e.endsWith(".") && !e.endsWith(" "), St = (e) => re(e) && e === e.normalize("NFC") && e.split("/").every(Ho), Gt = (e) => {
|
|
1289
1301
|
const t = e.toLowerCase(), r = t.lastIndexOf(".");
|
|
1290
1302
|
return r < 0 ? "" : t.slice(r + 1);
|
|
1291
|
-
},
|
|
1292
|
-
const t =
|
|
1293
|
-
if (
|
|
1294
|
-
const r =
|
|
1295
|
-
if (r !== void 0) return r.kind === "image" ? { kind: "image" } : { kind: "media", mediaType: r.mediaType };
|
|
1296
|
-
const n =
|
|
1297
|
-
|
|
1298
|
-
|
|
1303
|
+
}, Bo = (e) => {
|
|
1304
|
+
const t = Gt(e);
|
|
1305
|
+
if (jo.has(t)) return { kind: "markdown" };
|
|
1306
|
+
const r = Ut.get(t);
|
|
1307
|
+
if (r !== void 0) return r.kind === "image" ? { kind: "image", imageType: r.imageType } : { kind: "media", mediaType: r.mediaType };
|
|
1308
|
+
const n = zo.get(t);
|
|
1309
|
+
if (n !== void 0) return { kind: "spreadsheet", format: n };
|
|
1310
|
+
const a = e.toLowerCase();
|
|
1311
|
+
return Do.has(t) || !a.includes(".") && Co.has(a) ? { kind: "text" } : { kind: "file" };
|
|
1312
|
+
}, De = (e) => {
|
|
1299
1313
|
switch (typeof e == "object" && e !== null ? e.code : void 0) {
|
|
1300
1314
|
case "ENOENT":
|
|
1301
1315
|
case "ENOTDIR":
|
|
@@ -1311,226 +1325,230 @@ const ln = (e) => e instanceof Error && Object.hasOwn(e, Pt) && Tt(e.reason), fn
|
|
|
1311
1325
|
default:
|
|
1312
1326
|
return null;
|
|
1313
1327
|
}
|
|
1314
|
-
},
|
|
1315
|
-
const t =
|
|
1316
|
-
return t === null ? e : new
|
|
1317
|
-
},
|
|
1328
|
+
}, Yt = (e) => {
|
|
1329
|
+
const t = De(e);
|
|
1330
|
+
return t === null ? e : new Oe(t);
|
|
1331
|
+
}, Wt = (e) => {
|
|
1318
1332
|
const t = typeof e == "object" && e !== null ? e.code : void 0;
|
|
1319
1333
|
return t === "EACCES" || t === "EPERM" || t === "ENOENT" || t === "ENOTDIR";
|
|
1320
|
-
},
|
|
1334
|
+
}, Fo = async (e) => {
|
|
1321
1335
|
try {
|
|
1322
|
-
return Math.trunc((await
|
|
1336
|
+
return Math.trunc((await It(e)).mtimeMs);
|
|
1323
1337
|
} catch (t) {
|
|
1324
|
-
if (
|
|
1338
|
+
if (Wt(t)) return;
|
|
1325
1339
|
throw t;
|
|
1326
1340
|
}
|
|
1327
|
-
},
|
|
1341
|
+
}, xt = async (e, t) => {
|
|
1328
1342
|
const r = [];
|
|
1329
1343
|
for await (const n of e.createReadStream({ start: 0, end: t - 1, autoClose: !1 }))
|
|
1330
1344
|
r.push(n);
|
|
1331
1345
|
return Buffer.concat(r);
|
|
1332
|
-
},
|
|
1333
|
-
let
|
|
1346
|
+
}, Uo = (e, t) => e !== null ? { start: e.offset, end: e.offset + e.length - 1 } : t === 0n ? {} : { start: 0, end: Number(t) - 1 }, Xo = async (e, t, r, n) => {
|
|
1347
|
+
let a;
|
|
1334
1348
|
try {
|
|
1335
|
-
|
|
1336
|
-
const
|
|
1337
|
-
if (!
|
|
1338
|
-
} catch (
|
|
1339
|
-
throw await
|
|
1349
|
+
a = await Nt(e, we.O_RDONLY | Xt | Jt);
|
|
1350
|
+
const f = await a.stat({ bigint: !0 });
|
|
1351
|
+
if (!f.isFile() || f.ino !== t.ino || f.dev !== t.dev || f.size !== t.size || f.mtimeNs !== t.mtimeNs) throw new Oe("not-found");
|
|
1352
|
+
} catch (f) {
|
|
1353
|
+
throw await a?.close(), Yt(f);
|
|
1340
1354
|
}
|
|
1341
|
-
const
|
|
1342
|
-
|
|
1355
|
+
const s = a.createReadStream(Uo(r, t.size)), c = Gr.toWeb(s), m = () => {
|
|
1356
|
+
s.destroy(n.reason);
|
|
1343
1357
|
};
|
|
1344
1358
|
return n.aborted ? m() : n.addEventListener("abort", m, { once: !0 }), c;
|
|
1345
|
-
},
|
|
1346
|
-
const r =
|
|
1359
|
+
}, Jo = (e, t) => {
|
|
1360
|
+
const r = Mr.compare(e, t);
|
|
1347
1361
|
return r !== 0 ? r : e === t ? 0 : e < t ? -1 : 1;
|
|
1348
|
-
},
|
|
1362
|
+
}, Go = (e) => {
|
|
1349
1363
|
let t = 0;
|
|
1350
1364
|
const r = [];
|
|
1351
1365
|
return async (n) => {
|
|
1352
|
-
t < e ? t += 1 : await new Promise((
|
|
1366
|
+
t < e ? t += 1 : await new Promise((a) => r.push(a));
|
|
1353
1367
|
try {
|
|
1354
1368
|
return await n();
|
|
1355
1369
|
} finally {
|
|
1356
|
-
const
|
|
1357
|
-
|
|
1370
|
+
const a = r.shift();
|
|
1371
|
+
a === void 0 ? t -= 1 : a();
|
|
1358
1372
|
}
|
|
1359
1373
|
};
|
|
1360
|
-
},
|
|
1374
|
+
}, Yo = (e, t) => {
|
|
1361
1375
|
if (e.isSymbolicLink()) return "symbolic-link";
|
|
1362
1376
|
if (!(e.isDirectory() || e.isFile())) return "special-file";
|
|
1363
1377
|
const { name: r } = e;
|
|
1364
|
-
return r !== r.normalize("NFC") ? "not-nfc" : r.includes(":") ? "colon" : r.endsWith(".") || r.endsWith(" ") ? "trailing-dot-or-space" :
|
|
1365
|
-
},
|
|
1378
|
+
return r !== r.normalize("NFC") ? "not-nfc" : r.includes(":") ? "colon" : r.endsWith(".") || r.endsWith(" ") ? "trailing-dot-or-space" : re(r) ? re(t) ? null : "path-too-long" : "control-character-or-backslash";
|
|
1379
|
+
}, Wo = /* @__PURE__ */ new Set(["id", "label", "root", "pathPrefix", "parse", "deny", "maxEntries", "maxDocumentBytes", "textPreviewBytes", "legacyTextEncoding", "walkConcurrency", "cacheScope", "reportSkipped"]), Se = (e, t, r) => {
|
|
1366
1380
|
if (t === void 0) return r;
|
|
1367
1381
|
if (typeof t != "number" || !Number.isSafeInteger(t) || t <= 0) throw new RangeError(`[markdown-explorer] ${e} must be a positive integer; got ${String(t)}`);
|
|
1368
1382
|
return t;
|
|
1369
|
-
},
|
|
1383
|
+
}, ds = (e) => {
|
|
1370
1384
|
if (e === null || typeof e != "object") throw new TypeError("[markdown-explorer] createFileSystemSource needs an options object");
|
|
1371
1385
|
for (const E of Object.keys(e))
|
|
1372
|
-
if (!
|
|
1373
|
-
const { id: t, label: r, root: n, parse:
|
|
1386
|
+
if (!Wo.has(E)) throw new TypeError(`[markdown-explorer] createFileSystemSource does not know the option ${JSON.stringify(E)}`);
|
|
1387
|
+
const { id: t, label: r, root: n, parse: a } = e;
|
|
1374
1388
|
if (typeof t != "string" || t === "") throw new TypeError("[markdown-explorer] a file-system source needs a non-empty id");
|
|
1375
1389
|
if (typeof r != "string" || r.trim() === "") throw new TypeError("[markdown-explorer] a file-system source needs a non-blank label");
|
|
1376
|
-
if (typeof
|
|
1377
|
-
if (typeof n != "string" || !
|
|
1378
|
-
let
|
|
1390
|
+
if (typeof a != "function") throw new TypeError("[markdown-explorer] a file-system source needs a parse function");
|
|
1391
|
+
if (typeof n != "string" || !We(n)) throw new RangeError(`[markdown-explorer] root must be an absolute path; got ${JSON.stringify(n)}`);
|
|
1392
|
+
let s;
|
|
1379
1393
|
try {
|
|
1380
|
-
|
|
1394
|
+
s = Cr(n).isDirectory();
|
|
1381
1395
|
} catch (E) {
|
|
1382
1396
|
throw new RangeError(`[markdown-explorer] root does not exist: ${n}`, { cause: E });
|
|
1383
1397
|
}
|
|
1384
|
-
if (!
|
|
1385
|
-
const c =
|
|
1398
|
+
if (!s) throw new RangeError(`[markdown-explorer] root is not a directory: ${n}`);
|
|
1399
|
+
const c = Hr(n), m = e.pathPrefix;
|
|
1386
1400
|
if (typeof m != "string") throw new TypeError('[markdown-explorer] pathPrefix is required: "" for a source over the whole root, or relative segments ending with "/"');
|
|
1387
|
-
if (m !== "" && !(m.endsWith("/") &&
|
|
1401
|
+
if (m !== "" && !(m.endsWith("/") && St(m.slice(0, -1))))
|
|
1388
1402
|
throw new RangeError(`[markdown-explorer] pathPrefix must be empty or relative segments ending with "/"; got ${JSON.stringify(m)}`);
|
|
1389
|
-
const
|
|
1390
|
-
if (
|
|
1391
|
-
const
|
|
1392
|
-
if (
|
|
1393
|
-
const
|
|
1403
|
+
const f = vt(e.deny), S = Se("maxEntries", e.maxEntries, ke.maxEntries), h = Se("maxDocumentBytes", e.maxDocumentBytes, ke.maxDocumentBytes), y = Se("textPreviewBytes", e.textPreviewBytes, ke.textPreviewBytes), T = e.legacyTextEncoding;
|
|
1404
|
+
if (T != null && typeof T != "string") throw new TypeError("[markdown-explorer] legacyTextEncoding must be a string or null");
|
|
1405
|
+
const v = typeof T == "string" ? Pr(T) : null, z = Se("walkConcurrency", e.walkConcurrency, ke.walkConcurrency), x = e.cacheScope === void 0 ? "principal" : e.cacheScope;
|
|
1406
|
+
if (x !== "principal" && x !== "shared") throw new RangeError(`[markdown-explorer] cacheScope must be "principal" or "shared"; got ${JSON.stringify(x)}`);
|
|
1407
|
+
const O = e.reportSkipped;
|
|
1408
|
+
if (O !== void 0 && typeof O != "function") throw new TypeError("[markdown-explorer] reportSkipped must be a function");
|
|
1409
|
+
const D = O === void 0 ? (E) => {
|
|
1394
1410
|
console.warn(`[markdown-explorer] the file-system source ${JSON.stringify(E.sourceId)} does not list ${JSON.stringify(E.path)}: ${E.reason}`);
|
|
1395
|
-
} :
|
|
1396
|
-
const
|
|
1397
|
-
return
|
|
1398
|
-
},
|
|
1399
|
-
const
|
|
1400
|
-
R.has(
|
|
1401
|
-
},
|
|
1411
|
+
} : O, R = /* @__PURE__ */ new Set(), I = (E) => {
|
|
1412
|
+
const _ = Fr(c, ...E.split("/")), N = Ke(c, _);
|
|
1413
|
+
return N === "" || N === ".." || N.startsWith(`..${Ve}`) || We(N) ? null : _;
|
|
1414
|
+
}, C = (E, _) => {
|
|
1415
|
+
const N = `${_}\0${E}`;
|
|
1416
|
+
R.has(N) || R.size >= S || (R.add(N), D({ sourceId: t, path: E, reason: _ }));
|
|
1417
|
+
}, F = async ({ signal: E }) => {
|
|
1402
1418
|
E.throwIfAborted();
|
|
1403
|
-
const
|
|
1404
|
-
|
|
1419
|
+
const _ = new AbortController(), N = () => {
|
|
1420
|
+
_.abort(E.reason);
|
|
1405
1421
|
};
|
|
1406
|
-
E.addEventListener("abort",
|
|
1407
|
-
const
|
|
1408
|
-
let
|
|
1409
|
-
const
|
|
1410
|
-
const
|
|
1411
|
-
|
|
1422
|
+
E.addEventListener("abort", N, { once: !0 });
|
|
1423
|
+
const $ = Go(z);
|
|
1424
|
+
let X = 0;
|
|
1425
|
+
const G = async (P, W) => {
|
|
1426
|
+
const K = await $(async () => {
|
|
1427
|
+
_.signal.throwIfAborted();
|
|
1412
1428
|
try {
|
|
1413
|
-
return await
|
|
1429
|
+
return await Jr(P, { withFileTypes: !0 });
|
|
1414
1430
|
} catch (H) {
|
|
1415
|
-
if (
|
|
1431
|
+
if (W === "" || !Wt(H)) throw H;
|
|
1416
1432
|
return null;
|
|
1417
1433
|
}
|
|
1418
1434
|
});
|
|
1419
|
-
if (
|
|
1420
|
-
return
|
|
1435
|
+
if (_.signal.throwIfAborted(), K === null)
|
|
1436
|
+
return C(`${m}${W}`, "unreadable-directory"), null;
|
|
1421
1437
|
const J = [];
|
|
1422
|
-
for (const H of
|
|
1423
|
-
if (
|
|
1424
|
-
const
|
|
1425
|
-
if (
|
|
1426
|
-
|
|
1438
|
+
for (const H of K) {
|
|
1439
|
+
if (f.deniesName(H.name)) continue;
|
|
1440
|
+
const te = W === "" ? H.name : `${W}/${H.name}`, q = `${m}${te}`, ne = Yo(H, q);
|
|
1441
|
+
if (ne !== null) {
|
|
1442
|
+
C(q, ne);
|
|
1427
1443
|
continue;
|
|
1428
1444
|
}
|
|
1429
|
-
J.push({ dirent: H, relativePath:
|
|
1445
|
+
J.push({ dirent: H, relativePath: te, path: q });
|
|
1430
1446
|
}
|
|
1431
|
-
if (
|
|
1432
|
-
return J.sort((H,
|
|
1433
|
-
J.map(async ({ dirent: H, relativePath:
|
|
1434
|
-
const
|
|
1435
|
-
if (!H.isDirectory()) return { name: H.name, path:
|
|
1436
|
-
const
|
|
1437
|
-
return
|
|
1447
|
+
if (X += J.length, X > S) throw new Oe("too-large");
|
|
1448
|
+
return J.sort((H, te) => Jo(H.dirent.name, te.dirent.name)), (await Promise.all(
|
|
1449
|
+
J.map(async ({ dirent: H, relativePath: te, path: q }) => {
|
|
1450
|
+
const ne = await Fo(Ze(P, H.name)), de = ne === void 0 ? {} : { modifiedAt: ne };
|
|
1451
|
+
if (!H.isDirectory()) return { name: H.name, path: q, type: "file", ...de };
|
|
1452
|
+
const Ee = await G(Ze(P, H.name), te);
|
|
1453
|
+
return Ee === null ? null : { name: H.name, path: q, type: "directory", ...de, children: Ee };
|
|
1438
1454
|
})
|
|
1439
1455
|
)).filter((H) => H !== null);
|
|
1440
1456
|
};
|
|
1441
1457
|
try {
|
|
1442
|
-
const
|
|
1443
|
-
if (
|
|
1444
|
-
return
|
|
1445
|
-
} catch (
|
|
1446
|
-
throw
|
|
1458
|
+
const P = await G(c, "");
|
|
1459
|
+
if (P === null) throw new Error("[markdown-explorer] the source's root could not be listed");
|
|
1460
|
+
return P;
|
|
1461
|
+
} catch (P) {
|
|
1462
|
+
throw _.abort(), P;
|
|
1447
1463
|
} finally {
|
|
1448
|
-
E.removeEventListener("abort",
|
|
1464
|
+
E.removeEventListener("abort", N);
|
|
1449
1465
|
}
|
|
1450
|
-
},
|
|
1466
|
+
}, w = async (E) => {
|
|
1451
1467
|
if (!E.startsWith(m)) return { status: "refused", reason: "not-found" };
|
|
1452
|
-
const
|
|
1453
|
-
if (!
|
|
1454
|
-
if (
|
|
1455
|
-
const
|
|
1456
|
-
if (
|
|
1457
|
-
const
|
|
1458
|
-
if (
|
|
1459
|
-
if (
|
|
1460
|
-
const
|
|
1461
|
-
return
|
|
1462
|
-
},
|
|
1463
|
-
let
|
|
1468
|
+
const _ = E.slice(m.length);
|
|
1469
|
+
if (!St(_)) return { status: "refused", reason: "invalid" };
|
|
1470
|
+
if (f.deniesPath(_)) return { status: "refused", reason: "forbidden" };
|
|
1471
|
+
const N = I(_);
|
|
1472
|
+
if (N === null) return { status: "refused", reason: "forbidden" };
|
|
1473
|
+
const $ = await It(N, { bigint: !0 });
|
|
1474
|
+
if ($.isSymbolicLink()) return { status: "refused", reason: "forbidden" };
|
|
1475
|
+
if (!$.isFile()) return { status: "refused", reason: "unsupported" };
|
|
1476
|
+
const X = await Xr(N);
|
|
1477
|
+
return X !== N || f.deniesPath(Ke(c, X).split(Ve).join("/")) ? { status: "refused", reason: "forbidden" } : { status: "file", target: N, name: _.slice(_.lastIndexOf("/") + 1), stats: $ };
|
|
1478
|
+
}, g = async (E, _, N) => {
|
|
1479
|
+
let $;
|
|
1464
1480
|
try {
|
|
1465
|
-
const
|
|
1466
|
-
if (
|
|
1467
|
-
const { target:
|
|
1468
|
-
if (
|
|
1469
|
-
if (
|
|
1470
|
-
if (
|
|
1471
|
-
|
|
1472
|
-
|
|
1473
|
-
|
|
1474
|
-
if (
|
|
1475
|
-
|
|
1476
|
-
|
|
1477
|
-
|
|
1478
|
-
|
|
1479
|
-
|
|
1481
|
+
const X = await w(N);
|
|
1482
|
+
if (X.status === "refused") return ee(X.reason);
|
|
1483
|
+
const { target: G, name: P, stats: W } = X, K = Bo(P), J = kt(W);
|
|
1484
|
+
if (K.kind === "image") return { kind: "image", name: P, imageType: K.imageType, version: J };
|
|
1485
|
+
if (K.kind === "media") return { kind: "media", name: P, mediaType: K.mediaType, version: J };
|
|
1486
|
+
if (K.kind === "spreadsheet") return { kind: "spreadsheet", name: P, format: K.format, firstSheetOnly: !1, edit: null, version: J };
|
|
1487
|
+
if (K.kind === "file") return { kind: "file", name: P, version: J };
|
|
1488
|
+
$ = await Nt(G, we.O_RDONLY | Xt | Jt);
|
|
1489
|
+
const ae = await $.stat({ bigint: !0 });
|
|
1490
|
+
if (!ae.isFile() || ae.ino !== W.ino || ae.dev !== W.dev) return ee("forbidden");
|
|
1491
|
+
if (K.kind === "markdown") {
|
|
1492
|
+
if (ae.size > BigInt(h)) return ee("too-large");
|
|
1493
|
+
const ne = await xt($, h + 1);
|
|
1494
|
+
if (ne.length > h) return ee("too-large");
|
|
1495
|
+
const de = await a($e(ne, !0, v), _);
|
|
1496
|
+
return { kind: "markdown", name: P, htmlContent: de.htmlContent, headings: de.headings, edit: null };
|
|
1480
1497
|
}
|
|
1481
|
-
const H = await
|
|
1482
|
-
|
|
1483
|
-
|
|
1484
|
-
|
|
1485
|
-
|
|
1486
|
-
|
|
1487
|
-
if (U === null) throw M;
|
|
1488
|
-
return Q(U);
|
|
1498
|
+
const H = await xt($, y), te = ae.size > BigInt(y), q = $e(H, !te, v);
|
|
1499
|
+
return q.includes("\0") ? { kind: "file", name: P, version: J } : { kind: "text", name: P, text: q, truncated: te, version: J };
|
|
1500
|
+
} catch (X) {
|
|
1501
|
+
const G = De(X);
|
|
1502
|
+
if (G === null) throw X;
|
|
1503
|
+
return ee(G);
|
|
1489
1504
|
} finally {
|
|
1490
|
-
await
|
|
1505
|
+
await $?.close();
|
|
1491
1506
|
}
|
|
1492
|
-
},
|
|
1493
|
-
let
|
|
1507
|
+
}, M = async (E, _, N) => {
|
|
1508
|
+
let $;
|
|
1494
1509
|
try {
|
|
1495
|
-
|
|
1510
|
+
$ = await w(N);
|
|
1496
1511
|
} catch (J) {
|
|
1497
|
-
throw
|
|
1512
|
+
throw Yt(J);
|
|
1498
1513
|
}
|
|
1499
|
-
if (
|
|
1500
|
-
const { target:
|
|
1501
|
-
return { name:
|
|
1502
|
-
},
|
|
1503
|
-
let
|
|
1514
|
+
if ($.status === "refused") throw new Oe($.reason);
|
|
1515
|
+
const { target: X, name: G, stats: P } = $, W = Ut.get(Gt(G)), K = W === void 0 ? "" : W.contentType;
|
|
1516
|
+
return { name: G, contentType: K, size: Number(P.size), version: kt(P), open: (J) => Xo(X, P, J, E.signal) };
|
|
1517
|
+
}, U = async (E, _, N) => {
|
|
1518
|
+
let $;
|
|
1504
1519
|
try {
|
|
1505
|
-
|
|
1506
|
-
} catch (
|
|
1507
|
-
if (
|
|
1508
|
-
throw
|
|
1520
|
+
$ = await w(N);
|
|
1521
|
+
} catch (P) {
|
|
1522
|
+
if (De(P) !== null) return null;
|
|
1523
|
+
throw P;
|
|
1509
1524
|
}
|
|
1510
|
-
if (
|
|
1511
|
-
const
|
|
1512
|
-
if (
|
|
1513
|
-
const
|
|
1514
|
-
return
|
|
1525
|
+
if ($.status === "refused") return null;
|
|
1526
|
+
const X = N.slice(m.length).split("/");
|
|
1527
|
+
if (X.some((P) => f.deniesName(P))) return null;
|
|
1528
|
+
const G = X.slice(0, -1);
|
|
1529
|
+
return G.map((P, W) => `${m}${G.slice(0, W + 1).join("/")}`);
|
|
1515
1530
|
};
|
|
1516
1531
|
return Object.freeze({
|
|
1517
1532
|
id: t,
|
|
1518
1533
|
label: r,
|
|
1519
|
-
cacheScope:
|
|
1534
|
+
cacheScope: x,
|
|
1520
1535
|
boundary: Object.freeze({ contains: (E) => E.startsWith(m) }),
|
|
1521
|
-
tree:
|
|
1522
|
-
ancestors:
|
|
1523
|
-
document:
|
|
1524
|
-
asset:
|
|
1536
|
+
tree: F,
|
|
1537
|
+
ancestors: U,
|
|
1538
|
+
document: g,
|
|
1539
|
+
asset: M
|
|
1525
1540
|
});
|
|
1526
1541
|
};
|
|
1527
1542
|
export {
|
|
1528
|
-
|
|
1529
|
-
|
|
1530
|
-
|
|
1531
|
-
|
|
1532
|
-
|
|
1533
|
-
|
|
1534
|
-
|
|
1535
|
-
|
|
1543
|
+
ms as DEFAULT_DENIED_PATH_SEGMENTS,
|
|
1544
|
+
Oe as ExplorerError,
|
|
1545
|
+
ps as MAX_DOCUMENT_PATH_LENGTH,
|
|
1546
|
+
cs as anonymousAccess,
|
|
1547
|
+
ds as createFileSystemSource,
|
|
1548
|
+
us as createMarkdownExplorer,
|
|
1549
|
+
ys as decodeText,
|
|
1550
|
+
$e as decodeTextLeniently,
|
|
1551
|
+
re as isAcceptableDocumentPath,
|
|
1552
|
+
ws as isDeniedPath,
|
|
1553
|
+
Pr as legacyTextEncodingOf
|
|
1536
1554
|
};
|