From ea90b49604fd9d768f574bcd97d3149a05404259 Mon Sep 17 00:00:00 2001 From: Zamitto <167933696+zamitto@users.noreply.github.com> Date: Mon, 23 Dec 2024 10:50:35 -0300 Subject: [PATCH 1/2] chore: sonar adjustments --- python_rpc/profile_image_processor.py | 4 ++-- src/main/services/download/download-manager.ts | 2 +- src/main/services/download/real-debrid.ts | 2 +- src/main/services/download/torbox.ts | 2 +- src/main/services/python-rpc.ts | 2 +- 5 files changed, 6 insertions(+), 6 deletions(-) diff --git a/python_rpc/profile_image_processor.py b/python_rpc/profile_image_processor.py index 9fe8489e..45ba5160 100644 --- a/python_rpc/profile_image_processor.py +++ b/python_rpc/profile_image_processor.py @@ -15,8 +15,8 @@ class ProfileImageProcessor: mime_type = image.get_format_mimetype() return image_path, mime_type else: - newUUID = str(uuid.uuid4()) - new_image_path = os.path.join(tempfile.gettempdir(), newUUID) + ".webp" + new_uuid = str(uuid.uuid4()) + new_image_path = os.path.join(tempfile.gettempdir(), new_uuid) + ".webp" image.save(new_image_path) new_image = Image.open(new_image_path) diff --git a/src/main/services/download/download-manager.ts b/src/main/services/download/download-manager.ts index 3b1c2295..65270429 100644 --- a/src/main/services/download/download-manager.ts +++ b/src/main/services/download/download-manager.ts @@ -172,7 +172,7 @@ export class DownloadManager { if (!game) return; const totalSize = await getDirSize( - path.join(game.downloadPath!, status.folderName!) + path.join(game.downloadPath!, status.folderName) ); if (totalSize < status.fileSize) { diff --git a/src/main/services/download/real-debrid.ts b/src/main/services/download/real-debrid.ts index a6b08e45..8580a963 100644 --- a/src/main/services/download/real-debrid.ts +++ b/src/main/services/download/real-debrid.ts @@ -9,7 +9,7 @@ import type { export class RealDebridClient { private static instance: AxiosInstance; - private static baseURL = "https://api.real-debrid.com/rest/1.0"; + private static readonly baseURL = "https://api.real-debrid.com/rest/1.0"; static authorize(apiToken: string) { this.instance = axios.create({ diff --git a/src/main/services/download/torbox.ts b/src/main/services/download/torbox.ts index ed01bcd3..3eade81d 100644 --- a/src/main/services/download/torbox.ts +++ b/src/main/services/download/torbox.ts @@ -10,7 +10,7 @@ import { logger } from "../logger"; export class TorBoxClient { private static instance: AxiosInstance; - private static baseURL = "https://api.torbox.app/v1/api"; + private static readonly baseURL = "https://api.torbox.app/v1/api"; public static apiToken: string; static authorize(apiToken: string) { diff --git a/src/main/services/python-rpc.ts b/src/main/services/python-rpc.ts index df37f02a..84898c65 100644 --- a/src/main/services/python-rpc.ts +++ b/src/main/services/python-rpc.ts @@ -28,7 +28,7 @@ export class PythonRPC { private static pythonProcess: cp.ChildProcess | null = null; - public static rpc = axios.create({ + public static readonly rpc = axios.create({ baseURL: `http://localhost:${this.RPC_PORT}`, headers: { "x-hydra-rpc-password": this.RPC_PASSWORD, From 843301c8b6b158d04fca36986de2589ef76ac807 Mon Sep 17 00:00:00 2001 From: Hachi-R Date: Mon, 23 Dec 2024 13:50:57 -0300 Subject: [PATCH 2/2] feat: implement pause and resume functionality for game seeding in DownloadManager --- python_rpc/main.py | 8 ++++++++ src/main/events/torrenting/pause-game-seed.ts | 2 +- .../events/torrenting/resume-game-seed.ts | 2 +- .../services/download/download-manager.ts | 19 +++++++++++++++++++ 4 files changed, 29 insertions(+), 2 deletions(-) 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: {