From 114a8873279aa1103173525d98349fb609fb2dd9 Mon Sep 17 00:00:00 2001 From: Eric Kok Date: Wed, 3 Jun 2020 09:16:02 +0200 Subject: [PATCH] Fixes #534 qBittorrent auth errors by eagerly logging in, assuming qBit is up-to-date --- .../daemon/Qbittorrent/QbittorrentAdapter.java | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/app/src/main/java/org/transdroid/daemon/Qbittorrent/QbittorrentAdapter.java b/app/src/main/java/org/transdroid/daemon/Qbittorrent/QbittorrentAdapter.java index 57fdc592..50440db8 100644 --- a/app/src/main/java/org/transdroid/daemon/Qbittorrent/QbittorrentAdapter.java +++ b/app/src/main/java/org/transdroid/daemon/Qbittorrent/QbittorrentAdapter.java @@ -161,12 +161,6 @@ public class QbittorrentAdapter implements IDaemonAdapter { } private synchronized void ensureAuthenticated(Log log) throws DaemonException { - // API changed in 3.2.0, login is now handled by its own request, which provides you a cookie. - // If we don't have that cookie, let's try and get it. - if (version != -1 && version < 30200) { - return; - } - // Have we already authenticated? Check if we have the cookie that we need if (isAuthenticated()) { return; @@ -174,12 +168,13 @@ public class QbittorrentAdapter implements IDaemonAdapter { final BasicNameValuePair usernameParam = new BasicNameValuePair("username", settings.getUsername()); final BasicNameValuePair passwordParam = new BasicNameValuePair("password", settings.getPassword()); - if (version == -1 || version >= 40100) { - try { - makeRequest(log, "/api/v2/auth/login", usernameParam, passwordParam); - } catch (DaemonException ignored) { - } + + // Try qBittorrent 4.1 API v2 first + try { + makeRequest(log, "/api/v2/auth/login", usernameParam, passwordParam); + } catch (DaemonException ignored) { } + // If still not authenticated, try the qBittorrent 3.2 API v1 endpoint if (!isAuthenticated()) { try { makeRequest(log, "/login", usernameParam, passwordParam);