mirror of
https://github.com/block/buzz.git
synced 2026-12-01 13:42:45 +00:00
fix(desktop): use IPv4 loopback for media proxy URLs (#1245)
Signed-off-by: npub1mprnacetjua2xx3p5eddmhxyk6wv929ymm5py8kd2xfxurxahspqqlgyta <d8473ee32b973aa31a21a65adddcc4b69cc2a8a4dee8121ecd51926e0cddbc02@sprout-oss.stage.blox.sqprod.co> Co-authored-by: npub1mprnacetjua2xx3p5eddmhxyk6wv929ymm5py8kd2xfxurxahspqqlgyta <d8473ee32b973aa31a21a65adddcc4b69cc2a8a4dee8121ecd51926e0cddbc02@sprout-oss.stage.blox.sqprod.co>
This commit is contained in:
13
desktop/src/shared/lib/mediaUrl.test.mjs
Normal file
13
desktop/src/shared/lib/mediaUrl.test.mjs
Normal file
@@ -0,0 +1,13 @@
|
||||
import assert from "node:assert/strict";
|
||||
import { test } from "node:test";
|
||||
|
||||
import { mediaProxyUrl } from "./mediaUrl.ts";
|
||||
|
||||
const HASH = "a".repeat(64);
|
||||
|
||||
test("mediaProxyUrl: uses the IPv4 loopback literal for the localhost proxy", () => {
|
||||
assert.equal(
|
||||
mediaProxyUrl(54321, `${HASH}.png`),
|
||||
`http://127.0.0.1:54321/media/${HASH}.png`,
|
||||
);
|
||||
});
|
||||
@@ -80,9 +80,18 @@ export function resetMediaCaches(): void {
|
||||
cachedRelayOrigin = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Build the local proxy URL with an IPv4 literal. The Rust proxy binds
|
||||
* `127.0.0.1:0`, not `::1`, and some WebViews resolve `localhost` to IPv6
|
||||
* first. Matching the bind address avoids machine-dependent image failures.
|
||||
*/
|
||||
export function mediaProxyUrl(port: number, mediaPath: string): string {
|
||||
return `http://127.0.0.1:${port}/media/${mediaPath}`;
|
||||
}
|
||||
|
||||
/**
|
||||
* If `url` is a Blossom media URL hosted on the Buzz relay, rewrite it
|
||||
* to go through the localhost streaming proxy. External Blossom URLs and
|
||||
* to go through the local streaming proxy. External Blossom URLs and
|
||||
* non-Blossom URLs are returned unchanged.
|
||||
*
|
||||
* Falls back to buzz-media:// if the proxy port isn't available yet.
|
||||
@@ -100,7 +109,7 @@ export function rewriteRelayUrl(url: string): string {
|
||||
}
|
||||
|
||||
if (cachedPort && cachedPort > 0) {
|
||||
return `http://localhost:${cachedPort}/media/${m[1]}`;
|
||||
return mediaProxyUrl(cachedPort, m[1]);
|
||||
}
|
||||
|
||||
// Kick off fetch if we haven't yet.
|
||||
|
||||
Reference in New Issue
Block a user