Skip to content

Commit

Permalink
fix(deluge/webui_unconnected): checks for webui being connected to da…
Browse files Browse the repository at this point in the history
…emon (cross-seed#552)

this addresses when the web_ui is not connected to a daemon.

it will get the available daemons and connect to it

the current implementation, if not connected, will return errors or
empty json results.
  • Loading branch information
zakkarry authored Nov 18, 2023
1 parent eb201b7 commit 026dfe3
Showing 1 changed file with 22 additions and 2 deletions.
24 changes: 22 additions & 2 deletions src/clients/Deluge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,32 @@ export default class Deluge implements TorrentClient {
"You need to define a password in the delugeRpcUrl. (e.g. http://:<PASSWORD>@localhost:8112)"
);
}
const response = await this.call("auth.login", [password], 0);
if (!response.result) {
const authResponse = await this.call("auth.login", [password], 0);
if (!authResponse.result) {
throw new CrossSeedError(
`Reached Deluge, but failed to authenticate: ${href}`
);
}
const connectedResponse = await this.call("web.connected", [], 0);

if (!connectedResponse.result) {
logger.warn(
"Deluge WebUI disconnected from daemon...attempting to reconnect."
);
const webuiHostList = await this.call("web.get_hosts", [], 0);
const connectResponse = await this.call(
"web.connect",
[webuiHostList.result[0][0]],
0
);
if (connectResponse) {
logger.info("Deluge WebUI connected to the daemon.");
} else {
throw new CrossSeedError(
"Unable to connect WebUI to Deluge daemon. Connect to the WebUI to resolve this."
);
}
}
}

/**
Expand Down

0 comments on commit 026dfe3

Please sign in to comment.