Merge branch 'feature/seed-completed-downloads' into feat/achievements-points

This commit is contained in:
Zamitto
2024-12-23 14:33:00 -03:00
5 changed files with 36 additions and 33 deletions

View File

@@ -24,13 +24,20 @@ import { logger } from "../logger";
export class DownloadManager {
private static downloadingGameId: number | null = null;
public static startRPC(game: Game) {
public static startRPC(game: Game, initialSeeding?: Game[]) {
if (game && game.status === "active") {
PythonRPC.spawn({
game_id: game.id,
url: game.uri!,
save_path: game.downloadPath!,
});
PythonRPC.spawn(
{
game_id: game.id,
url: game.uri!,
save_path: game.downloadPath!,
},
initialSeeding?.map((game) => ({
game_id: game.id,
url: game.uri!,
save_path: game.downloadPath!,
}))
);
this.downloadingGameId = game.id;
}

View File

@@ -9,7 +9,7 @@ import { logger } from "./logger";
import { Readable } from "node:stream";
import { app, dialog } from "electron";
interface StartDownloadPayload {
interface GamePayload {
game_id: number;
url: string;
save_path: string;
@@ -42,12 +42,16 @@ export class PythonRPC {
readable.on("data", logger.log);
}
public static spawn(initialDownload?: StartDownloadPayload) {
public static spawn(
initialDownload?: GamePayload,
initialSeeding?: GamePayload[]
) {
const commonArgs = [
this.BITTORRENT_PORT,
this.RPC_PORT,
this.RPC_PASSWORD,
initialDownload ? JSON.stringify(initialDownload) : "",
initialSeeding ? JSON.stringify(initialSeeding) : "",
];
if (app.isPackaged) {

View File

@@ -1,21 +0,0 @@
import { gameRepository } from "@main/repository";
import { DownloadManager } from "./download/download-manager";
import { sleep } from "@main/helpers";
export const startSeedProcess = async () => {
const seedList = await gameRepository.find({
where: {
shouldSeed: true,
downloader: 1,
progress: 1,
},
});
if (seedList.length === 0) return;
await sleep(1000);
seedList.map(async (game) => {
await DownloadManager.startDownload(game);
await sleep(300);
});
};