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;
|
this.dirMappings = config.remoteConfig.directoryMapping;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Initialize the connection
|
// Initialize the connection - but don't throw if it fails initially
|
||||||
this.initializeConnection();
|
// 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() {
|
async getStatus() {
|
||||||
try {
|
try {
|
||||||
|
// Use the session-stats method for basic connectivity check
|
||||||
const sessionInfo = await this.client.sessionStats();
|
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 {
|
return {
|
||||||
connected: true,
|
connected: true,
|
||||||
version: version.version,
|
version: session.version || "Unknown",
|
||||||
rpcVersion: version['rpc-version'],
|
rpcVersion: session['rpc-version'] || "Unknown",
|
||||||
downloadSpeed: sessionInfo.downloadSpeed,
|
downloadSpeed: sessionInfo.downloadSpeed,
|
||||||
uploadSpeed: sessionInfo.uploadSpeed,
|
uploadSpeed: sessionInfo.uploadSpeed,
|
||||||
torrentCount: sessionInfo.torrentCount,
|
torrentCount: sessionInfo.torrentCount,
|
||||||
@ -446,7 +456,8 @@ class TransmissionClient {
|
|||||||
*/
|
*/
|
||||||
async setSessionParams(params) {
|
async setSessionParams(params) {
|
||||||
try {
|
try {
|
||||||
await this.client.sessionSet(params);
|
// In transmission-promise, the method is sessionUpdate not sessionSet
|
||||||
|
await this.client.sessionUpdate(params);
|
||||||
return {
|
return {
|
||||||
success: true,
|
success: true,
|
||||||
message: 'Session parameters updated successfully'
|
message: 'Session parameters updated successfully'
|
||||||
|
62
server.js
62
server.js
@ -885,7 +885,15 @@ app.post('/api/transmission/remove', authenticateJWT, async (req, res) => {
|
|||||||
|
|
||||||
app.post('/api/transmission/test', authenticateJWT, async (req, res) => {
|
app.post('/api/transmission/test', authenticateJWT, async (req, res) => {
|
||||||
try {
|
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
|
// Create a temporary client for testing
|
||||||
const testConfig = {
|
const testConfig = {
|
||||||
@ -894,26 +902,48 @@ app.post('/api/transmission/test', authenticateJWT, async (req, res) => {
|
|||||||
port: port || config.transmissionConfig.port,
|
port: port || config.transmissionConfig.port,
|
||||||
username: username || config.transmissionConfig.username,
|
username: username || config.transmissionConfig.username,
|
||||||
password: password || config.transmissionConfig.password,
|
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);
|
// Log the actual test config (without password)
|
||||||
const status = await testClient.getStatus();
|
console.log('Test configuration:', {
|
||||||
|
host: testConfig.transmissionConfig.host,
|
||||||
|
port: testConfig.transmissionConfig.port,
|
||||||
|
path: testConfig.transmissionConfig.path,
|
||||||
|
isRemote: testConfig.remoteConfig.isRemote
|
||||||
|
});
|
||||||
|
|
||||||
if (status.connected) {
|
try {
|
||||||
res.json({
|
const testClient = new TransmissionClient(testConfig);
|
||||||
success: true,
|
const status = await testClient.getStatus();
|
||||||
message: 'Successfully connected to Transmission server',
|
|
||||||
data: {
|
if (status.connected) {
|
||||||
version: status.version,
|
res.json({
|
||||||
rpcVersion: status.rpcVersion
|
success: true,
|
||||||
}
|
message: 'Successfully connected to Transmission server',
|
||||||
});
|
data: {
|
||||||
} else {
|
version: status.version,
|
||||||
res.status(400).json({
|
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,
|
success: false,
|
||||||
message: `Failed to connect: ${status.error}`
|
message: `Error testing connection: ${error.message}`
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user