@maintainer-pro/ai-bridge 0.1.19 → 0.1.20
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 +9 -19
package/package.json
CHANGED
package/src/share-rewrite.mjs
CHANGED
|
@@ -284,8 +284,8 @@ function isProbablyUtf8Text(buf) {
|
|
|
284
284
|
}
|
|
285
285
|
|
|
286
286
|
/**
|
|
287
|
-
* Replace app
|
|
288
|
-
*
|
|
287
|
+
* Replace loopback app origins only (`localhost:8080`, `127.0.0.1`, `::1`,
|
|
288
|
+
* `0.0.0.0`). Real hostnames and other base URLs are left unchanged.
|
|
289
289
|
*
|
|
290
290
|
* @param {string} text
|
|
291
291
|
* @param {Record<string, string> | null | undefined} portUrls
|
|
@@ -297,14 +297,7 @@ export function rewriteMappedLocalUrls(text, portUrls) {
|
|
|
297
297
|
.filter((port) => Number.isInteger(port) && port > 0 && port <= 65535)
|
|
298
298
|
.sort((a, b) => b - a);
|
|
299
299
|
if (!ports.length) return text;
|
|
300
|
-
const localHost =
|
|
301
|
-
"(?:localhost|127\\.0\\.0\\.1|\\[::1\\]|::1|0\\.0\\.0\\.0|" +
|
|
302
|
-
"10\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}|" +
|
|
303
|
-
"192\\.168\\.\\d{1,3}\\.\\d{1,3}|" +
|
|
304
|
-
"172\\.(?:1[6-9]|2\\d|3[01])\\.\\d{1,3}\\.\\d{1,3}|" +
|
|
305
|
-
"169\\.254\\.\\d{1,3}\\.\\d{1,3}|" +
|
|
306
|
-
"[A-Za-z0-9](?:[A-Za-z0-9-]{0,61}[A-Za-z0-9])?(?:\\.(?:local|lan|internal|home))?)";
|
|
307
|
-
const anyHost = "(?:[^\\s'\"\\\\/<>@:]+|\\[[0-9a-fA-F:]+\\])";
|
|
300
|
+
const localHost = "(?:localhost|127\\.0\\.0\\.1|\\[::1\\]|::1|0\\.0\\.0\\.0)";
|
|
308
301
|
let out = String(text);
|
|
309
302
|
for (let i = 0; i < ports.length; i++) {
|
|
310
303
|
const port = ports[i];
|
|
@@ -339,12 +332,6 @@ export function rewriteMappedLocalUrls(text, portUrls) {
|
|
|
339
332
|
out = out.replace(new RegExp("//" + localHost + ":" + port + tail, "gi"), function (m) {
|
|
340
333
|
return swap(m, dest.replace(/^https?:/i, ""));
|
|
341
334
|
});
|
|
342
|
-
out = out.replace(new RegExp("http://" + anyHost + ":" + port + tail, "gi"), function (m) {
|
|
343
|
-
return swap(m, dest);
|
|
344
|
-
});
|
|
345
|
-
out = out.replace(new RegExp("ws://" + anyHost + ":" + port + tail, "gi"), function (m) {
|
|
346
|
-
return swap(m, destWs);
|
|
347
|
-
});
|
|
348
335
|
out = out.replace(
|
|
349
336
|
new RegExp("(?<![\\w./])" + localHost + ":" + port + tail, "gi"),
|
|
350
337
|
function (m) {
|
|
@@ -452,9 +439,10 @@ export function prefixShareOriginUrl(value, publicBase) {
|
|
|
452
439
|
const basePort = base.port || (base.protocol === "https:" ? "443" : "80");
|
|
453
440
|
if (reqPort !== basePort) return value;
|
|
454
441
|
const path = u.pathname || "/";
|
|
442
|
+
if (path === "/" || path === "") return value;
|
|
455
443
|
if (path === prefix || path.indexOf(prefix + "/") === 0) return u.toString();
|
|
456
444
|
if (path.indexOf("/p/") === 0) return u.toString();
|
|
457
|
-
u.pathname =
|
|
445
|
+
u.pathname = prefix + path;
|
|
458
446
|
return u.toString();
|
|
459
447
|
} catch {
|
|
460
448
|
return value;
|
|
@@ -475,11 +463,11 @@ export function rewriteShareOriginPaths(text, publicBase) {
|
|
|
475
463
|
.replace(/\//g, "\\/")
|
|
476
464
|
.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
477
465
|
let out = String(text);
|
|
478
|
-
out = out.replace(new RegExp(originEsc + "(
|
|
466
|
+
out = out.replace(new RegExp(originEsc + "/(?!p/)[^\\s'\"<>\\\\]+", "gi"), function (matched) {
|
|
479
467
|
return prefixShareOriginUrl(matched, publicBase);
|
|
480
468
|
});
|
|
481
469
|
out = out.replace(
|
|
482
|
-
new RegExp(originSlashEsc + "(
|
|
470
|
+
new RegExp(originSlashEsc + "\\\\/(?!p/)[^\\s'\"<>]+", "gi"),
|
|
483
471
|
function (matched) {
|
|
484
472
|
const unescaped = matched.replace(/\\\//g, "/");
|
|
485
473
|
return prefixShareOriginUrl(unescaped, publicBase).replace(/\//g, "\\/");
|
|
@@ -1024,6 +1012,7 @@ function shareProxyShim(p, portMap, rewriteMappedLocalUrls) {
|
|
|
1024
1012
|
try {
|
|
1025
1013
|
var nav = new URL(v, location.href);
|
|
1026
1014
|
if (nav.origin !== location.origin) return v;
|
|
1015
|
+
if (nav.pathname === "/" || nav.pathname === "") return v;
|
|
1027
1016
|
nav.pathname = prefixPath(nav.pathname);
|
|
1028
1017
|
return nav.toString();
|
|
1029
1018
|
} catch (e) {}
|
|
@@ -1229,6 +1218,7 @@ function shareServiceWorkerMain(portMap, tokenRoot, rewriteMappedLocalUrls) {
|
|
|
1229
1218
|
try {
|
|
1230
1219
|
var u = new URL(url, self.location.href);
|
|
1231
1220
|
if (u.origin !== self.location.origin) return url;
|
|
1221
|
+
if (u.pathname === "/" || u.pathname === "") return url;
|
|
1232
1222
|
if (u.pathname.indexOf("/p/") === 0) return url;
|
|
1233
1223
|
if (u.pathname === prefix || u.pathname.indexOf(prefix + "/") === 0) return url;
|
|
1234
1224
|
u.pathname = u.pathname === "/" ? prefix : prefix + u.pathname;
|