mirror of
https://github.com/hydralauncher/hydra.git
synced 2025-03-09 15:40:26 +00:00
refactor: change logic to seed new downloads
This commit is contained in:
parent
7c039ead10
commit
5078946191
2 changed files with 17 additions and 32 deletions
|
@ -5,7 +5,6 @@ import { WindowManager } from "../window-manager";
|
|||
import {
|
||||
downloadQueueRepository,
|
||||
gameRepository,
|
||||
userPreferencesRepository,
|
||||
} from "@main/repository";
|
||||
import { publishDownloadCompleteNotification } from "../notifications";
|
||||
import { RealDebridDownloader } from "./real-debrid-downloader";
|
||||
|
@ -104,36 +103,6 @@ export class DownloadManager {
|
|||
{ status: "seeding" }
|
||||
);
|
||||
}
|
||||
|
||||
const userPreferences = await userPreferencesRepository.findOneBy({
|
||||
id: 1,
|
||||
});
|
||||
|
||||
const shouldSeedOrNot = await gameRepository.find({
|
||||
where: {
|
||||
id: In(gameIds),
|
||||
shouldSeed: false,
|
||||
isDeleted: false,
|
||||
status: Not(In(["complete", "seeding"])),
|
||||
},
|
||||
});
|
||||
|
||||
if (shouldSeedOrNot.length === 0) return;
|
||||
|
||||
if (userPreferences?.seedAfterDownloadComplete) {
|
||||
await gameRepository.update(
|
||||
{ id: In(shouldSeedOrNot.map((game) => game.id)) },
|
||||
{ shouldSeed: true, status: "seeding" }
|
||||
);
|
||||
} else {
|
||||
await gameRepository.update(
|
||||
{ id: In(shouldSeedOrNot.map((game) => game.id)) },
|
||||
{ shouldSeed: false, status: "complete" }
|
||||
);
|
||||
for (const game of shouldSeedOrNot) {
|
||||
await this.pauseSeeding(game.id);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static async pauseSeeding(gameId: number) {
|
||||
|
|
|
@ -6,7 +6,7 @@ import {
|
|||
RPC_PORT,
|
||||
startTorrentClient as startRPCClient,
|
||||
} from "./torrent-client";
|
||||
import { gameRepository } from "@main/repository";
|
||||
import { gameRepository, userPreferencesRepository } from "@main/repository";
|
||||
import type { DownloadProgress } from "@types";
|
||||
import { QueryDeepPartialEntity } from "typeorm/query-builder/QueryPartialEntity";
|
||||
import { calculateETA } from "./helpers";
|
||||
|
@ -107,6 +107,22 @@ export class PythonInstance {
|
|||
}
|
||||
|
||||
if (progress === 1 && !isCheckingFiles) {
|
||||
const userPreferences = await userPreferencesRepository.findOneBy({
|
||||
id: 1,
|
||||
});
|
||||
|
||||
if (userPreferences?.seedAfterDownloadComplete) {
|
||||
gameRepository.update(
|
||||
{ id: gameId },
|
||||
{ status: "seeding", shouldSeed: true }
|
||||
);
|
||||
} else {
|
||||
gameRepository.update(
|
||||
{ id: gameId },
|
||||
{ status: "complete", shouldSeed: false }
|
||||
);
|
||||
}
|
||||
|
||||
this.downloadingGameId = -1;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue