From f294652ca38fc472a7237351fb4b33ba79d74f35 Mon Sep 17 00:00:00 2001 From: Max Date: Thu, 20 Aug 2026 11:36:03 -0400 Subject: [PATCH] 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 Signed-off-by: Max --- desktop/src/shared/lib/mediaUrl.test.mjs | 32 ++++++++++++++++++++++++ desktop/src/shared/lib/mediaUrl.ts | 2 +- 2 files changed, 33 insertions(+), 1 deletion(-) diff --git a/desktop/src/shared/lib/mediaUrl.test.mjs b/desktop/src/shared/lib/mediaUrl.test.mjs index 96c004ec56..9d714152d0 100644 --- a/desktop/src/shared/lib/mediaUrl.test.mjs +++ b/desktop/src/shared/lib/mediaUrl.test.mjs @@ -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; diff --git a/desktop/src/shared/lib/mediaUrl.ts b/desktop/src/shared/lib/mediaUrl.ts index 76ae8d65b8..d653c3c8ec 100644 --- a/desktop/src/shared/lib/mediaUrl.ts +++ b/desktop/src/shared/lib/mediaUrl.ts @@ -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;