Fix a bittorrent bug
This commit is contained in:
@@ -53,8 +53,8 @@
|
||||
"persistent": true,
|
||||
"scripts": [
|
||||
"config.js",
|
||||
"torrent/background.js",
|
||||
"torrent/common.js",
|
||||
"torrent/background.js",
|
||||
"i2pcontrol/i2pcontrol.js",
|
||||
"host.js",
|
||||
"privacy.js",
|
||||
|
@@ -1,5 +1,45 @@
|
||||
"use strict";
|
||||
|
||||
var TrpcCall = async function(meth, args) {
|
||||
const server = await browser.storage.local.get(null);
|
||||
const myHeaders = {
|
||||
"Content-Type": "application/json",
|
||||
"x-transmission-session-id": server.session
|
||||
};
|
||||
console.log("(torrent) session", server.session);
|
||||
if (server.username !== "" || server.btrpcpass !== "") {
|
||||
myHeaders["Authorization"] =
|
||||
"Basic " + btoa((server.username || "") + ":" + (server.btrpcpass || ""));
|
||||
}
|
||||
console.log("(torrent) rpcurl", server.base_url + "rpc");
|
||||
return fetch(server.base_url + "rpc", {
|
||||
method: "POST",
|
||||
headers: myHeaders,
|
||||
body: JSON.stringify({ method: meth, arguments: args }),
|
||||
credentials: "include" // allows HTTPS client certs!
|
||||
});
|
||||
|
||||
/*.then(function(response) {
|
||||
console.log("(torrent) responses", response);
|
||||
const session = response.headers.get("x-transmission-session-id");
|
||||
if (session) {
|
||||
browser.storage.local.get({}).then(function(storage) {
|
||||
storage.session = session;
|
||||
browser.storage.local.set(storage);
|
||||
});
|
||||
}
|
||||
if (response.status === 409) {
|
||||
return TrpcCall(meth, args);
|
||||
}
|
||||
if (response.status >= 200 && response.status < 300) {
|
||||
return response;
|
||||
}
|
||||
const error = new Error(response.statusText);
|
||||
error.response = response;
|
||||
throw error;
|
||||
});*/
|
||||
};
|
||||
|
||||
const torrentsPane = document.getElementById("torrents-pane");
|
||||
const configPane = document.getElementById("config-pane");
|
||||
|
||||
@@ -64,18 +104,22 @@ torrentsSearch.addEventListener("change", searchTorrents);
|
||||
torrentsSearch.addEventListener("keyup", searchTorrents);
|
||||
|
||||
function refreshTorrents(server) {
|
||||
return rpcCall("torrent-get", getArgs).then(function(response) {
|
||||
console.log("(torrent) refreshing", response);
|
||||
let newTorrents = response.arguments.torrents;
|
||||
newTorrents.sort((x, y) => y.queuePosition - x.queuePosition);
|
||||
cachedTorrents = newTorrents;
|
||||
torrentsSearch.hidden = newTorrents.length <= 8;
|
||||
if (torrentsSearch.hidden) {
|
||||
torrentsSearch.value = "";
|
||||
renderTorrents(newTorrents);
|
||||
} else {
|
||||
searchTorrents();
|
||||
}
|
||||
console.log("(torrent) initiating", server);
|
||||
return TrpcCall("torrent-get", getArgs).then(function(response) {
|
||||
let sponse = response.json();
|
||||
sponse.then(function(response) {
|
||||
console.log("(torrent) refreshing", response);
|
||||
let newTorrents = response.arguments.torrents;
|
||||
newTorrents.sort((x, y) => y.queuePosition - x.queuePosition);
|
||||
cachedTorrents = newTorrents;
|
||||
torrentsSearch.hidden = newTorrents.length <= 8;
|
||||
if (torrentsSearch.hidden) {
|
||||
torrentsSearch.value = "";
|
||||
renderTorrents(newTorrents);
|
||||
} else {
|
||||
searchTorrents();
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
@@ -92,6 +136,7 @@ function showTorrents(server) {
|
||||
for (const opener of document.querySelectorAll(".webui-opener")) {
|
||||
opener.href = server.base_url + "web/";
|
||||
}
|
||||
console.log("(torrent) showing torrents");
|
||||
refreshTorrents(server).catch(_ => refreshTorrentsLogErr(server));
|
||||
setInterval(() => refreshTorrentsLogErr(server), 2000);
|
||||
}
|
||||
|
@@ -165,7 +165,7 @@
|
||||
<script src="i2pcontrol/i2pcontrol.js"></script>
|
||||
<script src="info.js"></script>
|
||||
<script crossorigin="anonymous" src="content.js"></script>
|
||||
<script src="torrent/common.js"></script>
|
||||
<script src="torrent/popup.js"></script>
|
||||
<script src="torrent/popup.js"></script>
|
||||
<script src="torrent/common.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
|
Reference in New Issue
Block a user