From 70ccb8f4fd178881ffd68a4a0358fafd0abaa696 Mon Sep 17 00:00:00 2001 From: MasterDraco Date: Fri, 7 Mar 2025 09:19:27 +0000 Subject: [PATCH] Fix Transmission connection testing and API compatibility MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Updated TransmissionClient to use correct method names from transmission-promise - Changed sessionGet to session() and sessionSet to sessionUpdate() - Added robust error handling in connection test - Improved logging for connection debugging - Fixed error handling in TransmissionClient constructor 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude --- modules/transmission-client.js | 23 +++++++++---- server.js | 62 +++++++++++++++++++++++++--------- 2 files changed, 63 insertions(+), 22 deletions(-) diff --git a/modules/transmission-client.js b/modules/transmission-client.js index 20986c8..0edff70 100644 --- a/modules/transmission-client.js +++ b/modules/transmission-client.js @@ -28,8 +28,14 @@ class TransmissionClient { this.dirMappings = config.remoteConfig.directoryMapping; } - // Initialize the connection - this.initializeConnection(); + // Initialize the connection - but don't throw if it fails initially + // This allows the object to be created even if the connection fails + try { + this.initializeConnection(); + } catch (error) { + console.error("Failed to initialize Transmission connection:", error.message); + // Don't throw - allow methods to handle connection retry logic + } } /** @@ -64,13 +70,17 @@ class TransmissionClient { */ async getStatus() { try { + // Use the session-stats method for basic connectivity check const sessionInfo = await this.client.sessionStats(); - const version = await this.client.sessionGet(); + + // Use the session-get method to get version info + // Note: In transmission-promise, this is 'session' not 'sessionGet' + const session = await this.client.session(); return { connected: true, - version: version.version, - rpcVersion: version['rpc-version'], + version: session.version || "Unknown", + rpcVersion: session['rpc-version'] || "Unknown", downloadSpeed: sessionInfo.downloadSpeed, uploadSpeed: sessionInfo.uploadSpeed, torrentCount: sessionInfo.torrentCount, @@ -446,7 +456,8 @@ class TransmissionClient { */ async setSessionParams(params) { try { - await this.client.sessionSet(params); + // In transmission-promise, the method is sessionUpdate not sessionSet + await this.client.sessionUpdate(params); return { success: true, message: 'Session parameters updated successfully' diff --git a/server.js b/server.js index f2bf902..a4ed422 100644 --- a/server.js +++ b/server.js @@ -885,7 +885,15 @@ app.post('/api/transmission/remove', authenticateJWT, async (req, res) => { app.post('/api/transmission/test', authenticateJWT, async (req, res) => { try { - const { host, port, username, password } = req.body; + const { host, port, username, password, path: rpcPath } = req.body; + + // Debug info + console.log('Testing Transmission connection with params:', { + host: host || 'from config', + port: port || 'from config', + username: username ? 'provided' : 'from config', + path: rpcPath || 'from config', + }); // Create a temporary client for testing const testConfig = { @@ -894,26 +902,48 @@ app.post('/api/transmission/test', authenticateJWT, async (req, res) => { port: port || config.transmissionConfig.port, username: username || config.transmissionConfig.username, password: password || config.transmissionConfig.password, - path: config.transmissionConfig.path + path: rpcPath || config.transmissionConfig.path + }, + // Also include remoteConfig to ensure proper remote handling + remoteConfig: { + // If host is provided and different from localhost, set isRemote to true + isRemote: host && host !== 'localhost' ? true : config.remoteConfig?.isRemote || false, + directoryMapping: config.remoteConfig?.directoryMapping || {} } }; - const testClient = new TransmissionClient(testConfig); - const status = await testClient.getStatus(); + // Log the actual test config (without password) + console.log('Test configuration:', { + host: testConfig.transmissionConfig.host, + port: testConfig.transmissionConfig.port, + path: testConfig.transmissionConfig.path, + isRemote: testConfig.remoteConfig.isRemote + }); - if (status.connected) { - res.json({ - success: true, - message: 'Successfully connected to Transmission server', - data: { - version: status.version, - rpcVersion: status.rpcVersion - } - }); - } else { - res.status(400).json({ + try { + const testClient = new TransmissionClient(testConfig); + const status = await testClient.getStatus(); + + if (status.connected) { + res.json({ + success: true, + message: 'Successfully connected to Transmission server', + data: { + version: status.version, + rpcVersion: status.rpcVersion + } + }); + } else { + res.status(400).json({ + success: false, + message: `Failed to connect: ${status.error}` + }); + } + } catch (error) { + console.error('Error testing Transmission connection:', error); + res.status(500).json({ success: false, - message: `Failed to connect: ${status.error}` + message: `Error testing connection: ${error.message}` }); } } catch (error) {