diff --git a/python_rpc/main.py b/python_rpc/main.py index ed4e7c4f..1c08e896 100644 --- a/python_rpc/main.py +++ b/python_rpc/main.py @@ -148,6 +148,14 @@ def action(): downloader = downloads.get(game_id) if downloader: downloader.cancel_download() + elif action == 'resume_seeding': + torrent_downloader = TorrentDownloader(torrent_session) + downloads[game_id] = torrent_downloader + torrent_downloader.start_download(data['url'], data['save_path'], "") + elif action == 'pause_seeding': + downloader = downloads.get(game_id) + if downloader: + downloader.cancel_download() else: return jsonify({"error": "Invalid action"}), 400 diff --git a/src/main/events/torrenting/pause-game-seed.ts b/src/main/events/torrenting/pause-game-seed.ts index 5ba7b4ce..df2af756 100644 --- a/src/main/events/torrenting/pause-game-seed.ts +++ b/src/main/events/torrenting/pause-game-seed.ts @@ -11,7 +11,7 @@ const pauseGameSeed = async ( shouldSeed: false, }); - await DownloadManager.cancelDownload(gameId); + await DownloadManager.pauseSeeding(gameId); }; registerEvent("pauseGameSeed", pauseGameSeed); diff --git a/src/main/events/torrenting/resume-game-seed.ts b/src/main/events/torrenting/resume-game-seed.ts index cee0a527..6310f5b8 100644 --- a/src/main/events/torrenting/resume-game-seed.ts +++ b/src/main/events/torrenting/resume-game-seed.ts @@ -22,7 +22,7 @@ const resumeGameSeed = async ( shouldSeed: true, }); - await DownloadManager.startDownload(game); + await DownloadManager.resumeSeeding(game); }; registerEvent("resumeGameSeed", resumeGameSeed); diff --git a/src/main/services/download/download-manager.ts b/src/main/services/download/download-manager.ts index 65270429..9e32a742 100644 --- a/src/main/services/download/download-manager.ts +++ b/src/main/services/download/download-manager.ts @@ -19,6 +19,7 @@ import { calculateETA, getDirSize } from "./helpers"; import { QueryDeepPartialEntity } from "typeorm/query-builder/QueryPartialEntity"; import { RealDebridClient } from "./real-debrid"; import path from "path"; +import { logger } from "../logger"; export class DownloadManager { private static downloadingGameId: number | null = null; @@ -164,6 +165,8 @@ export class DownloadManager { if (!seedStatus.length) return; + logger.log(seedStatus); + seedStatus.forEach(async (status) => { const game = await gameRepository.findOne({ where: { id: status.gameId }, @@ -219,6 +222,22 @@ export class DownloadManager { this.downloadingGameId = null; } + static async resumeSeeding(game: Game) { + await PythonRPC.rpc.post("/action", { + action: "resume_seeding", + game_id: game.id, + url: game.uri, + save_path: game.downloadPath, + }); + } + + static async pauseSeeding(gameId: number) { + await PythonRPC.rpc.post("/action", { + action: "pause_seeding", + game_id: gameId, + }); + } + static async startDownload(game: Game) { switch (game.downloader) { case Downloader.Gofile: {