@aiquants/markdown-explorer 0.12.1 → 0.14.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 +30 -1
- package/README.md +21 -12
- package/dist/EditSurface-BLlu5zEt.cjs +2 -0
- package/dist/EditSurface-CF2io496.js +705 -0
- package/dist/{ExplorerSplit-BjjqNRtj.js → ExplorerSplit-BPLECNpv.js} +109 -109
- package/dist/{ExplorerSplit-CqmbUSZ7.cjs → ExplorerSplit-Cjvy0JHP.cjs} +1 -1
- package/dist/{MultiLayout-BZbEl73E.cjs → MultiLayout-BjA0k-5n.cjs} +1 -1
- package/dist/{MultiLayout-BYXoD1aS.js → MultiLayout-D8F0BfxA.js} +25 -25
- package/dist/{NativeScrollBar-RP37nwmY.js → NativeScrollBar-BFF12oEd.js} +1 -1
- package/dist/{NativeScrollBar-B7jTbQmn.cjs → NativeScrollBar-BUWXPvTV.cjs} +1 -1
- package/dist/{TreeLayout-CEp5oKly.cjs → TreeLayout-CQUpgsxz.cjs} +1 -1
- package/dist/{TreeLayout-Uo6RG7lq.js → TreeLayout-rhyVTfrI.js} +3 -3
- package/dist/core/contracts.d.cts +7 -1
- package/dist/core/contracts.d.ts +7 -1
- package/dist/core/labels.d.cts +14 -1
- package/dist/core/labels.d.ts +14 -1
- package/dist/core/revalidation.d.cts +1 -2
- package/dist/core/revalidation.d.ts +1 -2
- package/dist/{dataRoute-CH3yOKR0.cjs → dataRoute-BONacTPi.cjs} +1 -1
- package/dist/{dataRoute-Pm_0ue_4.js → dataRoute-CObbjNxG.js} +14 -12
- package/dist/index-Dn7cYy-4.cjs +13 -0
- package/dist/index-v997iKxe.js +3464 -0
- package/dist/index.cjs +1 -1
- package/dist/index.js +21 -21
- package/dist/{location-BUNWJ4eB.cjs → location-D6RE3wAN.cjs} +1 -1
- package/dist/{location-DWd6SQhN.js → location-IRD9h42r.js} +1 -1
- package/dist/{merge-DRGBbLuR.cjs → merge-BFk7nT59.cjs} +1 -1
- package/dist/{merge-q-5i8qsn.js → merge-Bi2VedIr.js} +1 -1
- package/dist/{sanitizePolicy-djLC3fRN.js → sanitizePolicy-DlrakwA4.js} +1 -1
- package/dist/{sanitizePolicy-BfUlXI5E.cjs → sanitizePolicy-DrIMuYCb.cjs} +1 -1
- package/dist/sanitizeWorker.cjs +1 -1
- package/dist/sanitizeWorker.js +1 -1
- package/dist/server/ports.d.cts +3 -0
- package/dist/server/ports.d.ts +3 -0
- package/dist/server.cjs +1 -1
- package/dist/server.js +93 -83
- package/dist/styles/markdown-explorer.css +1 -1
- package/docs/behavior/dom-hooks.md +6 -5
- package/docs/behavior/layout.md +10 -3
- package/package.json +6 -5
- package/dist/EditSurface-By6NPcD7.js +0 -633
- package/dist/EditSurface-BztcpQPW.cjs +0 -2
- package/dist/index-CGBl3fYT.cjs +0 -13
- package/dist/index-CjCr8czx.js +0 -3356
package/dist/server.js
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
import { b as Tt, c as nr, f as ke, g as or, h as sr, j as ir, k as ar, E as kt, l as he, r as cr, m as ur, i as q, n as dr, o as lr, p as fr, q as St, s as mr, t as pr, u as
|
|
2
|
-
import { D as ns, M as os, C as ss } from "./dataRoute-
|
|
1
|
+
import { b as Tt, c as nr, f as ke, g as or, h as sr, j as ir, k as ar, E as kt, l as he, r as cr, m as ur, i as q, n as dr, o as lr, p as fr, q as St, s as mr, t as pr, u as Le, v as wr, w as hr, x as yr, y as ae, z as Q, e as Fe, A as gr, B as Er } from "./dataRoute-CObbjNxG.js";
|
|
2
|
+
import { D as ns, M as os, C as ss } from "./dataRoute-CObbjNxG.js";
|
|
3
3
|
import { createHash as br, createHmac as Tr } from "node:crypto";
|
|
4
4
|
import { createLinkCardHandler as kr } from "@aiquants/markdown/server";
|
|
5
5
|
import { crossOriginRefusal as xt, NO_CROSS_ORIGIN_NAVIGATION as Ot } from "@aiquants/request-isolation";
|
|
6
6
|
import { data as Ue, redirect as Sr } from "react-router";
|
|
7
|
-
import { w as xr, d as Or, r as Rr, i as vr, a as _r, p as Ar, b as Nr, f as Ir, N as Pr } from "./location-
|
|
7
|
+
import { w as xr, d as Or, r as Rr, i as vr, a as _r, p as Ar, b as Nr, f as Ir, N as Pr } from "./location-IRD9h42r.js";
|
|
8
8
|
import { existsSync as Mr, statSync as $r, realpathSync as Lr, constants as me } from "node:fs";
|
|
9
9
|
import { extname as jr, isAbsolute as Xe, relative as Je, sep as Ge, join as Ye, resolve as zr } from "node:path";
|
|
10
|
-
import { fileURLToPath as
|
|
10
|
+
import { fileURLToPath as Re } from "node:url";
|
|
11
11
|
import { Worker as Dr } from "node:worker_threads";
|
|
12
|
-
import { open as Rt, lstat as vt, realpath as Cr, readdir as
|
|
13
|
-
import { Readable as
|
|
12
|
+
import { open as Rt, lstat as vt, realpath as Cr, readdir as Hr } from "node:fs/promises";
|
|
13
|
+
import { Readable as Br } from "node:stream";
|
|
14
14
|
const We = Object.freeze({ kind: "anonymous" }), Qo = Object.freeze({
|
|
15
15
|
authenticate: async () => ({ status: "signed-in", principal: We }),
|
|
16
16
|
principalKey: () => We.kind,
|
|
@@ -42,7 +42,7 @@ const We = Object.freeze({ kind: "anonymous" }), Qo = Object.freeze({
|
|
|
42
42
|
"video/ogg",
|
|
43
43
|
"video/quicktime",
|
|
44
44
|
_t
|
|
45
|
-
]), At = "default-src 'none'; media-src 'self'; style-src 'unsafe-inline'", Nt = `${At}; sandbox`, Xr = `${At}; sandbox allow-same-origin`, Ke = /^[!#$%&'*+\-.^_`|~0-9A-Za-z]+$/u, Jr = /^[\t\n\r ]+|[\t\n\r ]+$/gu,
|
|
45
|
+
]), At = "default-src 'none'; media-src 'self'; style-src 'unsafe-inline'", Nt = `${At}; sandbox`, Xr = `${At}; sandbox allow-same-origin`, Ke = /^[!#$%&'*+\-.^_`|~0-9A-Za-z]+$/u, Jr = /^[\t\n\r ]+|[\t\n\r ]+$/gu, Me = /^[\t ]+|[\t ]+$/gu, Gr = (e) => {
|
|
46
46
|
const t = [];
|
|
47
47
|
let r = "", n = 0;
|
|
48
48
|
for (; ; ) {
|
|
@@ -54,7 +54,7 @@ const We = Object.freeze({ kind: "anonymous" }), Qo = Object.freeze({
|
|
|
54
54
|
n += e[n] === "\\" ? 2 : 1;
|
|
55
55
|
if (n = Math.min(n + 1, e.length), r += e.slice(a, n), n < e.length) continue;
|
|
56
56
|
}
|
|
57
|
-
if (t.push(r.replace(
|
|
57
|
+
if (t.push(r.replace(Me, "")), r = "", n >= e.length) return t;
|
|
58
58
|
n += 1;
|
|
59
59
|
}
|
|
60
60
|
}, Yr = (e) => {
|
|
@@ -113,8 +113,8 @@ const We = Object.freeze({ kind: "anonymous" }), Qo = Object.freeze({
|
|
|
113
113
|
const t = [];
|
|
114
114
|
let r = 0, n = !1;
|
|
115
115
|
for (let a = 0; a < e.length; a += 1)
|
|
116
|
-
e[a] === '"' ? n = !n : e[a] === "," && !n && (t.push(e.slice(r, a).replace(
|
|
117
|
-
return t.push(e.slice(r).replace(
|
|
116
|
+
e[a] === '"' ? n = !n : e[a] === "," && !n && (t.push(e.slice(r, a).replace(Me, "")), r = a + 1);
|
|
117
|
+
return t.push(e.slice(r).replace(Me, "")), t;
|
|
118
118
|
}, Qe = (e) => e.startsWith(Ze) ? e.slice(Ze.length) : e, nn = (e, t) => {
|
|
119
119
|
if (e === null) return !1;
|
|
120
120
|
const r = rn(e);
|
|
@@ -134,7 +134,7 @@ const We = Object.freeze({ kind: "anonymous" }), Qo = Object.freeze({
|
|
|
134
134
|
}
|
|
135
135
|
})
|
|
136
136
|
);
|
|
137
|
-
},
|
|
137
|
+
}, ve = async (e, t, r, n, a) => {
|
|
138
138
|
if (n !== null && r.set("Content-Length", String(n)), e.method.toUpperCase() === "HEAD") return new Response(null, { status: t, headers: r });
|
|
139
139
|
const i = await a();
|
|
140
140
|
return new Response(n === null ? i : on(i, n), { status: t, headers: r });
|
|
@@ -146,16 +146,16 @@ const We = Object.freeze({ kind: "anonymous" }), Qo = Object.freeze({
|
|
|
146
146
|
const a = `"${t.version}"`, i = n === "text" ? qr(t.name) : Zr(t.contentType, t.name), c = new Headers(r);
|
|
147
147
|
for (const [S, w] of Object.entries({ ...i.headers, ...Vr, ETag: a })) c.set(S, w);
|
|
148
148
|
if (nn(e.headers.get("If-None-Match"), a)) return new Response(null, { status: 304, headers: c });
|
|
149
|
-
if (c.set("Content-Type", i.contentType), t.size === null) return
|
|
149
|
+
if (c.set("Content-Type", i.contentType), t.size === null) return ve(e, 200, c, null, () => t.open(null));
|
|
150
150
|
if (t.size === 0)
|
|
151
151
|
return c.set("Content-Length", "0"), new Response(null, { status: 200, headers: c });
|
|
152
152
|
c.set("Accept-Ranges", "bytes");
|
|
153
153
|
const m = tn(e.headers, t.size, a);
|
|
154
154
|
if (m.kind === "unsatisfiable") return sn(r, t.size);
|
|
155
|
-
if (m.kind === "whole") return
|
|
155
|
+
if (m.kind === "whole") return ve(e, 200, c, t.size, () => t.open(null));
|
|
156
156
|
const { range: h } = m;
|
|
157
|
-
return c.set("Content-Range", `bytes ${h.offset}-${h.offset + h.length - 1}/${t.size}`),
|
|
158
|
-
},
|
|
157
|
+
return c.set("Content-Range", `bytes ${h.offset}-${h.offset + h.length - 1}/${t.size}`), ve(e, 206, c, h.length, () => t.open(h));
|
|
158
|
+
}, _e = (e, t) => {
|
|
159
159
|
const r = new AbortController(), n = t(AbortSignal.any([e.signal, r.signal]));
|
|
160
160
|
return new Promise((a) => {
|
|
161
161
|
let i;
|
|
@@ -187,13 +187,13 @@ class Se extends Error {
|
|
|
187
187
|
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, Pt, { value: !0 });
|
|
188
188
|
}
|
|
189
189
|
}
|
|
190
|
-
const un = (e) => e instanceof Error && Object.hasOwn(e, Pt) && Tt(e.reason), dn = (e) => typeof e == "object" && e !== null && e.name === "AbortError",
|
|
190
|
+
const un = (e) => e instanceof Error && Object.hasOwn(e, Pt) && Tt(e.reason), dn = (e) => typeof e == "object" && e !== null && e.name === "AbortError", je = (e, t, r) => {
|
|
191
191
|
try {
|
|
192
192
|
e.error(t, r);
|
|
193
193
|
} catch (n) {
|
|
194
194
|
console.error("[markdown-explorer] the logger threw while reporting a failure", { operation: r.operation, error: n });
|
|
195
195
|
}
|
|
196
|
-
}, oe = (e, t) =>
|
|
196
|
+
}, oe = (e, t) => je(e, `[markdown-explorer] ${t.operation} failed`, t), ln = (e, t) => je(e, `[markdown-explorer] ${t.operation} left out an entry`, t), Ae = (e, t) => je(e, `[markdown-explorer] ${t.operation} refused a path the deny rules match`, { ...t, error: new RangeError("[markdown-explorer] the path matches a deny rule") }), qe = (e, t) => {
|
|
197
197
|
e === null || typeof e != "object" && typeof e != "function" || Promise.resolve(e).then(void 0, t);
|
|
198
198
|
}, G = (e, t, r, n) => un(e) ? ke(e.reason, e.code) : (dn(e) || r.aborted || oe(n, { ...t, error: e }), { reason: "failed" }), et = 2 * 1024 * 1024, tt = 256 * 1024 * 1024, fn = async (e, t) => {
|
|
199
199
|
const r = e.getReader(), n = new Uint8Array(t);
|
|
@@ -267,7 +267,7 @@ const un = (e) => e instanceof Error && Object.hasOwn(e, Pt) && Tt(e.reason), dn
|
|
|
267
267
|
return p;
|
|
268
268
|
}, R = (p, g) => {
|
|
269
269
|
m.has(p) && (m.delete(p), v(p, g), p.worker.terminate().catch(() => {
|
|
270
|
-
}),
|
|
270
|
+
}), B());
|
|
271
271
|
}, z = (p) => {
|
|
272
272
|
p.timer = setTimeout(() => {
|
|
273
273
|
R(p, { status: "timeout" });
|
|
@@ -285,7 +285,7 @@ const un = (e) => e instanceof Error && Object.hasOwn(e, Pt) && Tt(e.reason), dn
|
|
|
285
285
|
R(p, { status: "unavailable", error: new Error(`[markdown-explorer] a worker did not start within ${String(r)} ms`) });
|
|
286
286
|
}, r), p.worker.on("message", (g) => {
|
|
287
287
|
if (!p.ready && wn(g)) {
|
|
288
|
-
p.ready = !0, p.timer !== null && clearTimeout(p.timer), p.timer = null, p.job === null ? p.worker.unref() : I(p, p.job), p.job === null &&
|
|
288
|
+
p.ready = !0, p.timer !== null && clearTimeout(p.timer), p.timer = null, p.job === null ? p.worker.unref() : I(p, p.job), p.job === null && B();
|
|
289
289
|
return;
|
|
290
290
|
}
|
|
291
291
|
const { job: E } = p;
|
|
@@ -293,7 +293,7 @@ const un = (e) => e instanceof Error && Object.hasOwn(e, Pt) && Tt(e.reason), dn
|
|
|
293
293
|
R(p, _(p, new Error("[markdown-explorer] a worker sent a message that answers no job")));
|
|
294
294
|
return;
|
|
295
295
|
}
|
|
296
|
-
v(p, { status: "done", output: g.output }), p.worker.unref(),
|
|
296
|
+
v(p, { status: "done", output: g.output }), p.worker.unref(), B();
|
|
297
297
|
}), p.worker.on("error", (g) => {
|
|
298
298
|
R(p, _(p, g));
|
|
299
299
|
}), p.worker.on("messageerror", (g) => {
|
|
@@ -301,7 +301,7 @@ const un = (e) => e instanceof Error && Object.hasOwn(e, Pt) && Tt(e.reason), dn
|
|
|
301
301
|
}), p.worker.on("exit", (g) => {
|
|
302
302
|
R(p, _(p, new Error(`[markdown-explorer] a worker exited with code ${String(g)}`)));
|
|
303
303
|
}), m.add(p), p;
|
|
304
|
-
},
|
|
304
|
+
}, B = () => {
|
|
305
305
|
for (; ; ) {
|
|
306
306
|
const p = A(), g = h[p];
|
|
307
307
|
if (g === void 0) return;
|
|
@@ -337,7 +337,7 @@ const un = (e) => e instanceof Error && Object.hasOwn(e, Pt) && Tt(e.reason), dn
|
|
|
337
337
|
k += 1;
|
|
338
338
|
const T = { id: k, input: p, scope: g, settle: O, detach: () => {
|
|
339
339
|
} };
|
|
340
|
-
h.push(T), ue(w, g, 1),
|
|
340
|
+
h.push(T), ue(w, g, 1), B();
|
|
341
341
|
const N = h.indexOf(T);
|
|
342
342
|
if (N < 0) return;
|
|
343
343
|
if (h.length > a) {
|
|
@@ -354,7 +354,7 @@ const un = (e) => e instanceof Error && Object.hasOwn(e, Pt) && Tt(e.reason), dn
|
|
|
354
354
|
}),
|
|
355
355
|
workers: () => m.size
|
|
356
356
|
};
|
|
357
|
-
},
|
|
357
|
+
}, ze = 1024 * 1024, gn = 3e4, En = 4 * ze, bn = 64 * ze, Tn = 3, kn = 2, Sn = (e, t) => e + $t(t) + Tn, xn = 4, On = 32, Rn = 512, vn = 64, _n = 4096, An = 32, ot = 4096, Nn = 4, Lt = ({ workerHeapMb: e, maxHtmlBytes: t }) => Math.floor(((e - vn) * ze - t * An) / _n), In = ({ maxHtmlBytes: e }) => e, Pn = ({ maxHtmlBytes: e }) => Nn * e, Mn = 1024, $n = 2147483647, Ln = 64, jn = 2 ** 29, zn = 1024 * 1024, Dn = 64, st = Object.freeze({ status: "rejected", reason: "too-large", cause: null }), Ne = Object.freeze({ status: "rejected", reason: "failed", cause: null }), de = (e, t, r, n) => {
|
|
358
358
|
if (t === void 0) return r;
|
|
359
359
|
if (typeof t != "number") throw new TypeError(`[markdown-explorer] sanitizer.${e} must be a number; got ${typeof t}`);
|
|
360
360
|
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)}`);
|
|
@@ -379,11 +379,11 @@ const un = (e) => e instanceof Error && Object.hasOwn(e, Pt) && Tt(e.reason), dn
|
|
|
379
379
|
`[markdown-explorer] sanitizer.workerHeapMb (${String(y.workerHeapMb)} MiB) must leave room for ${String(ot)} parsed nodes beside HTML of sanitizer.maxHtmlBytes (${String(y.maxHtmlBytes)} bytes); raise workerHeapMb or lower maxHtmlBytes`
|
|
380
380
|
);
|
|
381
381
|
return y;
|
|
382
|
-
},
|
|
383
|
-
const e = import.meta.url, t = new URL(`./sanitizeWorker${jr(
|
|
384
|
-
if (!Mr(
|
|
382
|
+
}, Hn = () => {
|
|
383
|
+
const e = import.meta.url, t = new URL(`./sanitizeWorker${jr(Re(e))}`, e);
|
|
384
|
+
if (!Mr(Re(t))) throw new Error(`[markdown-explorer] the HTML sanitizer worker is missing: ${Re(t)}`);
|
|
385
385
|
return t;
|
|
386
|
-
}, it = /* @__PURE__ */ new Map(),
|
|
386
|
+
}, it = /* @__PURE__ */ new Map(), Bn = (e, t) => {
|
|
387
387
|
const r = [e.href, t.workers, t.deadlineMs, t.workerHeapMb, t.jobsPerScope, t.maxQueuedJobs].map(String).join("\0");
|
|
388
388
|
let n = it.get(r);
|
|
389
389
|
return n === void 0 && (n = yn({
|
|
@@ -412,7 +412,7 @@ const un = (e) => e instanceof Error && Object.hasOwn(e, Pt) && Tt(e.reason), dn
|
|
|
412
412
|
const D = _.limit === "scope" ? `its reader already has ${String(r.jobsPerScope)} documents being sanitized or waiting` : `${String(r.maxQueuedJobs)} documents are already waiting`;
|
|
413
413
|
return { outcome: { status: "rejected", reason: "failed", cause: new Error(`[markdown-explorer] the HTML sanitizer refused a document: ${D}`) }, lasting: !1 };
|
|
414
414
|
}
|
|
415
|
-
if (_.status === "aborted") return { outcome:
|
|
415
|
+
if (_.status === "aborted") return { outcome: Ne, lasting: !1 };
|
|
416
416
|
if (_.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 };
|
|
417
417
|
if (_.status === "unavailable") return { outcome: { status: "rejected", reason: "failed", cause: new Error("[markdown-explorer] the HTML sanitizer worker could not start", { cause: _.error }) }, lasting: !1 };
|
|
418
418
|
if (_.status === "crashed" && Un(_.error))
|
|
@@ -425,20 +425,20 @@ const un = (e) => e instanceof Error && Object.hasOwn(e, Pt) && Tt(e.reason), dn
|
|
|
425
425
|
};
|
|
426
426
|
const D = new Promise((g) => {
|
|
427
427
|
I = g;
|
|
428
|
-
}),
|
|
429
|
-
S.set(z,
|
|
428
|
+
}), B = { hash: R, key: z, outcome: D, answer: I, controller: new AbortController(), waiters: 0 };
|
|
429
|
+
S.set(z, B);
|
|
430
430
|
const p = w.get(R);
|
|
431
|
-
return p === void 0 ? w.set(R, /* @__PURE__ */ new Set([
|
|
432
|
-
if (y(
|
|
431
|
+
return p === void 0 ? w.set(R, /* @__PURE__ */ new Set([B])) : p.add(B), k(A, _, B.controller.signal).catch((g) => ({ outcome: { status: "rejected", reason: "failed", cause: g instanceof Error ? g : new Error(String(g)) }, lasting: !0 })).then(({ outcome: g, lasting: E }) => {
|
|
432
|
+
if (y(B), B.answer(g), !E) return;
|
|
433
433
|
const O = h.get(R), T = O ?? (g.status === "rejected" ? { ...g, cause: null } : g);
|
|
434
434
|
O === void 0 && h.set(R, T);
|
|
435
435
|
for (const N of w.get(R) ?? [])
|
|
436
436
|
y(N), N.answer(T), N.controller.abort();
|
|
437
|
-
}),
|
|
437
|
+
}), B;
|
|
438
438
|
}, L = (A, R) => new Promise((z) => {
|
|
439
439
|
A.waiters += 1;
|
|
440
440
|
const _ = () => {
|
|
441
|
-
A.waiters -= 1, z(
|
|
441
|
+
A.waiters -= 1, z(Ne), !(A.waiters > 0) && (y(A), A.controller.abort());
|
|
442
442
|
};
|
|
443
443
|
R.addEventListener("abort", _, { once: !0 }), A.outcome.then((I) => {
|
|
444
444
|
R.removeEventListener("abort", _), z(I);
|
|
@@ -448,17 +448,17 @@ const un = (e) => e instanceof Error && Object.hasOwn(e, Pt) && Tt(e.reason), dn
|
|
|
448
448
|
if (A.length > r.maxHtmlBytes || Buffer.byteLength(A, "utf8") > r.maxHtmlBytes) return Promise.resolve(st);
|
|
449
449
|
const _ = br("sha256").update(A, "utf8").digest("base64"), I = h.get(_);
|
|
450
450
|
if (I !== void 0) return Promise.resolve(I);
|
|
451
|
-
if (z.aborted) return Promise.resolve(
|
|
452
|
-
const D = `${_}\0${R}`,
|
|
453
|
-
return L(
|
|
451
|
+
if (z.aborted) return Promise.resolve(Ne);
|
|
452
|
+
const D = `${_}\0${R}`, B = S.get(D);
|
|
453
|
+
return L(B === void 0 ? v(A, _, D, R) : B, z);
|
|
454
454
|
};
|
|
455
|
-
}, xe = (e) => ({ result: e, json: JSON.stringify(e) }),
|
|
455
|
+
}, xe = (e) => ({ result: e, json: JSON.stringify(e) }), Ie = Object.freeze(xe(Object.freeze({ status: "error", failure: Object.freeze({ reason: "failed" }) }))), Jn = (e) => e.status === "ok" && e.entries.length > 0, Gn = ({ ttlMs: e, maxEntries: t, maxBytes: r, now: n }) => {
|
|
456
456
|
const a = Mt(t, { max: r, of: (w, y) => 2 * y.tree.json.length }), i = /* @__PURE__ */ new Map(), c = /* @__PURE__ */ new Map(), m = (w, y) => {
|
|
457
|
-
const k = new AbortController(), v = { waiters: 0, superseded: !1, started: !1, loadTree: y }, L = c.get(w), A = (D,
|
|
457
|
+
const k = new AbortController(), v = { waiters: 0, superseded: !1, started: !1, loadTree: y }, L = c.get(w), A = (D, B) => {
|
|
458
458
|
const p = xe(D);
|
|
459
|
-
return !(v.superseded || k.signal.aborted) && Jn(D) && a.set(w, { tree: p, loadedAt:
|
|
459
|
+
return !(v.superseded || k.signal.aborted) && Jn(D) && a.set(w, { tree: p, loadedAt: B }), p;
|
|
460
460
|
}, z = (async () => {
|
|
461
|
-
if (L !== void 0 && await L, k.signal.aborted) return
|
|
461
|
+
if (L !== void 0 && await L, k.signal.aborted) return Ie;
|
|
462
462
|
const D = n();
|
|
463
463
|
return v.started = !0, A(await v.loadTree(k.signal, D), D);
|
|
464
464
|
})().finally(() => {
|
|
@@ -489,7 +489,7 @@ const un = (e) => e instanceof Error && Object.hasOwn(e, Pt) && Tt(e.reason), dn
|
|
|
489
489
|
};
|
|
490
490
|
return {
|
|
491
491
|
load: (w, y, k) => {
|
|
492
|
-
if (y.aborted) return Promise.resolve(
|
|
492
|
+
if (y.aborted) return Promise.resolve(Ie);
|
|
493
493
|
const v = a.get(w);
|
|
494
494
|
if (v !== void 0) {
|
|
495
495
|
if (n() - v.loadedAt < e) return Promise.resolve(v.tree);
|
|
@@ -499,7 +499,7 @@ const un = (e) => e instanceof Error && Object.hasOwn(e, Pt) && Tt(e.reason), dn
|
|
|
499
499
|
return h(w, L === void 0 ? m(w, k) : L, y);
|
|
500
500
|
},
|
|
501
501
|
refresh: (w, y, k) => {
|
|
502
|
-
if (y.aborted) return Promise.resolve(
|
|
502
|
+
if (y.aborted) return Promise.resolve(Ie);
|
|
503
503
|
S(w);
|
|
504
504
|
const v = i.get(w);
|
|
505
505
|
return v === void 0 ? h(w, m(w, k), y) : (v.state.loadTree = k, h(w, v, y));
|
|
@@ -591,12 +591,22 @@ const un = (e) => e instanceof Error && Object.hasOwn(e, Pt) && Tt(e.reason), dn
|
|
|
591
591
|
return { kind: "failure", failure: ke(i, c) };
|
|
592
592
|
}
|
|
593
593
|
case "markdown":
|
|
594
|
-
return a.headings.length > kt ? { kind: "failure", failure: ke("too-large") } : a.edit?.kind === "inline" && !r ? x(
|
|
594
|
+
return a.headings.length > kt ? { kind: "failure", failure: ke("too-large") } : (a.edit?.kind === "inline" || a.edit?.kind === "draft") && !r ? x(`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: i, depth: c, id: m }) => ({ text: i, depth: c, id: m })), edit: to(a.edit) };
|
|
595
595
|
}
|
|
596
|
-
}, to = (e) =>
|
|
596
|
+
}, to = (e) => {
|
|
597
|
+
if (e === null) return null;
|
|
598
|
+
switch (e.kind) {
|
|
599
|
+
case "inline":
|
|
600
|
+
return { kind: "inline" };
|
|
601
|
+
case "draft":
|
|
602
|
+
return { kind: "draft" };
|
|
603
|
+
case "external":
|
|
604
|
+
return { kind: "external", href: e.href };
|
|
605
|
+
}
|
|
606
|
+
}, Oe = (e, t, r) => typeof e != "string" ? x(`${r} needs a text string`) : e.includes("\0") ? x(`${r} holds NUL, which no text editor can keep`) : new TextEncoder().encode(e).byteLength > t ? x(`${r} is over editMaxBytes (${t} bytes); refuse a longer source with ExplorerError "too-large"`) : e, zt = (e) => dr(e.href) ? { kind: "grant", href: e.href } : x("a grant needs a root-relative href"), ro = (e, t) => {
|
|
597
607
|
if (e === null || typeof e != "object") return x("an edit source must be an object");
|
|
598
608
|
const r = e;
|
|
599
|
-
return r.kind === "grant" ? zt(r) : r.kind !== "edit" ? x(`an edit source's kind must be "edit" or "grant"`) : he(r.version) ? typeof r.history != "boolean" ? x("an edit source needs history") : { kind: "edit", text:
|
|
609
|
+
return r.kind === "grant" ? zt(r) : r.kind === "draft" ? { kind: "draft", text: Oe(r.text, t, "a draft source") } : r.kind !== "edit" ? x(`an edit source's kind must be "edit", "draft" or "grant"`) : he(r.version) ? typeof r.history != "boolean" ? x("an edit source needs history") : { kind: "edit", text: Oe(r.text, t, "an edit source"), version: r.version, history: r.history } : x("an edit source needs a version of 1 to 1024 characters");
|
|
600
610
|
}, no = (e, t) => {
|
|
601
611
|
if (e === null || typeof e != "object") return x("a save result must be an object");
|
|
602
612
|
const r = e;
|
|
@@ -606,7 +616,7 @@ const un = (e) => e instanceof Error && Object.hasOwn(e, Pt) && Tt(e.reason), dn
|
|
|
606
616
|
case "saved":
|
|
607
617
|
return he(r.version) ? { kind: "saved", version: r.version } : x("a saved result needs a version of 1 to 1024 characters");
|
|
608
618
|
case "conflict":
|
|
609
|
-
return he(r.version) ? { kind: "conflict", version: r.version, text:
|
|
619
|
+
return he(r.version) ? { kind: "conflict", version: r.version, text: Oe(r.text, t, "a conflict's current text") } : x("a conflict needs the current version of 1 to 1024 characters");
|
|
610
620
|
default:
|
|
611
621
|
return x(`a save result's kind must be "saved", "conflict" or "grant"`);
|
|
612
622
|
}
|
|
@@ -629,7 +639,7 @@ const un = (e) => e instanceof Error && Object.hasOwn(e, Pt) && Tt(e.reason), dn
|
|
|
629
639
|
const { id: a, modifiedAt: i, size: c, author: m, kept: h, current: S } = r;
|
|
630
640
|
return t.has(a) ? x(`two revisions share the id ${JSON.stringify(a.slice(0, 64))}`) : (t.add(a), { id: a, modifiedAt: i, size: c, author: m, kept: h, current: S });
|
|
631
641
|
});
|
|
632
|
-
}, io = (e, t) =>
|
|
642
|
+
}, io = (e, t) => Oe(e, t, "a revision"), at = (e) => {
|
|
633
643
|
if (e === null || typeof e != "object") return x("an asset file must be an object");
|
|
634
644
|
const { name: t, contentType: r, size: n, version: a, open: i } = e;
|
|
635
645
|
return typeof t != "string" || t === "" ? x("an asset file needs a non-empty name") : typeof r != "string" ? x("an asset file needs a contentType string ('' when unknown)") : n !== null && !(typeof n == "number" && Number.isSafeInteger(n) && n >= 0) ? x("an asset file's size must be null or a non-negative safe integer") : jt(a) ? typeof i != "function" ? x("an asset file needs an open function") : Object.freeze({ name: t, contentType: r, size: n, version: a, open: i }) : x(`an asset file needs a version of 1 to 256 visible ASCII characters other than '"'`);
|
|
@@ -650,7 +660,7 @@ const un = (e) => e instanceof Error && Object.hasOwn(e, Pt) && Tt(e.reason), dn
|
|
|
650
660
|
"X-Content-Type-Options": "nosniff",
|
|
651
661
|
"Content-Security-Policy": "default-src 'none'; frame-ancestors 'none'; sandbox",
|
|
652
662
|
"Cross-Origin-Resource-Policy": "same-origin"
|
|
653
|
-
}), lo = 22, fo = 2147483647,
|
|
663
|
+
}), lo = 22, fo = 2147483647, Pe = Object.freeze([]), mo = Object.freeze({ status: "ok", source: null, ancestors: null }), ut = Object.freeze(["contains", "confirm"]), dt = Object.freeze({ readOnly: !1 }), po = Object.freeze({ readOnly: !0 }), K = (e, t, r) => {
|
|
654
664
|
if (!(r && t === void 0) && typeof t != "function")
|
|
655
665
|
throw new TypeError(`[markdown-explorer] ${e} must be a function; got ${typeof t}`);
|
|
656
666
|
}, fe = (e, t, r) => {
|
|
@@ -723,7 +733,7 @@ const un = (e) => e instanceof Error && Object.hasOwn(e, Pt) && Tt(e.reason), dn
|
|
|
723
733
|
}, j = (e, t, r) => W(pr[e.reason], JSON.stringify({ failure: e }), t, r), To = /* @__PURE__ */ new Set(["refresh", "save", "preview"]), ko = /* @__PURE__ */ new Set(["edit", "save", "preview", "revisions", "revision"]), ht = (e, t) => {
|
|
724
734
|
const r = To.has(t) ? ["POST"] : ["GET", "HEAD"];
|
|
725
735
|
return r.includes(e.method.toUpperCase()) ? null : W(405, JSON.stringify({ failure: { reason: "invalid" } }), void 0, { Allow: r.join(", ") });
|
|
726
|
-
}, yt = (e) => e.headers.get(
|
|
736
|
+
}, yt = (e) => e.headers.get(Le) === wr && xt(e, Ot) === void 0, So = (e) => e.headers.get(Le) === hr && xt(e, Ot) === void 0, xo = async (e, t) => {
|
|
727
737
|
const [r, ...n] = (e.headers.get("Content-Type") ?? "").split(";").map((k) => k.trim().toLowerCase()), a = n.find((k) => k.startsWith("charset="));
|
|
728
738
|
if (r !== Er || a !== void 0 && a !== "charset=utf-8") return { status: "error", failure: { reason: "invalid" } };
|
|
729
739
|
const i = Number(e.headers.get("Content-Length") ?? "0");
|
|
@@ -773,7 +783,7 @@ const un = (e) => e instanceof Error && Object.hasOwn(e, Pt) && Tt(e.reason), dn
|
|
|
773
783
|
throw new TypeError("[markdown-explorer] logger must be an object with an error function");
|
|
774
784
|
const c = e.logger === void 0 ? cn : e.logger, m = St(e.deny), h = e.deferredTimeoutMs === void 0 ? co : fe("deferredTimeoutMs", e.deferredTimeoutMs, fo), S = e.textMaxBytes === void 0 ? et : fe("textMaxBytes", e.textMaxBytes, tt), w = Oo(e.edit);
|
|
775
785
|
if (w === void 0 && e.editMaxBytes !== void 0) throw new TypeError("[markdown-explorer] editMaxBytes needs the edit ports");
|
|
776
|
-
const y = e.editMaxBytes === void 0 ? et : fe("editMaxBytes", e.editMaxBytes, tt), k = Eo(e.treeCache), v = () => Date.now(), L = k === !1 ? Yn(v) : Gn({ ...k, now: v }), A = Cn(e.sanitizer, t.multiView.maxPanels), R = Xn({ iframeHosts: t.iframeHosts, dataPath: t.dataPath, options: A, pool: Hn(
|
|
786
|
+
const y = e.editMaxBytes === void 0 ? et : fe("editMaxBytes", e.editMaxBytes, tt), k = Eo(e.treeCache), v = () => Date.now(), L = k === !1 ? Yn(v) : Gn({ ...k, now: v }), A = Cn(e.sanitizer, t.multiView.maxPanels), R = Xn({ iframeHosts: t.iframeHosts, dataPath: t.dataPath, options: A, pool: Bn(Hn(), A) }), z = new Map(n.map((o) => [o.id, o])), _ = Or(t), { authenticate: I, principalKey: D, signedOutPage: B, forbiddenPage: p, onTreeRefreshed: g } = e, E = (o, u) => {
|
|
777
787
|
if (typeof o.label == "string") return o.label;
|
|
778
788
|
const s = o.label(u);
|
|
779
789
|
if (typeof s != "string" || s.trim() === "") throw new TypeError(`[markdown-explorer] the label of source ${JSON.stringify(o.id)} must be a non-blank string`);
|
|
@@ -893,11 +903,11 @@ const un = (e) => e instanceof Error && Object.hasOwn(e, Pt) && Tt(e.reason), dn
|
|
|
893
903
|
const b = await R(f.html, { scope: u, signal: o.signal });
|
|
894
904
|
return b.status === "sanitized" ? { kind: "markdown", name: f.name, htmlContent: b.html, headings: f.headings, edit: f.edit } : (b.cause !== null && oe(c, { operation: "document", path: s, error: b.cause }), Q(b.reason));
|
|
895
905
|
}, ye = async (o) => {
|
|
896
|
-
if (e.notices === void 0) return
|
|
906
|
+
if (e.notices === void 0) return Pe;
|
|
897
907
|
try {
|
|
898
908
|
return ao(await e.notices(o));
|
|
899
909
|
} catch (u) {
|
|
900
|
-
return G(u, { operation: "notices" }, o.signal, c),
|
|
910
|
+
return G(u, { operation: "notices" }, o.signal, c), Pe;
|
|
901
911
|
}
|
|
902
912
|
}, Jt = async (o, u, s) => {
|
|
903
913
|
const d = ce(u, ae.path);
|
|
@@ -905,7 +915,7 @@ const un = (e) => e instanceof Error && Object.hasOwn(e, Pt) && Tt(e.reason), dn
|
|
|
905
915
|
const l = gr(u);
|
|
906
916
|
if (l === null) return j({ reason: "invalid" }, s);
|
|
907
917
|
if (m.deniesPath(d))
|
|
908
|
-
return
|
|
918
|
+
return Ae(c, { operation: "asset", path: d }), j({ reason: "forbidden" }, s);
|
|
909
919
|
const f = await M(o, d);
|
|
910
920
|
if (f.status === "error") return j(f.failure, s);
|
|
911
921
|
try {
|
|
@@ -916,7 +926,7 @@ const un = (e) => e instanceof Error && Object.hasOwn(e, Pt) && Tt(e.reason), dn
|
|
|
916
926
|
}
|
|
917
927
|
}, Gt = async (o, u) => {
|
|
918
928
|
if (m.deniesPath(u))
|
|
919
|
-
return
|
|
929
|
+
return Ae(c, { operation: "text", path: u }), Q("forbidden");
|
|
920
930
|
const s = await M(o, u);
|
|
921
931
|
if (s.status === "error") return { kind: "failure", failure: s.failure };
|
|
922
932
|
try {
|
|
@@ -925,7 +935,7 @@ const un = (e) => e instanceof Error && Object.hasOwn(e, Pt) && Tt(e.reason), dn
|
|
|
925
935
|
} catch (d) {
|
|
926
936
|
return { kind: "failure", failure: G(d, { operation: "text", path: u }, o.signal, c) };
|
|
927
937
|
}
|
|
928
|
-
}, pe = async (o, u, s) => m.deniesPath(s) ? (
|
|
938
|
+
}, pe = async (o, u, s) => m.deniesPath(s) ? (Ae(c, { operation: u, path: s }), { status: "error", failure: { reason: "forbidden" } }) : M(o, s), Yt = async (o, u, s) => {
|
|
929
939
|
const d = await pe(u, "edit", s);
|
|
930
940
|
if (d.status === "error") return { kind: "failure", failure: d.failure };
|
|
931
941
|
try {
|
|
@@ -984,7 +994,7 @@ const un = (e) => e instanceof Error && Object.hasOwn(e, Pt) && Tt(e.reason), dn
|
|
|
984
994
|
return F.status === "error" ? j(F.failure, f) : u === "preview" ? W(200, JSON.stringify(await Kt(o, s, d, b, F.text)), f) : W(200, JSON.stringify(await Wt(o, s, b, P, F.text)), f);
|
|
985
995
|
}, qt = async ({ request: o, url: u, params: s }) => {
|
|
986
996
|
const d = mt(await I(o, dt)), l = lt(d.headers);
|
|
987
|
-
if (l.set("Cache-Control", Dt), d.status === "signed-out") throw pt("signedOutPage",
|
|
997
|
+
if (l.set("Cache-Control", Dt), d.status === "signed-out") throw pt("signedOutPage", B(o, l));
|
|
988
998
|
if (d.status === "forbidden") throw p === void 0 ? Ue(null, { status: 403, headers: l }) : pt("forbiddenPage", p(o, l));
|
|
989
999
|
const f = _r(a, s["*"], u.searchParams);
|
|
990
1000
|
if (f.kind === "redirect") throw Sr(f.href, { headers: l });
|
|
@@ -992,14 +1002,14 @@ const un = (e) => e instanceof Error && Object.hasOwn(e, Pt) && Tt(e.reason), dn
|
|
|
992
1002
|
if (re === void 0) throw new RangeError(`[markdown-explorer] no source for ${JSON.stringify(b.source)}`);
|
|
993
1003
|
const we = { signal: o.signal, timeoutMs: h, late: null, handOverMs: h }, ne = {
|
|
994
1004
|
scope: F,
|
|
995
|
-
sources: n.map((
|
|
1005
|
+
sources: n.map((H) => ({ id: H.id, label: E(H, P) })),
|
|
996
1006
|
settings: Ar(Nr(o.headers.get("Cookie"), t.settingsCookie), _),
|
|
997
1007
|
tree: b.view === "single" ? null : {
|
|
998
1008
|
sourceId: b.source,
|
|
999
|
-
result:
|
|
1009
|
+
result: _e(we, (H) => V(re, P, F, o, H).then((Y) => Y.result))
|
|
1000
1010
|
},
|
|
1001
|
-
documents: bo(b).map((
|
|
1002
|
-
notices:
|
|
1011
|
+
documents: bo(b).map((H) => ({ path: H, document: _e(we, (Y) => ie({ principal: P, request: o, signal: Y, refresh: !1 }, F, H)) })),
|
|
1012
|
+
notices: _e({ signal: o.signal, timeoutMs: h, late: Pe, handOverMs: 0 }, (H) => ye({ principal: P, request: o, signal: H, refresh: !1 }))
|
|
1003
1013
|
};
|
|
1004
1014
|
return Ue(ne, { headers: l });
|
|
1005
1015
|
}, De = async (o, u) => {
|
|
@@ -1023,8 +1033,8 @@ const un = (e) => e instanceof Error && Object.hasOwn(e, Pt) && Tt(e.reason), dn
|
|
|
1023
1033
|
if (o === "document") {
|
|
1024
1034
|
const Y = ce(s, ae.path);
|
|
1025
1035
|
if (Y === null || !q(Y)) return re();
|
|
1026
|
-
const
|
|
1027
|
-
return
|
|
1036
|
+
const Be = u.headers.has(Le);
|
|
1037
|
+
return Be && !yt(u) ? j({ reason: "forbidden" }, f) : W(200, JSON.stringify(await ie({ ...F, refresh: Be }, P, Y)), f);
|
|
1028
1038
|
}
|
|
1029
1039
|
if (o === "text") {
|
|
1030
1040
|
const Y = ce(s, ae.path);
|
|
@@ -1034,14 +1044,14 @@ const un = (e) => e instanceof Error && Object.hasOwn(e, Pt) && Tt(e.reason), dn
|
|
|
1034
1044
|
return w === void 0 ? j({ reason: "not-found" }, f) : Qt(w, o, F, P, s, f);
|
|
1035
1045
|
const we = ce(s, ae.source), ne = ce(s, ae.path);
|
|
1036
1046
|
if (we === null || (o === "children" || o === "ancestors" || o === "reveal") && (ne === null || !q(ne))) return re();
|
|
1037
|
-
const
|
|
1038
|
-
if (
|
|
1039
|
-
if (o === "tree") return W(200, (await V(
|
|
1047
|
+
const H = z.get(we);
|
|
1048
|
+
if (H === void 0) return j({ reason: "not-found" }, f);
|
|
1049
|
+
if (o === "tree") return W(200, (await V(H, b, P, u, u.signal)).json, f);
|
|
1040
1050
|
if (o === "refresh") {
|
|
1041
|
-
const Y = await J(
|
|
1042
|
-
return u.signal.aborted || se(
|
|
1051
|
+
const Y = await J(H, b, P, u);
|
|
1052
|
+
return u.signal.aborted || se(H, O(H, P)), W(200, Y.json, f);
|
|
1043
1053
|
}
|
|
1044
|
-
return o === "ancestors" ?
|
|
1054
|
+
return o === "ancestors" ? H.ancestors === void 0 || ne === null ? j({ reason: "not-found" }, f) : W(200, JSON.stringify(await ee(H, H.ancestors, F, ne)), f) : o === "reveal" ? ne === null ? re() : W(200, JSON.stringify(await te(H, F, ne)), f) : H.children === void 0 || ne === null ? j({ reason: "not-found" }, f) : W(200, JSON.stringify(await C(H, H.children, F, ne)), f);
|
|
1045
1055
|
}, tr = async (o) => {
|
|
1046
1056
|
const { authentication: u, headers: s } = await De(o, po);
|
|
1047
1057
|
if (!s.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)");
|
|
@@ -1052,7 +1062,7 @@ const un = (e) => e instanceof Error && Object.hasOwn(e, Pt) && Tt(e.reason), dn
|
|
|
1052
1062
|
} catch (s) {
|
|
1053
1063
|
return j(G(ft(s), { operation: "authenticate" }, u.signal, c));
|
|
1054
1064
|
}
|
|
1055
|
-
},
|
|
1065
|
+
}, He = async (o, u, s) => {
|
|
1056
1066
|
if (new URL(o.url).pathname.endsWith(".data")) return j({ reason: "not-found" });
|
|
1057
1067
|
if (!mr(s)) return j({ reason: "not-found" });
|
|
1058
1068
|
if (s === "link-card") {
|
|
@@ -1074,8 +1084,8 @@ const un = (e) => e instanceof Error && Object.hasOwn(e, Pt) && Tt(e.reason), dn
|
|
|
1074
1084
|
return Object.freeze({
|
|
1075
1085
|
loader: qt,
|
|
1076
1086
|
headers: Ro,
|
|
1077
|
-
dataLoader: ({ request: o, url: u, params: s }) =>
|
|
1078
|
-
dataAction: ({ request: o, url: u, params: s }) =>
|
|
1087
|
+
dataLoader: ({ request: o, url: u, params: s }) => He(o, u, s["*"]),
|
|
1088
|
+
dataAction: ({ request: o, url: u, params: s }) => He(o, u, s["*"]),
|
|
1079
1089
|
forgetTree: (o) => {
|
|
1080
1090
|
if (typeof o != "string") throw new TypeError(`[markdown-explorer] forgetTree needs the string key onTreeRefreshed received; got ${typeof o}`);
|
|
1081
1091
|
L.forget(o);
|
|
@@ -1262,7 +1272,7 @@ const un = (e) => e instanceof Error && Object.hasOwn(e, Pt) && Tt(e.reason), dn
|
|
|
1262
1272
|
"jenkinsfile",
|
|
1263
1273
|
"brewfile",
|
|
1264
1274
|
"codeowners"
|
|
1265
|
-
]),
|
|
1275
|
+
]), Ht = typeof me.O_NOFOLLOW == "number" ? me.O_NOFOLLOW : 0, Bt = typeof me.O_NONBLOCK == "number" ? me.O_NONBLOCK : 0, gt = (e) => `${e.size}-${e.mtimeNs}`, No = (e) => e !== "" && e !== "." && e !== ".." && !e.includes(":") && !e.endsWith(".") && !e.endsWith(" "), Et = (e) => q(e) && e === e.normalize("NFC") && e.split("/").every(No), Ft = (e) => {
|
|
1266
1276
|
const t = e.toLowerCase(), r = t.lastIndexOf(".");
|
|
1267
1277
|
return r < 0 ? "" : t.slice(r + 1);
|
|
1268
1278
|
}, Io = (e) => {
|
|
@@ -1272,7 +1282,7 @@ const un = (e) => e instanceof Error && Object.hasOwn(e, Pt) && Tt(e.reason), dn
|
|
|
1272
1282
|
if (r !== void 0) return r.kind === "image" ? { kind: "image" } : { kind: "media", mediaType: r.mediaType };
|
|
1273
1283
|
const n = e.toLowerCase();
|
|
1274
1284
|
return _o.has(t) || !n.includes(".") && Ao.has(n) ? { kind: "text" } : { kind: "file" };
|
|
1275
|
-
},
|
|
1285
|
+
}, $e = (e) => {
|
|
1276
1286
|
switch (typeof e == "object" && e !== null ? e.code : void 0) {
|
|
1277
1287
|
case "ENOENT":
|
|
1278
1288
|
case "ENOTDIR":
|
|
@@ -1289,7 +1299,7 @@ const un = (e) => e instanceof Error && Object.hasOwn(e, Pt) && Tt(e.reason), dn
|
|
|
1289
1299
|
return null;
|
|
1290
1300
|
}
|
|
1291
1301
|
}, Ut = (e) => {
|
|
1292
|
-
const t =
|
|
1302
|
+
const t = $e(e);
|
|
1293
1303
|
return t === null ? e : new Se(t);
|
|
1294
1304
|
}, Xt = (e) => {
|
|
1295
1305
|
const t = typeof e == "object" && e !== null ? e.code : void 0;
|
|
@@ -1309,13 +1319,13 @@ const un = (e) => e instanceof Error && Object.hasOwn(e, Pt) && Tt(e.reason), dn
|
|
|
1309
1319
|
}, Mo = (e, t) => e !== null ? { start: e.offset, end: e.offset + e.length - 1 } : t === 0n ? {} : { start: 0, end: Number(t) - 1 }, $o = async (e, t, r, n) => {
|
|
1310
1320
|
let a;
|
|
1311
1321
|
try {
|
|
1312
|
-
a = await Rt(e, me.O_RDONLY |
|
|
1322
|
+
a = await Rt(e, me.O_RDONLY | Ht | Bt);
|
|
1313
1323
|
const h = await a.stat({ bigint: !0 });
|
|
1314
1324
|
if (!h.isFile() || h.ino !== t.ino || h.dev !== t.dev || h.size !== t.size || h.mtimeNs !== t.mtimeNs) throw new Se("not-found");
|
|
1315
1325
|
} catch (h) {
|
|
1316
1326
|
throw await a?.close(), Ut(h);
|
|
1317
1327
|
}
|
|
1318
|
-
const i = a.createReadStream(Mo(r, t.size)), c =
|
|
1328
|
+
const i = a.createReadStream(Mo(r, t.size)), c = Br.toWeb(i), m = () => {
|
|
1319
1329
|
i.destroy(n.reason);
|
|
1320
1330
|
};
|
|
1321
1331
|
return n.aborted ? m() : n.addEventListener("abort", m, { once: !0 }), c;
|
|
@@ -1387,7 +1397,7 @@ const un = (e) => e instanceof Error && Object.hasOwn(e, Pt) && Tt(e.reason), dn
|
|
|
1387
1397
|
const V = await N(async () => {
|
|
1388
1398
|
O.signal.throwIfAborted();
|
|
1389
1399
|
try {
|
|
1390
|
-
return await
|
|
1400
|
+
return await Hr($, { withFileTypes: !0 });
|
|
1391
1401
|
} catch (C) {
|
|
1392
1402
|
if (X === "" || !Xt(C)) throw C;
|
|
1393
1403
|
return null;
|
|
@@ -1436,7 +1446,7 @@ const un = (e) => e instanceof Error && Object.hasOwn(e, Pt) && Tt(e.reason), dn
|
|
|
1436
1446
|
if (!N.isFile()) return { status: "refused", reason: "unsupported" };
|
|
1437
1447
|
const M = await Cr(T);
|
|
1438
1448
|
return M !== T || h.deniesPath(Je(c, M).split(Ge).join("/")) ? { status: "refused", reason: "forbidden" } : { status: "file", target: T, name: O.slice(O.lastIndexOf("/") + 1), stats: N };
|
|
1439
|
-
},
|
|
1449
|
+
}, B = async (E, O, T) => {
|
|
1440
1450
|
let N;
|
|
1441
1451
|
try {
|
|
1442
1452
|
const M = await D(T);
|
|
@@ -1445,7 +1455,7 @@ const un = (e) => e instanceof Error && Object.hasOwn(e, Pt) && Tt(e.reason), dn
|
|
|
1445
1455
|
if (V.kind === "image") return { kind: "image", name: $, version: J };
|
|
1446
1456
|
if (V.kind === "media") return { kind: "media", name: $, mediaType: V.mediaType, version: J };
|
|
1447
1457
|
if (V.kind === "file") return { kind: "file", name: $, version: J };
|
|
1448
|
-
N = await Rt(U, me.O_RDONLY |
|
|
1458
|
+
N = await Rt(U, me.O_RDONLY | Ht | Bt);
|
|
1449
1459
|
const se = await N.stat({ bigint: !0 });
|
|
1450
1460
|
if (!se.isFile() || se.ino !== X.ino || se.dev !== X.dev) return Q("forbidden");
|
|
1451
1461
|
if (V.kind === "markdown") {
|
|
@@ -1460,7 +1470,7 @@ const un = (e) => e instanceof Error && Object.hasOwn(e, Pt) && Tt(e.reason), dn
|
|
|
1460
1470
|
const Z = se.size > BigInt(y), ee = new TextDecoder("utf-8").decode(C, { stream: Z });
|
|
1461
1471
|
return { kind: "text", name: $, text: ee, truncated: Z, version: J };
|
|
1462
1472
|
} catch (M) {
|
|
1463
|
-
const U =
|
|
1473
|
+
const U = $e(M);
|
|
1464
1474
|
if (U === null) throw M;
|
|
1465
1475
|
return Q(U);
|
|
1466
1476
|
} finally {
|
|
@@ -1481,7 +1491,7 @@ const un = (e) => e instanceof Error && Object.hasOwn(e, Pt) && Tt(e.reason), dn
|
|
|
1481
1491
|
try {
|
|
1482
1492
|
N = await D(T);
|
|
1483
1493
|
} catch ($) {
|
|
1484
|
-
if (
|
|
1494
|
+
if ($e($) !== null) return null;
|
|
1485
1495
|
throw $;
|
|
1486
1496
|
}
|
|
1487
1497
|
if (N.status === "refused") return null;
|
|
@@ -1497,7 +1507,7 @@ const un = (e) => e instanceof Error && Object.hasOwn(e, Pt) && Tt(e.reason), dn
|
|
|
1497
1507
|
boundary: Object.freeze({ contains: (E) => E.startsWith(m) }),
|
|
1498
1508
|
tree: I,
|
|
1499
1509
|
ancestors: g,
|
|
1500
|
-
document:
|
|
1510
|
+
document: B,
|
|
1501
1511
|
asset: p
|
|
1502
1512
|
});
|
|
1503
1513
|
};
|