diff --git a/contrib/webconsole/torrent-rpc.js b/contrib/webconsole/torrent-rpc.js index bfc3f1bc..f596c5dc 100644 --- a/contrib/webconsole/torrent-rpc.js +++ b/contrib/webconsole/torrent-rpc.js @@ -33,6 +33,19 @@ class TorrentClient { return (bytesPerSec / 1024).toFixed(2) + ' KB/s'; } + async addTorrentByMagnet(magnet) + { + // TODO: check link + const magnetRegex = /^magnet:\?xt=urn:btih:[a-f0-9]{40}(&.+)?$/i; + if(!magnetRegex.test(magnet)) return false; + const res = await fetch(this.getEndpoint(), { + method: "POST", + body: JSON.stringify({ 'method': 'torrent-add', 'arguments': { 'filename': magnet } }), + headers: { 'Content-Type': 'application/json' } + }); + return res.json(); + + } async addTorrent(b64metainfo) { const res = await fetch(this.getEndpoint(), { method: "POST", diff --git a/contrib/webconsole/torrent_client.html b/contrib/webconsole/torrent_client.html index 01f33732..424340f9 100644 --- a/contrib/webconsole/torrent_client.html +++ b/contrib/webconsole/torrent_client.html @@ -1,6 +1,33 @@ +