Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
created new client for v2, restored v1 of qbt
- Loading branch information
1 parent
eeed867
commit c7b2e31
Showing
7 changed files
with
85 additions
and
65 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,59 +1,57 @@ | ||
RTA.clients.qBittorrentAdder = function(server, data, torrentname, label, dir) { | ||
|
||
var rootUrl = (server.hostsecure ? "https" : "http") + "://" + server.host + ":" + server.port; | ||
|
||
var loginXhr = new XMLHttpRequest(); | ||
loginXhr.open("POST", rootUrl + "/api/v2/auth/login", true); | ||
loginXhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=utf-8"); | ||
loginXhr.send("username=" + encodeURIComponent(server.login) + "&password=" + encodeURIComponent(server.password)); | ||
loginXhr.onreadystatechange = function() { | ||
if(loginXhr.readyState == 4 && loginXhr.status == 0) { | ||
RTA.displayResponse("Failure", "Could not contact server at: " + rootUrl, true); | ||
} | ||
else if(loginXhr.readyState == 4 && loginXhr.status == 200) { | ||
|
||
xhr = new XMLHttpRequest(); | ||
xhr.open("POST", "http" + (server.hostsecure ? "s" : "") + "://" + server.host + ":" + server.port + "/api/v2/torrents/add"); | ||
xhr.onreadystatechange = function(data) { | ||
if(xhr.readyState == 4 && xhr.status == 200) { | ||
RTA.displayResponse("Success", "Torrent added successfully."); | ||
} else if(xhr.readyState == 4 && xhr.status != 200) { | ||
RTA.displayResponse("Failure", "Server responded with an irregular HTTP error code:\n" + xhr.status + ": " + xhr.responseText, true); | ||
} | ||
}; | ||
|
||
var boundary = "AJAX-----------------------" + (new Date).getTime(); | ||
xhr.setRequestHeader("Content-Type", "multipart/form-data; boundary=" + boundary); | ||
var message = "--" + boundary + "\r\n"; | ||
|
||
if(data.substring(0,7) == "magnet:") { | ||
message += "Content-Disposition: form-data; name=\"urls\"\r\n\r\n"; | ||
message += data + "\r\n"; | ||
message += "--" + boundary + "\r\n"; | ||
} else { | ||
message += "Content-Disposition: form-data; name=\"fileselect[]\"; filename=\"" + ((torrentname.length && torrentname.length > 1) ? torrentname : (new Date).getTime()) + "\"\r\n"; | ||
message += "Content-Type: application/x-bittorrent\r\n\r\n"; | ||
message += data + "\r\n"; | ||
message += "--" + boundary + "\r\n"; | ||
} | ||
|
||
if(dir) { | ||
message += "Content-Disposition: form-data; name=\"savepath\"\r\n\r\n" | ||
message += dir + "\r\n"; | ||
message += "--" + boundary + "\r\n"; | ||
} | ||
|
||
if(label) { | ||
message += "Content-Disposition: form-data; name=\"category\"\r\n\r\n" | ||
message += label + "\r\n"; | ||
message += "--" + boundary + "--\r\n"; | ||
} | ||
|
||
xhr.sendAsBinary(message); | ||
} | ||
else if(loginXhr.readyState == 4 && loginXhr.status != 200) | ||
{ | ||
RTA.displayResponse("Failure", "Unable to Authenticate with Server. HTTP error code:\n" + xhr.status + ": " + xhr.responseText, true); | ||
} | ||
}; | ||
} | ||
RTA.clients.qBittorrentAdder = function(server, data, torrentname, label, dir) { | ||
var target; | ||
if(data.substring(0,7) == "magnet:") | ||
target = "download"; | ||
else | ||
target = "upload"; | ||
|
||
|
||
var rootUrl = (server.hostsecure ? "https" : "http") + "://" + server.host + ":" + server.port; | ||
|
||
var loginXhr = new XMLHttpRequest(); | ||
loginXhr.open("POST", rootUrl + "/login", true); | ||
loginXhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=utf-8"); | ||
loginXhr.send("username=" + encodeURIComponent(server.login) + "&password=" + encodeURIComponent(server.password)); | ||
loginXhr.onreadystatechange = function() { | ||
if(loginXhr.readyState == 4) { | ||
xhr = new XMLHttpRequest(); | ||
xhr.open("POST", "http" + (server.hostsecure ? "s" : "") + "://" + server.host + ":" + server.port + "/command/" + target, true, server.login, server.password); | ||
xhr.onreadystatechange = function(data) { | ||
if(xhr.readyState == 4 && xhr.status == 200) { | ||
RTA.displayResponse("Success", "Torrent added successfully."); | ||
} else if(xhr.readyState == 4 && xhr.status != 200) { | ||
RTA.displayResponse("Failure", "Server responded with an irregular HTTP error code:\n" + xhr.status + ": " + xhr.responseText, true); | ||
} | ||
}; | ||
|
||
var boundary = "AJAX-----------------------" + (new Date).getTime(); | ||
xhr.setRequestHeader("Content-Type", "multipart/form-data; boundary=" + boundary); | ||
var message = "--" + boundary + "\r\n"; | ||
|
||
if(data.substring(0,7) == "magnet:") { | ||
message += "Content-Disposition: form-data; name=\"urls\"\r\n\r\n"; | ||
message += data + "\r\n"; | ||
message += "--" + boundary + "\r\n"; | ||
} else { | ||
message += "Content-Disposition: form-data; name=\"fileselect[]\"; filename=\"" + ((torrentname.length && torrentname.length > 1) ? torrentname : (new Date).getTime()) + "\"\r\n"; | ||
message += "Content-Type: application/x-bittorrent\r\n\r\n"; | ||
message += data + "\r\n"; | ||
message += "--" + boundary + "\r\n"; | ||
} | ||
|
||
if(dir) { | ||
message += "Content-Disposition: form-data; name=\"savepath\"\r\n\r\n" | ||
message += dir + "\r\n"; | ||
message += "--" + boundary + "\r\n"; | ||
} | ||
|
||
if(label) { | ||
message += "Content-Disposition: form-data; name=\"category\"\r\n\r\n" | ||
message += label + "\r\n"; | ||
message += "--" + boundary + "--\r\n"; | ||
} | ||
|
||
xhr.sendAsBinary(message); | ||
} | ||
}; | ||
} |