Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/src/main/java/org/transdroid/daemon/Daemon.java
Original file line number Diff line number Diff line change
Expand Up @@ -420,7 +420,7 @@ public static boolean supportsFirstLastPiece(Daemon type) {
}

public static boolean supportsExtraPassword(Daemon type) {
return type == Deluge || type == Aria2;
return type == Deluge || type == Aria2 || type == qBittorrent;
}

public static boolean supportsRemoteRssManagement(Daemon type) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,10 @@ private int parseVersionNumber(String versionText) {
}

private synchronized void ensureAuthenticated(Log log) throws DaemonException {
if (hasApiKey()) {
return;
}

// Have we already authenticated? Check if we have the cookie that we need
if (isAuthenticated()) {
return;
Expand Down Expand Up @@ -218,6 +222,19 @@ private boolean isSessionCookie(Cookie cookie) {
return name.equals("SID") || name.startsWith("QBT_SID_");
}

private boolean hasApiKey() {
return getApiKey() != null;
}

private String getApiKey() {
String apiKey = settings.getExtraPassword();
if (apiKey == null) {
return null;
}
apiKey = apiKey.trim();
return apiKey.length() == 0 ? null : apiKey;
}

@Override
public DaemonTaskResult executeTask(Log log, DaemonTask task) {

Expand Down Expand Up @@ -595,12 +612,18 @@ private String makeUploadRequest(String path, String file, Log log) throws Daemo
private String makeWebRequest(HttpPost httppost, Log log) throws DaemonException {

try {
String apiKey = getApiKey();
if (apiKey != null) {
httppost.setHeader("Authorization", "Bearer " + apiKey);
}

// Execute
HttpResponse response = httpclient.execute(httppost);

// Throw exception on 403
if (response.getStatusLine().getStatusCode() == 403) {
throw new DaemonException(ExceptionType.AuthenticationFailure, "Response code 403");
// Throw exception on authentication failure
int statusCode = response.getStatusLine().getStatusCode();
if (statusCode == 401 || statusCode == 403) {
throw new DaemonException(ExceptionType.AuthenticationFailure, "Response code " + statusCode);
}

HttpEntity entity = response.getEntity();
Expand Down