From d54d08487f58e9337764352d5503cb0bf0050b0d Mon Sep 17 00:00:00 2001 From: wipedlifepotato <60944239+wipedlifepotato@users.noreply.github.com> Date: Sun, 30 Aug 2026 12:10:07 +0300 Subject: [PATCH] start all stop all --- contrib/webconsole/torrent-rpc.js | 181 +++++++++++-------------- contrib/webconsole/torrent_client.html | 52 +++++-- 2 files changed, 118 insertions(+), 115 deletions(-) diff --git a/contrib/webconsole/torrent-rpc.js b/contrib/webconsole/torrent-rpc.js index 5023b835..bfc3f1bc 100644 --- a/contrib/webconsole/torrent-rpc.js +++ b/contrib/webconsole/torrent-rpc.js @@ -1,117 +1,92 @@ class TorrentClient { - constructor(host = "127.0.0.1", port = 9191, path = "mytorrents") { - this.host = host; - this.port = port; - this.path = path; - } - - setConnection(host, port, path) { - this.host = host; - this.port = port; - this.path = path; - } - - getEndpoint() { - return `http://${this.host}:${this.port}${this.path}`; - } - - getStatusString(status) { - switch (status) { - case 4: - return "DOWNLOADING"; - case 6: - return "SEEDING"; - case 0: - return "STOPPED"; - case 2: - return "CHECKING"; - default: - return "QUEUED"; + constructor(host = '127.0.0.1', port = 9191, path = 'mytorrents') { + this.host = host; + this.port = port; + this.path = path; } - } - formatBytes(bytesPerSec) { - if (!bytesPerSec) return "0 B/s"; - if (bytesPerSec > 1024 * 1024) { - return (bytesPerSec / (1024 * 1024)).toFixed(2) + " MB/s"; + setConnection(host, port, path) { + this.host = host; + this.port = port; + this.path = path; } - return (bytesPerSec / 1024).toFixed(2) + " KB/s"; - } - async addTorrent(b64metainfo) { - const res = await fetch(this.getEndpoint(), { - method: "POST", - body: JSON.stringify({ - method: "torrent-add", - arguments: { metainfo: b64metainfo }, - }), - headers: { "Content-Type": "application/json" }, - }); - return res.json(); - } + getEndpoint() { + return `http://${this.host}:${this.port}${this.path}`; + } - async removeTorrent(id) { - const res = await fetch(this.getEndpoint(), { - method: "POST", - body: JSON.stringify({ - method: "torrent-remove", - arguments: { ids: [id], "delete-local-data": true }, - }), - headers: { "Content-Type": "application/json" }, - }); - return res.json(); - } + getStatusString(status) { + switch (status) { + case 4: return 'DOWNLOADING'; + case 6: return 'SEEDING'; + case 0: return 'STOPPED'; + case 2: return 'CHECKING'; + default: return 'QUEUED'; + } + } - async getTorrents() { - const res = await fetch(this.getEndpoint(), { - method: "POST", - body: JSON.stringify({ - method: "torrent-get", - arguments: { - fields: [ - "id", - "name", - "status", - "rateDownload", - "rateUpload", - "totalSize", - "percentDone", - "files", - "peers", - "trackers", - "trackerStats", - ], - }, - }), - headers: { "Content-Type": "application/json" }, - }); - return res.json(); - } - async stopTorrent(ids = []) { - const res = await fetch(this.getEndpoint(), { - method: "POST", - body: JSON.stringify({ - method: "torrent-stop", - arguments: ids.length ? { ids } : {}, - tag: 666, - }), - headers: { "Content-Type": "application/json" }, - }); - return res.json(); - } + formatBytes(bytesPerSec) { + if (!bytesPerSec) return '0 B/s'; + if (bytesPerSec > 1024 * 1024) { + return (bytesPerSec / (1024 * 1024)).toFixed(2) + ' MB/s'; + } + return (bytesPerSec / 1024).toFixed(2) + ' KB/s'; + } - async startTorrent(ids = []) { + async addTorrent(b64metainfo) { + const res = await fetch(this.getEndpoint(), { + method: "POST", + body: JSON.stringify({ 'method': 'torrent-add', 'arguments': { 'metainfo': b64metainfo } }), + headers: { 'Content-Type': 'application/json' } + }); + return res.json(); + } + + async removeTorrent(id) { + const res = await fetch(this.getEndpoint(), { + method: "POST", + body: JSON.stringify({ 'method': 'torrent-remove', 'arguments': { 'ids': [id], 'delete-local-data': true } }), + headers: { 'Content-Type': 'application/json' } + }); + return res.json(); + } + + async getTorrents() { + const res = await fetch(this.getEndpoint(), { + method: "POST", + body: JSON.stringify({ + 'method': 'torrent-get', + 'arguments': { "fields": ["id", "name", "status", "rateDownload", "rateUpload", "totalSize", "percentDone", "files", "peers", "trackers", "trackerStats"] } + }), + headers: { 'Content-Type': 'application/json' } + }); + return res.json(); + } + async stopTorrent(ids = []) { const res = await fetch(this.getEndpoint(), { - method: "POST", - body: JSON.stringify({ - method: "torrent-start", - arguments: ids.length ? { ids } : {}, - tag: 666, - }), - headers: { "Content-Type": "application/json" }, + method: "POST", + body: JSON.stringify({ + 'method': 'torrent-stop', + 'arguments': ids.length ? { ids } : {}, + 'tag': 666 + }), + headers: { 'Content-Type': 'application/json' } }); return res.json(); - } +} + +async startTorrent(ids = []) { + const res = await fetch(this.getEndpoint(), { + method: "POST", + body: JSON.stringify({ + 'method': 'torrent-start', + 'arguments': ids.length ? { ids } : {}, + 'tag': 666 + }), + headers: { 'Content-Type': 'application/json' } + }); + return res.json(); +} } //window.tjs = new TorrentClient(); diff --git a/contrib/webconsole/torrent_client.html b/contrib/webconsole/torrent_client.html index 974909ca..e6d4190f 100644 --- a/contrib/webconsole/torrent_client.html +++ b/contrib/webconsole/torrent_client.html @@ -6,8 +6,12 @@ - - + +