@geravant/sinain 1.22.0 → 1.22.3
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/package.json +1 -1
- package/sinain-core/src/server.ts +25 -5
package/package.json
CHANGED
|
@@ -412,6 +412,7 @@ async function api(path, opts = {}) {
|
|
|
412
412
|
const SHARE_PEERJS_HOST = __SHARE_PEERJS_HOST__; // empty string → peerjs.com cloud
|
|
413
413
|
const SHARE_INLINE_MAX_BYTES = __SHARE_INLINE_MAX_BYTES__;
|
|
414
414
|
const SHARE_TTL_HOURS = __SHARE_TTL_HOURS__;
|
|
415
|
+
const SHARE_BASE_URL = __SHARE_BASE_URL__; // public redirector that points to localhost
|
|
415
416
|
|
|
416
417
|
// ── Router ────────────────────────────────────────────────────────────────
|
|
417
418
|
function navigate(path) {
|
|
@@ -508,6 +509,17 @@ const ShareManager = (() => {
|
|
|
508
509
|
return await r.text();
|
|
509
510
|
}
|
|
510
511
|
|
|
512
|
+
// Build the public-shareable URL. Recipient pastes this anywhere; the
|
|
513
|
+
// redirector at SHARE_BASE_URL does a client-side rewrite to their local
|
|
514
|
+
// sinain-core (location.href = "http://localhost:<port>/...#hash") with
|
|
515
|
+
// the fragment preserved (browsers don't send fragments to the server,
|
|
516
|
+
// so bundle bytes never touch the CDN).
|
|
517
|
+
function buildShareUrl(entity, hash) {
|
|
518
|
+
const port = location.port || (location.protocol === "https:" ? "443" : "80");
|
|
519
|
+
const params = new URLSearchParams({ entity, port });
|
|
520
|
+
return SHARE_BASE_URL + "?" + params.toString() + hash;
|
|
521
|
+
}
|
|
522
|
+
|
|
511
523
|
async function createShare(entity) {
|
|
512
524
|
const bundle = await buildBundle(entity);
|
|
513
525
|
const sizeBytes = new TextEncoder().encode(bundle).length;
|
|
@@ -515,8 +527,7 @@ const ShareManager = (() => {
|
|
|
515
527
|
|
|
516
528
|
if (sizeBytes <= SHARE_INLINE_MAX_BYTES) {
|
|
517
529
|
const compressed = await gzipBase64(bundle);
|
|
518
|
-
const url =
|
|
519
|
-
encodeURIComponent(entity) + "#bundle=" + compressed;
|
|
530
|
+
const url = buildShareUrl(entity, "#bundle=" + compressed);
|
|
520
531
|
await api("/knowledge/shares", { method: "POST",
|
|
521
532
|
headers: {"Content-Type": "application/json"},
|
|
522
533
|
body: JSON.stringify({
|
|
@@ -537,8 +548,7 @@ const ShareManager = (() => {
|
|
|
537
548
|
peer.on("error", e => rej(e));
|
|
538
549
|
setTimeout(() => rej(new Error("peerjs broker timeout")), 8000);
|
|
539
550
|
});
|
|
540
|
-
const url =
|
|
541
|
-
encodeURIComponent(entity) + "#peer=" + token;
|
|
551
|
+
const url = buildShareUrl(entity, "#peer=" + token);
|
|
542
552
|
await api("/knowledge/shares", { method: "POST",
|
|
543
553
|
headers: {"Content-Type": "application/json"},
|
|
544
554
|
body: JSON.stringify({
|
|
@@ -1276,10 +1286,20 @@ function renderKnowledgeUiV2(): string {
|
|
|
1276
1286
|
const peerHost = process.env.SINAIN_PEERJS_HOST || ""; // empty = peerjs.com cloud default
|
|
1277
1287
|
const inlineMax = parseInt(process.env.SINAIN_SHARE_INLINE_MAX_BYTES || "6000");
|
|
1278
1288
|
const ttlHours = parseInt(process.env.SINAIN_SHARE_TTL_HOURS || "24");
|
|
1289
|
+
// Public URL of the share-redirector. Self-hosted on the existing
|
|
1290
|
+
// sinain.duckdns.org Caddy + Let's Encrypt setup that already fronts the
|
|
1291
|
+
// OpenClaw gateway. We control the host, headers, and reliability — no
|
|
1292
|
+
// CDN policy quirks (jsDelivr serves gh-path HTML as text/plain;
|
|
1293
|
+
// raw.githack.com returns 403 with body). Browsers preserve URL fragments
|
|
1294
|
+
// through redirects without sending them to the server, so bundle bytes
|
|
1295
|
+
// in #bundle=… never touch our host either.
|
|
1296
|
+
const shareBaseUrl = process.env.SINAIN_SHARE_BASE_URL
|
|
1297
|
+
|| "https://sinain.duckdns.org/share.html";
|
|
1279
1298
|
return KNOWLEDGE_UI_V2_HTML
|
|
1280
1299
|
.replace(/__SHARE_PEERJS_HOST__/g, JSON.stringify(peerHost))
|
|
1281
1300
|
.replace(/__SHARE_INLINE_MAX_BYTES__/g, String(inlineMax))
|
|
1282
|
-
.replace(/__SHARE_TTL_HOURS__/g, String(ttlHours))
|
|
1301
|
+
.replace(/__SHARE_TTL_HOURS__/g, String(ttlHours))
|
|
1302
|
+
.replace(/__SHARE_BASE_URL__/g, JSON.stringify(shareBaseUrl));
|
|
1283
1303
|
}
|
|
1284
1304
|
|
|
1285
1305
|
/** Server epoch — lets clients detect restarts. */
|