mirror of
https://github.com/hydralauncher/hydra.git
synced 2025-01-24 05:54:55 +03:00
feat: add initial seeding logic and separation between seeding from downloading
This commit is contained in:
parent
83b7fb83ab
commit
bd8974c7cb
@ -2,7 +2,12 @@ import { Game } from "@main/entity";
|
|||||||
import { Downloader } from "@shared";
|
import { Downloader } from "@shared";
|
||||||
import { PythonInstance } from "./python-instance";
|
import { PythonInstance } from "./python-instance";
|
||||||
import { WindowManager } from "../window-manager";
|
import { WindowManager } from "../window-manager";
|
||||||
import { downloadQueueRepository, gameRepository } from "@main/repository";
|
import {
|
||||||
|
downloadQueueRepository,
|
||||||
|
gameRepository,
|
||||||
|
seedListRepository,
|
||||||
|
userPreferencesRepository,
|
||||||
|
} from "@main/repository";
|
||||||
import { publishDownloadCompleteNotification } from "../notifications";
|
import { publishDownloadCompleteNotification } from "../notifications";
|
||||||
import { RealDebridDownloader } from "./real-debrid-downloader";
|
import { RealDebridDownloader } from "./real-debrid-downloader";
|
||||||
import type { DownloadProgress } from "@types";
|
import type { DownloadProgress } from "@types";
|
||||||
@ -50,6 +55,22 @@ export class DownloadManager {
|
|||||||
|
|
||||||
await downloadQueueRepository.delete({ game });
|
await downloadQueueRepository.delete({ game });
|
||||||
|
|
||||||
|
const userPreferences = await userPreferencesRepository.findOne({
|
||||||
|
where: { id: 1 },
|
||||||
|
});
|
||||||
|
|
||||||
|
if (
|
||||||
|
userPreferences?.seedAfterDownloadCompletes &&
|
||||||
|
this.currentDownloader === Downloader.Torrent
|
||||||
|
) {
|
||||||
|
await seedListRepository.save({
|
||||||
|
downloadUri: game.uri!,
|
||||||
|
shouldSeed: true,
|
||||||
|
});
|
||||||
|
|
||||||
|
this.startSeedDownload(game);
|
||||||
|
}
|
||||||
|
|
||||||
const [nextQueueItem] = await downloadQueueRepository.find({
|
const [nextQueueItem] = await downloadQueueRepository.find({
|
||||||
order: {
|
order: {
|
||||||
id: "DESC",
|
id: "DESC",
|
||||||
@ -136,4 +157,10 @@ export class DownloadManager {
|
|||||||
this.currentDownloader = game.downloader;
|
this.currentDownloader = game.downloader;
|
||||||
this.downloadingGameId = game.id;
|
this.downloadingGameId = game.id;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static async startSeedDownload(game: Game) {
|
||||||
|
if (game) {
|
||||||
|
await PythonInstance.startSeeding(game);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -62,6 +62,7 @@ export class PythonInstance {
|
|||||||
|
|
||||||
public static async getStatus() {
|
public static async getStatus() {
|
||||||
if (this.downloadingGameId === -1) return null;
|
if (this.downloadingGameId === -1) return null;
|
||||||
|
console.log("getting status");
|
||||||
|
|
||||||
const response = await this.rpc.get<LibtorrentPayload | null>("/status");
|
const response = await this.rpc.get<LibtorrentPayload | null>("/status");
|
||||||
|
|
||||||
@ -174,6 +175,21 @@ export class PythonInstance {
|
|||||||
.then((response) => response.data);
|
.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) {
|
private static async handleRpcError(_error: unknown) {
|
||||||
await this.rpc.get("/healthcheck").catch(() => {
|
await this.rpc.get("/healthcheck").catch(() => {
|
||||||
logger.error(
|
logger.error(
|
||||||
|
@ -36,3 +36,8 @@ export interface ProcessPayload {
|
|||||||
exe: string;
|
exe: string;
|
||||||
pid: number;
|
pid: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface SeedPayload {
|
||||||
|
should_seed: boolean;
|
||||||
|
}
|
||||||
|
|
||||||
|
@ -26,6 +26,8 @@ contextBridge.exposeInMainWorld("electron", {
|
|||||||
ipcRenderer.invoke("pauseGameDownload", gameId),
|
ipcRenderer.invoke("pauseGameDownload", gameId),
|
||||||
resumeGameDownload: (gameId: number) =>
|
resumeGameDownload: (gameId: number) =>
|
||||||
ipcRenderer.invoke("resumeGameDownload", gameId),
|
ipcRenderer.invoke("resumeGameDownload", gameId),
|
||||||
|
startSeeding: (gameId: number, magnet: string, savePath: string) =>
|
||||||
|
ipcRenderer.invoke("startSeeding", gameId, magnet, savePath),
|
||||||
onDownloadProgress: (cb: (value: DownloadProgress) => void) => {
|
onDownloadProgress: (cb: (value: DownloadProgress) => void) => {
|
||||||
const listener = (
|
const listener = (
|
||||||
_event: Electron.IpcRendererEvent,
|
_event: Electron.IpcRendererEvent,
|
||||||
|
@ -107,6 +107,8 @@ class Handler(BaseHTTPRequestHandler):
|
|||||||
elif data['action'] == 'kill-torrent':
|
elif data['action'] == 'kill-torrent':
|
||||||
torrent_downloader.abort_session()
|
torrent_downloader.abort_session()
|
||||||
torrent_downloader = None
|
torrent_downloader = None
|
||||||
|
elif data['action'] == 'start-seeding':
|
||||||
|
torrent_downloader.start_seeding(data['game_id'], data['magnet'], data['save_path'])
|
||||||
|
|
||||||
self.send_response(200)
|
self.send_response(200)
|
||||||
self.end_headers()
|
self.end_headers()
|
||||||
|
@ -163,3 +163,12 @@ class TorrentDownloader:
|
|||||||
self.downloading_game_id = -1
|
self.downloading_game_id = -1
|
||||||
|
|
||||||
return response
|
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")
|
||||||
|
Loading…
Reference in New Issue
Block a user