Skip to content

Commit

Permalink
added support for jesec fork of flood #300
Browse files Browse the repository at this point in the history
  • Loading branch information
bogenpirat committed Dec 12, 2020
1 parent 25a613e commit f44da0d
Show file tree
Hide file tree
Showing 5 changed files with 95 additions and 0 deletions.
1 change: 1 addition & 0 deletions manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
"webuiapis/nodejsrtorrentWebUI.js",
"webuiapis/SynologyWebUI.js",
"webuiapis/floodWebUI.js",
"webuiapis/flood-jesecWebUI.js",
"webuiapis/tTorrentWebUI.js",
"webuiapis/rtorrentXmlRpc.js"
]
Expand Down
15 changes: 15 additions & 0 deletions miscapis/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ RTA.clients.config.getConfig = function(client, name) {
"Deluge WebUI" : RTA.clients.config.deluge,
"Hadouken WebUI" : RTA.clients.config.hadouken,
"flood WebUI" : RTA.clients.config.flood,
"flood-jesec WebUI" : RTA.clients.config.floodJesec,
"QNAP DownloadStation" : RTA.clients.config.qnap,
"qBittorrent WebUI" : RTA.clients.config.qbittorrent,
"qBittorrent v4.1+ WebUI" : RTA.clients.config.qbittorrentv2,
Expand Down Expand Up @@ -209,6 +210,20 @@ RTA.clients.config.flood = multiline(function(){/*
</tbody>
*/});

RTA.clients.config.floodJesec = multiline(function(){/*
<tbody name="floodJesecspecifics" class="specifics">
<tr>
<td><span class="title">Directory</span><br />(optional)</td>
<td><input type="text" name="floodjesecdirectory" /><br />
<span class="tip">Default directory to store added torrents in. This should be an absolute path. It should be inside your default directory for torrents.</span></td>
</tr>
<tr>
<td><span class="title">Add torrents paused?</span></td>
<td><input type="checkbox" name="floodjesecaddpaused" /></td>
</tr>
</tbody>
*/});

RTA.clients.config.qnap = multiline(function(){/*
<tbody name="qnapspecifics" class="specifics">
<tr>
Expand Down
13 changes: 13 additions & 0 deletions miscapis/functions.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ RTA.dispatchTorrent = function(server, data, name, label, dir) {
RTA.clients.synologyAdder(server, data, name); break;
case "flood WebUI":
RTA.clients.floodAdder(server, data, name); break;
case "flood-jesec WebUI":
RTA.clients.floodJesecAdder(server, data, name); break;
case "QNAP DownloadStation":
RTA.clients.qnapDownloadStationAdder(server, data, name); break;
case "tTorrent WebUI":
Expand Down Expand Up @@ -253,3 +255,14 @@ RTA.convertToBlob = function(data, myType="text/plain") {

return dataBlob;
};


RTA.blobToBase64 = function(blob) {
const reader = new FileReader();
reader.readAsDataURL(blob);
return new Promise(resolve => {
reader.onloadend = () => {
resolve(reader.result);
};
});
};
1 change: 1 addition & 0 deletions options.html
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ <h1><img src="icons/BitTorrent48.png" alt="BitTorrent!" /> Remote Torrent Adder
<option>NodeJS-rTorrent WebUI</option>
<option>Synology WebUI</option>
<option>flood WebUI</option>
<option>flood-jesec WebUI</option>
<option>QNAP DownloadStation</option>
<option>tTorrent WebUI</option>
<option>rTorrent XML-RPC</option>
Expand Down
65 changes: 65 additions & 0 deletions webuiapis/flood-jesecWebUI.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
RTA.clients.floodJesecAdder = function(server, torrentdata) {
var dir = server.floodjesecdirectory;
var paused = server.floodjesecaddpaused;

var apiUrl = (server.hostsecure ? "https://" : "http://") + server.host + ":" + server.port;

fetch(apiUrl + "/api/auth/authenticate", {
method: 'POST',
headers: {
"Content-Type": "application/json; charset=UTF-8"
},
body: JSON.stringify({"username": server.login, "password": server.password})
})
.then(RTA.handleFetchError)
.then(response => response.json())
.then(async function(json) {
if(!json.success) {
RTA.displayResponse("Failure", "Login to " + server.name + "'s WebUI failed.", true);
} else {
var fetchOpts = {
method: 'POST',
headers : { "Content-Type": "application/json; charset=UTF-8" }
};
if(torrentdata.substring(0,7) == "magnet:") {
apiUrl += "/api/torrents/add-urls";
fetchOpts.body = JSON.stringify({ "urls": [ torrentdata ], "start": !paused, "destination": (!!dir ? dir : undefined), "isBasePath": false, "isCompleted": false });
} else {
const dataBlob = RTA.convertToBlob(torrentdata, "application/x-bittorrent");

apiUrl += "/api/torrents/add-files";

let b64file = await RTA.blobToBase64(dataBlob);
b64file = b64file.substr(b64file.lastIndexOf(',') + 1);

fetchOpts.body = JSON.stringify({
tags: [],
"start": !paused,
"destination": (!!dir ? dir : undefined),
"isBasePath": false,
"isCompleted": false,
"files": [
b64file
]
});
}

fetch(apiUrl, fetchOpts)
.then(RTA.handleFetchError)
.then(response => {
if(response.status == 200) {
RTA.displayResponse("Success", "Torrent added successfully.");
} else {
RTA.displayResponse("Failure", "Torrent not added successfully:\n" + text);
}
})
.catch(error => {
RTA.displayResponse("Failure", "Could not contact " + server.name + "\nError: " + error.message, true);
});
}
})
.catch(error => {
RTA.displayResponse("Failure", "Could not contact " + server.name + "\nError: " + error.message, true);
});

};

0 comments on commit f44da0d

Please sign in to comment.