Fix Transmission remote connection issues

- Prevent remote host from defaulting to localhost
- Preserve remote connection settings during config updates
- Handle empty values correctly to avoid overriding good config

🤖 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:16:28 +00:00
parent f28d49284e
commit 301684886f
2 changed files with 44 additions and 5 deletions

View File

@ -39,8 +39,11 @@ class TransmissionClient {
const { host, port, username, password, path: rpcPath } = this.config.transmissionConfig; const { host, port, username, password, path: rpcPath } = this.config.transmissionConfig;
try { try {
// Only default to localhost if host is empty/null/undefined
const connectionHost = (host === undefined || host === null || host === '') ? 'localhost' : host;
this.client = new Transmission({ this.client = new Transmission({
host: host || 'localhost', host: connectionHost,
port: port || 9091, port: port || 9091,
username: username || '', username: username || '',
password: password || '', password: password || '',
@ -48,7 +51,7 @@ class TransmissionClient {
timeout: 30000 // 30 seconds timeout: 30000 // 30 seconds
}); });
console.log(`Initialized Transmission client connection to ${host}:${port}${rpcPath}`); console.log(`Initialized Transmission client connection to ${connectionHost}:${port}${rpcPath}`);
} catch (error) { } catch (error) {
console.error('Failed to initialize Transmission client:', error); console.error('Failed to initialize Transmission client:', error);
throw error; throw error;

View File

@ -468,9 +468,45 @@ app.post('/api/config', authenticateJWT, async (req, res) => {
// Merge the new config with the existing one // Merge the new config with the existing one
const newConfig = { ...config, ...req.body }; const newConfig = { ...config, ...req.body };
// Keep passwords if they're not provided // Preserve existing Transmission configuration values when not explicitly provided
if (newConfig.transmissionConfig && !newConfig.transmissionConfig.password && config.transmissionConfig) { if (newConfig.transmissionConfig && config.transmissionConfig) {
newConfig.transmissionConfig.password = config.transmissionConfig.password; // First create a copy of the existing configuration
const preservedTransConfig = { ...config.transmissionConfig };
// Only update values that are explicitly provided and not empty
if (!req.body.transmissionConfig?.host) {
newConfig.transmissionConfig.host = preservedTransConfig.host;
}
if (!req.body.transmissionConfig?.port) {
newConfig.transmissionConfig.port = preservedTransConfig.port;
}
if (!req.body.transmissionConfig?.path) {
newConfig.transmissionConfig.path = preservedTransConfig.path;
}
if (!req.body.transmissionConfig?.username) {
newConfig.transmissionConfig.username = preservedTransConfig.username;
}
// Always preserve password if not provided
if (!newConfig.transmissionConfig.password) {
newConfig.transmissionConfig.password = preservedTransConfig.password;
}
}
// Preserve remote configuration settings if not explicitly provided
if (newConfig.remoteConfig && config.remoteConfig) {
// Make sure isRemote setting is preserved if not explicitly set
if (req.body.remoteConfig?.isRemote === undefined) {
newConfig.remoteConfig.isRemote = config.remoteConfig.isRemote;
}
// Preserve directory mappings if not provided
if (!req.body.remoteConfig?.directoryMapping && config.remoteConfig.directoryMapping) {
newConfig.remoteConfig.directoryMapping = { ...config.remoteConfig.directoryMapping };
}
} }
// Keep user passwords // Keep user passwords