|
|
@ -126,6 +126,7 @@ export default class TorrentClient |
|
|
|
protected addTorrent(torrent: MagnetUri.Instance, downloadPath: string, selectOnly?: number[]) { |
|
|
|
// Select only: Select no files by default due to broken selection mechanism in Webtorrent
|
|
|
|
torrent.so = selectOnly ?? []; |
|
|
|
console.log("Torrent added:", torrent.infoHash); |
|
|
|
return this.__webtorrent.add(torrent, { path: downloadPath }); |
|
|
|
} |
|
|
|
|
|
|
@ -134,6 +135,7 @@ export default class TorrentClient |
|
|
|
*/ |
|
|
|
protected removeTorrent(torrent: WebTorrent.Torrent) { |
|
|
|
this.deleteTorrent(torrent); |
|
|
|
// console.log("Torrent removed:", torrent.infoHash);
|
|
|
|
this.__webtorrent.remove(torrent); |
|
|
|
} |
|
|
|
|
|
|
@ -169,7 +171,7 @@ export default class TorrentClient |
|
|
|
assert(this.__webtorrent.get(torrentInfo.infoHash) === null, "Torrent has already been added"); |
|
|
|
|
|
|
|
// Add the torrent to the client
|
|
|
|
let torrent = this.addTorrent(torrentInfo, options.downloadPath ?? <string>process.env["DEFAULT_STORAGE_PATH"]); |
|
|
|
let torrent = this.addTorrent(torrentInfo, options.downloadPath ?? "/storage/default"); |
|
|
|
|
|
|
|
// When the metadata has beened fetched, select the files to download and store the torrent
|
|
|
|
torrent.once("metadata", () => { |
|
|
@ -192,7 +194,7 @@ export default class TorrentClient |
|
|
|
|
|
|
|
// Get the torrent and ensure it exists it exists
|
|
|
|
let torrent = this.__webtorrent.get(torrentInfo.infoHash); |
|
|
|
assert(torrent !== undefined, "Torrent has not been added"); |
|
|
|
assert(torrent !== null, "Torrent has not been added"); |
|
|
|
|
|
|
|
// Remove the torrent
|
|
|
|
this.removeTorrent(torrent); |
|
|
|