@geravant/sinain 1.22.0 → 1.22.1
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 +21 -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,16 @@ 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 (docs/share.html in the repo). Browsers
|
|
1290
|
+
// preserve URL fragments through redirects without sending them to the
|
|
1291
|
+
// server, so the bundle bytes never touch this CDN.
|
|
1292
|
+
const shareBaseUrl = process.env.SINAIN_SHARE_BASE_URL
|
|
1293
|
+
|| "https://cdn.jsdelivr.net/gh/anthillnet/sinain-hud@main/docs/share.html";
|
|
1279
1294
|
return KNOWLEDGE_UI_V2_HTML
|
|
1280
1295
|
.replace(/__SHARE_PEERJS_HOST__/g, JSON.stringify(peerHost))
|
|
1281
1296
|
.replace(/__SHARE_INLINE_MAX_BYTES__/g, String(inlineMax))
|
|
1282
|
-
.replace(/__SHARE_TTL_HOURS__/g, String(ttlHours))
|
|
1297
|
+
.replace(/__SHARE_TTL_HOURS__/g, String(ttlHours))
|
|
1298
|
+
.replace(/__SHARE_BASE_URL__/g, JSON.stringify(shareBaseUrl));
|
|
1283
1299
|
}
|
|
1284
1300
|
|
|
1285
1301
|
/** Server epoch — lets clients detect restarts. */
|