@maintainer-pro/ai-bridge 0.1.28 → 0.1.29
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/src/share-rewrite.mjs +45 -19
package/package.json
CHANGED
package/src/share-rewrite.mjs
CHANGED
|
@@ -150,15 +150,22 @@ export function shouldProcessShareResponse(headers) {
|
|
|
150
150
|
return true;
|
|
151
151
|
}
|
|
152
152
|
|
|
153
|
-
function
|
|
154
|
-
const
|
|
153
|
+
function hasContentHash(path) {
|
|
154
|
+
const base = String(path || "").split("?")[0].split("/").pop() || "";
|
|
155
155
|
return (
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
156
|
+
/\.[0-9a-f]{8,}\.(?:js|css|woff2?)$/i.test(base) ||
|
|
157
|
+
/^[0-9a-f]{8,}\.(?:js|css|woff2?)$/i.test(base) ||
|
|
158
|
+
/-[0-9a-f]{8,}[^/]*\.(?:js|css)$/i.test(base)
|
|
159
159
|
);
|
|
160
160
|
}
|
|
161
161
|
|
|
162
|
+
/** Production hashed assets only. Next/Vite dev chunks reuse the same URL. */
|
|
163
|
+
function isImmutableAssetPath(path) {
|
|
164
|
+
const p = String(path || "").split("?")[0] || "";
|
|
165
|
+
if (/\/__nextjs_font\//.test(p)) return true;
|
|
166
|
+
return hasContentHash(p);
|
|
167
|
+
}
|
|
168
|
+
|
|
162
169
|
function isViteDevSourcePath(path) {
|
|
163
170
|
const raw = String(path || "");
|
|
164
171
|
const p = raw.split("?")[0] || "";
|
|
@@ -184,12 +191,12 @@ function isDocumentPath(path) {
|
|
|
184
191
|
|
|
185
192
|
function isNoStorePath(path) {
|
|
186
193
|
const p = String(path || "").split("?")[0] || "";
|
|
194
|
+
if (isImmutableAssetPath(path) || isCacheableMediaPath(path)) return false;
|
|
187
195
|
return (
|
|
188
196
|
/\/embed-config\.js$/i.test(p) ||
|
|
189
197
|
p === "/api" ||
|
|
190
198
|
p.startsWith("/api/") ||
|
|
191
|
-
/\/_next
|
|
192
|
-
/\/_next\/webpack\/hmr/i.test(p) ||
|
|
199
|
+
/\/_next\//i.test(p) ||
|
|
193
200
|
/\/__nextjs_original-stack-frames/i.test(p) ||
|
|
194
201
|
/\/__mp\//.test(p) ||
|
|
195
202
|
isViteDevSourcePath(path) ||
|
|
@@ -241,9 +248,9 @@ function dropHopCacheNoise(headers) {
|
|
|
241
248
|
}
|
|
242
249
|
|
|
243
250
|
/**
|
|
244
|
-
* Cache-Control for the share URL.
|
|
245
|
-
*
|
|
246
|
-
*
|
|
251
|
+
* Cache-Control for the share URL. Only content-hashed assets are immutable.
|
|
252
|
+
* Next/Vite dev chunks reuse URLs, so they must not be cached or HMR/hydration
|
|
253
|
+
* breaks. HTML, RSC, and HMR stay no-store.
|
|
247
254
|
*
|
|
248
255
|
* @param {Record<string, string>} headers
|
|
249
256
|
* @param {string} path
|
|
@@ -485,8 +492,11 @@ export function prefixShareOriginUrl(value, publicBase) {
|
|
|
485
492
|
const basePort = base.port || (base.protocol === "https:" ? "443" : "80");
|
|
486
493
|
if (reqPort !== basePort) return value;
|
|
487
494
|
const path = u.pathname || "/";
|
|
488
|
-
if (path === "/" || path === "") return value;
|
|
489
495
|
if (path === prefix || path.indexOf(prefix + "/") === 0) return u.toString();
|
|
496
|
+
if (path === "/" || path === "") {
|
|
497
|
+
u.pathname = prefix || "/";
|
|
498
|
+
return u.toString();
|
|
499
|
+
}
|
|
490
500
|
if (path.indexOf("/p/") === 0) return u.toString();
|
|
491
501
|
u.pathname = prefix + path;
|
|
492
502
|
return u.toString();
|
|
@@ -722,11 +732,11 @@ function rewriteShareAsLocalEnv(body) {
|
|
|
722
732
|
let out = String(body);
|
|
723
733
|
out = out.replace(
|
|
724
734
|
/(\/\.\*localhost\.\*\/\.test\()([^)]+)(\))/g,
|
|
725
|
-
"($1$2$3||
|
|
735
|
+
"($1$2$3||window.__MP_SHARE_PREFIX__)"
|
|
726
736
|
);
|
|
727
737
|
out = out.replace(
|
|
728
738
|
/((?:window\.)?location\.hostname)\s*===\s*(['"])localhost\2/g,
|
|
729
|
-
"($1===$2localhost$2||
|
|
739
|
+
"($1===$2localhost$2||window.__MP_SHARE_PREFIX__)"
|
|
730
740
|
);
|
|
731
741
|
return out;
|
|
732
742
|
}
|
|
@@ -1026,6 +1036,7 @@ function injectMaintainerProEmbed(html, aiPublicBase) {
|
|
|
1026
1036
|
function shareProxyShim(p, portMap, rewriteMappedLocalUrls, bypassCors) {
|
|
1027
1037
|
if (!p || window.__MP_SHARE_SHIM__) return;
|
|
1028
1038
|
window.__MP_SHARE_SHIM__ = 1;
|
|
1039
|
+
window.__MP_SHARE_PREFIX__ = p;
|
|
1029
1040
|
window.__MP_PORT_MAP__ = portMap || {};
|
|
1030
1041
|
window.__MP_BYPASS_CORS__ = Boolean(bypassCors);
|
|
1031
1042
|
function rewriteText(text) {
|
|
@@ -1121,10 +1132,8 @@ function shareProxyShim(p, portMap, rewriteMappedLocalUrls, bypassCors) {
|
|
|
1121
1132
|
if (v.charAt(0) === "/" && v.charAt(1) !== "/") return prefixPath(v);
|
|
1122
1133
|
try {
|
|
1123
1134
|
var nav = new URL(v, location.href);
|
|
1124
|
-
if (!loopback(nav.hostname)) return v;
|
|
1125
|
-
|
|
1126
|
-
if (nav.pathname === "/" || nav.pathname === "") return v;
|
|
1127
|
-
nav.pathname = prefixPath(nav.pathname);
|
|
1135
|
+
if (!loopback(nav.hostname) && nav.origin !== location.origin) return v;
|
|
1136
|
+
nav.pathname = prefixPath(nav.pathname || "/");
|
|
1128
1137
|
return nav.toString();
|
|
1129
1138
|
} catch (e) {}
|
|
1130
1139
|
return v;
|
|
@@ -1363,6 +1372,24 @@ function shareProxyShim(p, portMap, rewriteMappedLocalUrls, bypassCors) {
|
|
|
1363
1372
|
});
|
|
1364
1373
|
}
|
|
1365
1374
|
} catch (e) {}
|
|
1375
|
+
document.addEventListener(
|
|
1376
|
+
"click",
|
|
1377
|
+
function (e) {
|
|
1378
|
+
if (e.defaultPrevented || e.button !== 0) return;
|
|
1379
|
+
if (e.metaKey || e.ctrlKey || e.shiftKey || e.altKey) return;
|
|
1380
|
+
var a = e.target && e.target.closest ? e.target.closest("a[href]") : null;
|
|
1381
|
+
if (!a || (a.target && a.target !== "" && a.target !== "_self")) return;
|
|
1382
|
+
if (a.hasAttribute("download")) return;
|
|
1383
|
+
var href = a.getAttribute("href");
|
|
1384
|
+
if (!href || href.charAt(0) === "#") return;
|
|
1385
|
+
if (/^(mailto|tel|javascript):/i.test(href)) return;
|
|
1386
|
+
var next = addNav(href);
|
|
1387
|
+
if (!next || next === href) return;
|
|
1388
|
+
e.preventDefault();
|
|
1389
|
+
location.assign(next);
|
|
1390
|
+
},
|
|
1391
|
+
true
|
|
1392
|
+
);
|
|
1366
1393
|
try {
|
|
1367
1394
|
var tokenRoot = p.replace(/\/[^/]+$/, "/");
|
|
1368
1395
|
if (navigator.serviceWorker && tokenRoot.indexOf("/p/") === 0) {
|
|
@@ -1486,9 +1513,8 @@ function shareServiceWorkerMain(portMap, tokenRoot, rewriteMappedLocalUrls, bypa
|
|
|
1486
1513
|
return backend + path + (u.search || "") + (u.hash || "");
|
|
1487
1514
|
}
|
|
1488
1515
|
if (u.origin !== self.location.origin) return url;
|
|
1489
|
-
if (u.pathname === "/" || u.pathname === "") return url;
|
|
1490
1516
|
if (u.pathname === prefix || u.pathname.indexOf(prefix + "/") === 0) return url;
|
|
1491
|
-
u.pathname = u.pathname === "/" ? prefix : prefix + u.pathname;
|
|
1517
|
+
u.pathname = u.pathname === "/" || u.pathname === "" ? prefix : prefix + u.pathname;
|
|
1492
1518
|
return u.toString();
|
|
1493
1519
|
} catch (e) {}
|
|
1494
1520
|
return url;
|