From 68fb183c20c17aa44ba055cc7b2b39a8ffdb8650 Mon Sep 17 00:00:00 2001 From: Igor Kulman Date: Sun, 21 Sep 2025 22:23:46 +0200 Subject: [PATCH] Use service mixin fetch method with custom session handling for Transmission RPC --- src/components/services/Transmission.vue | 43 ++++++++++++------------ 1 file changed, 22 insertions(+), 21 deletions(-) diff --git a/src/components/services/Transmission.vue b/src/components/services/Transmission.vue index 25058f7..390057f 100644 --- a/src/components/services/Transmission.vue +++ b/src/components/services/Transmission.vue @@ -111,30 +111,31 @@ export default { } try { - const response = await fetch( - this.endpoint + "/transmission/rpc", - options, - ); + return await this.fetch("transmission/rpc", options); + } catch (error) { + // Handle Transmission's 409 session requirement + if (error.message.includes("409")) { + // Make a direct request to get session ID + let url = this.endpoint; + if (url && !url.endsWith("/")) { + url += "/"; + } + url += "transmission/rpc"; - // Handle session ID requirement - if (response.status === 409) { - this.sessionId = response.headers.get("X-Transmission-Session-Id"); - if (this.sessionId) { - options.headers["X-Transmission-Session-Id"] = this.sessionId; - const retryResponse = await fetch( - this.endpoint + "/transmission/rpc", - options, - ); - return await retryResponse.json(); + const sessionResponse = await fetch(url, { + method: "POST", + headers: { "Content-Type": "application/json" }, + body: JSON.stringify({ method: "session-get" }), + }); + + if (sessionResponse.status === 409) { + this.sessionId = sessionResponse.headers.get("X-Transmission-Session-Id"); + if (this.sessionId) { + options.headers["X-Transmission-Session-Id"] = this.sessionId; + return await this.fetch("transmission/rpc", options); + } } } - - if (!response.ok) { - throw new Error(`HTTP error! status: ${response.status}`); - } - - return await response.json(); - } catch (error) { console.error("Transmission RPC error:", error); throw error; }