Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions desktop/src-tauri/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -376,10 +376,9 @@ pub fn run() {
// client so WARP tunnelling applies. The port is stored in AppState
// and exposed to the frontend via the `get_media_proxy_port` command.
let proxy_client = state.http_client.clone();
let proxy_base_url = relay::relay_api_base_url_with_override(&state);
let proxy_handle = app_handle.clone();
tauri::async_runtime::spawn(async move {
let port = media_proxy::spawn_media_proxy(proxy_client, proxy_base_url).await;
let port = media_proxy::spawn_media_proxy(proxy_client, proxy_handle.clone()).await;
let state = proxy_handle.state::<AppState>();
state
.media_proxy_port
Expand Down
14 changes: 8 additions & 6 deletions desktop/src-tauri/src/media_proxy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use axum::{
Router,
};
use futures_util::TryStreamExt;
use tauri::http;
use tauri::{http, Manager};
use tokio::net::TcpListener;

use crate::app_state::AppState;
Expand All @@ -22,7 +22,7 @@ const MAX_PROXY_RESPONSE: u64 = 20 * 1024 * 1024;
#[derive(Clone)]
struct ProxyState {
client: reqwest::Client,
base_url: String,
app_handle: tauri::AppHandle,
}

async fn proxy_handler(AxumState(state): AxumState<ProxyState>, req: Request) -> Response {
Expand All @@ -44,8 +44,10 @@ async fn proxy_handler(AxumState(state): AxumState<ProxyState>, req: Request) ->
.map(|pq| pq.as_str())
.unwrap_or("/");

// Strip the /media/ prefix check — we only mount on /media/
let upstream_url = format!("{}{path_and_query}", state.base_url);
// Resolve relay URL dynamically so workspace switches take effect immediately.
let app_state = state.app_handle.state::<AppState>();
let base_url = relay::relay_api_base_url_with_override(&app_state);
let upstream_url = format!("{base_url}{path_and_query}");

let has_range = req.headers().contains_key("range");

Expand Down Expand Up @@ -111,10 +113,10 @@ async fn proxy_handler(AxumState(state): AxumState<ProxyState>, req: Request) ->
/// Spawn a localhost HTTP proxy that streams media via reqwest, avoiding the
/// Tauri protocol handler's requirement to buffer the entire response into
/// `Vec<u8>`. Returns the OS-assigned port.
pub async fn spawn_media_proxy(http_client: reqwest::Client, base_url: String) -> u16 {
pub async fn spawn_media_proxy(http_client: reqwest::Client, app_handle: tauri::AppHandle) -> u16 {
let proxy_state = ProxyState {
client: http_client,
base_url,
app_handle,
};

let app = Router::new()
Expand Down
Loading