Browse Source

Correct typings. Add logging. Remove unused ENV variables

master
David Ludwig 4 years ago
parent
commit
9832edb910
4 changed files with 9 additions and 9 deletions
  1. +0
    -4
      .env.example
  2. +4
    -2
      src/services/IpcInterface.ts
  3. +4
    -2
      src/services/TorrentClient.ts
  4. +1
    -1
      src/typings/webtorrent-hybrid/index.d.ts

+ 0
- 4
.env.example View File

@ -5,8 +5,4 @@ DB_USER = root
DB_PASSWORD_FILE = /run/secrets/mysql_root_password
DB_DATABASE = autoplex_torrent
DEFAULT_STORAGE_PATH = ./.data
REST_PORT = 3000
IPC_SOCKET_PATH = /tmp/torrent_client.sock

+ 4
- 2
src/services/IpcInterface.ts View File

@ -78,7 +78,7 @@ export default class IpcInterface
/**
* Add a torrent to the client
*/
protected async addTorrent(torrentInfo: IAddTorrent) {
protected async addTorrent(torrentInfo: IAddTorrent, downloadPath?: string) {
let torrent: WebTorrent.Torrent;
if (typeof torrentInfo == "string") {
torrent = await this.torrentClient.add(torrentInfo);
@ -93,7 +93,9 @@ export default class IpcInterface
* @param message Add
*/
protected async removeTorrent(torrentId: string) {
await this.torrentClient.remove(torrentId);
try {
await this.torrentClient.remove(torrentId);
} catch(e) {}
}
protected async listTorrents() {


+ 4
- 2
src/services/TorrentClient.ts View File

@ -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);


+ 1
- 1
src/typings/webtorrent-hybrid/index.d.ts View File

@ -82,7 +82,7 @@ declare module "webtorrent-hybrid" {
readonly torrents: Torrent[];
get(torrentId: Torrent | string | Buffer): Torrent | void;
get(torrentId: Torrent | string | Buffer): Torrent | null;
readonly downloadSpeed: number;


Loading…
Cancel
Save