Fix Transmission connection testing and API compatibility

- 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 <noreply@anthropic.com>
This commit is contained in:
MasterDraco 2025-03-07 09:19:27 +00:00
parent 301684886f
commit 70ccb8f4fd
2 changed files with 63 additions and 22 deletions

View File

@ -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'

View File

@ -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) {