Fix authenticated inline audio playback

Route the three supported audio extensions through the existing authenticated localhost media proxy, matching image and video attachments.

Co-authored-by: Max <d8473ee32b973aa31a21a65adddcc4b69cc2a8a4dee8121ecd51926e0cddbc02@buzz.block.builderlab.xyz>
Signed-off-by: Max <d8473ee32b973aa31a21a65adddcc4b69cc2a8a4dee8121ecd51926e0cddbc02@buzz.block.builderlab.xyz>
This commit is contained in:
Max
2026-08-20 11:36:03 -04:00
parent 9239abb57f
commit f294652ca3
2 changed files with 33 additions and 1 deletions

View File

@@ -27,6 +27,38 @@ test("mediaProxyUrl: uses the IPv4 loopback literal for the localhost proxy", ()
);
});
test("rewriteRelayUrl: routes each supported audio format through the authenticated proxy", async () => {
const previousWindow = globalThis.window;
globalThis.window = {
__TAURI_INTERNALS__: {
invoke(command) {
if (command === "get_media_proxy_port") return Promise.resolve(54321);
if (command === "get_relay_http_url") {
return Promise.resolve("https://relay.example");
}
return Promise.reject(new Error(`Unexpected command: ${command}`));
},
},
};
try {
const mediaUrl = await import(`./mediaUrl.ts?audioProxy=${Date.now()}`);
mediaUrl.rewriteRelayUrl(`https://relay.example/media/${HASH}.mp3`);
await new Promise((resolve) => setTimeout(resolve, 0));
for (const extension of ["mp3", "wav", "ogg"]) {
assert.equal(
mediaUrl.rewriteRelayUrl(
`https://relay.example/media/${HASH}.${extension}`,
),
`http://127.0.0.1:54321/media/${HASH}.${extension}`,
);
}
} finally {
globalThis.window = previousWindow;
}
});
test("media-proxy port store: resolved port publishes and reset notifies subscribers", async () => {
const previousWindow = globalThis.window;
let notifications = 0;

View File

@@ -20,7 +20,7 @@ import { invoke } from "@tauri-apps/api/core";
// Matches: https://anything.com/media/{64-hex}.{ext}
// Also matches thumbnails: /media/{64-hex}.thumb.jpg
const RELAY_MEDIA_RE =
/^(?:https?:\/\/[^/]+)\/media\/([\da-f]{64}(?:\.thumb)?\.(?:jpg|png|gif|webp|mp4|webm|mov)(?:\?.*)?)$/;
/^(?:https?:\/\/[^/]+)\/media\/([\da-f]{64}(?:\.thumb)?\.(?:jpg|png|gif|webp|mp4|webm|mov|mp3|wav|ogg)(?:\?.*)?)$/;
/** Cached proxy port — fetched once from the Tauri backend. */
let cachedPort: number | null = null;