From 86d3f7ac81c10160de9c6b29df46afd659ee9c45 Mon Sep 17 00:00:00 2001 From: Hachi-R Date: Tue, 5 Nov 2024 15:16:10 -0300 Subject: [PATCH] chore: use resumeDownload() --- .../services/download/download-manager.ts | 8 +------ src/main/services/download/python-instance.ts | 22 ++++--------------- torrent-client/torrent_downloader.py | 22 ++++++------------- 3 files changed, 12 insertions(+), 40 deletions(-) diff --git a/src/main/services/download/download-manager.ts b/src/main/services/download/download-manager.ts index 98ee791d..0bcf68db 100644 --- a/src/main/services/download/download-manager.ts +++ b/src/main/services/download/download-manager.ts @@ -79,7 +79,7 @@ export class DownloadManager { }); } - this.startSeedDownload(game); + this.resumeDownload(game); } const [nextQueueItem] = await downloadQueueRepository.find({ @@ -168,10 +168,4 @@ export class DownloadManager { this.currentDownloader = game.downloader; this.downloadingGameId = game.id; } - - static async startSeedDownload(game: Game) { - if (game) { - await PythonInstance.startSeeding(game); - } - } } diff --git a/src/main/services/download/python-instance.ts b/src/main/services/download/python-instance.ts index 821b5805..3bed660e 100644 --- a/src/main/services/download/python-instance.ts +++ b/src/main/services/download/python-instance.ts @@ -62,12 +62,13 @@ export class PythonInstance { public static async getStatus() { if (this.downloadingGameId === -1) return null; - console.log("getting status"); - + const response = await this.rpc.get("/status"); if (response.data === null) return null; + console.log(response.data); + try { const { progress, @@ -105,7 +106,7 @@ export class PythonInstance { ); } - if (progress === 1 && !isCheckingFiles) { + if (progress === 1 && !isCheckingFiles && status !== LibtorrentStatus.Seeding) { this.downloadingGameId = -1; } @@ -175,21 +176,6 @@ export class PythonInstance { .then((response) => response.data); } - static async startSeeding(game: Game) { - if (!this.pythonProcess) { - this.spawn(); - } - - await this.rpc - .post("/action", { - action: "start-seeding", - game_id: game.id, - magnet: game.uri, - save_path: game.downloadPath, - } as StartDownloadPayload) - .catch(() => {}); - } - private static async handleRpcError(_error: unknown) { await this.rpc.get("/healthcheck").catch(() => { logger.error( diff --git a/torrent-client/torrent_downloader.py b/torrent-client/torrent_downloader.py index bcb13ffe..d9f12439 100644 --- a/torrent-client/torrent_downloader.py +++ b/torrent-client/torrent_downloader.py @@ -106,7 +106,7 @@ class TorrentDownloader: params = {'url': magnet, 'save_path': save_path, 'trackers': self.trackers} torrent_handle = self.session.add_torrent(params) self.torrent_handles[game_id] = torrent_handle - torrent_handle.set_flags(lt.torrent_flags.auto_managed) + torrent_handle.set_flags(lt.torrent_flags.auto_managed, lt.torrent_flags.seed_mode) torrent_handle.resume() self.downloading_game_id = game_id @@ -151,24 +151,16 @@ class TorrentDownloader: 'gameId': self.downloading_game_id, 'progress': status.progress, 'downloadSpeed': status.download_rate, + 'uploadSpeed': status.upload_rate, 'numPeers': status.num_peers, 'numSeeds': status.num_seeds, 'status': status.state, 'bytesDownloaded': status.progress * info.total_size() if info else status.all_time_download, } - if status.progress == 1: - torrent_handle.pause() - self.session.remove_torrent(torrent_handle) - self.downloading_game_id = -1 + # if status.progress == 1: + # torrent_handle.pause() + # self.session.remove_torrent(torrent_handle) + # self.downloading_game_id = -1 - return response - - def start_seeding(self, game_id: int, magnet: str, save_path: str): - print("seed log 1") - params = {'url': magnet, 'save_path': save_path, 'trackers': self.trackers} - torrent_handle = self.session.add_torrent(params) - self.torrent_handles[game_id] = torrent_handle - torrent_handle.set_flags(lt.torrent_flags.seed_mode) - torrent_handle.resume() - print("seed log 2") + return response \ No newline at end of file