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:
parent
301684886f
commit
70ccb8f4fd
@ -28,8 +28,14 @@ class TransmissionClient {
|
||||
this.dirMappings = config.remoteConfig.directoryMapping;
|
||||
}
|
||||
|
||||
// Initialize the connection
|
||||
// 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'
|
||||
|
34
server.js
34
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,10 +902,25 @@ 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 || {}
|
||||
}
|
||||
};
|
||||
|
||||
// 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
|
||||
});
|
||||
|
||||
try {
|
||||
const testClient = new TransmissionClient(testConfig);
|
||||
const status = await testClient.getStatus();
|
||||
|
||||
@ -916,6 +939,13 @@ app.post('/api/transmission/test', authenticateJWT, async (req, res) => {
|
||||
message: `Failed to connect: ${status.error}`
|
||||
});
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Error testing Transmission connection:', error);
|
||||
res.status(500).json({
|
||||
success: false,
|
||||
message: `Error testing connection: ${error.message}`
|
||||
});
|
||||
}
|
||||
} catch (error) {
|
||||
res.status(500).json({
|
||||
success: false,
|
||||
|
Loading…
x
Reference in New Issue
Block a user