fix: improve download and seeding logic in main process

This commit is contained in:
Hachi-R 2025-02-03 12:55:40 -03:00
parent 5574f6cb20
commit 0e88300747
2 changed files with 12 additions and 13 deletions

View file

@ -8,11 +8,12 @@ const resumeGameSeed = async (
shop: GameShop,
objectId: string
) => {
const download = await downloadsSublevel.get(levelKeys.game(shop, objectId));
const downloadKey = levelKeys.game(shop, objectId);
const download = await downloadsSublevel.get(downloadKey);
if (!download) return;
await downloadsSublevel.put(levelKeys.game(shop, objectId), {
await downloadsSublevel.put(downloadKey, {
...download,
status: "seeding",
shouldSeed: true,

View file

@ -57,23 +57,21 @@ export const loadState = async () => {
.values()
.all()
.then((games) => {
return sortBy(
games.filter((game) => game.queued),
"timestamp",
"DESC"
);
return sortBy(games, "timestamp", "DESC");
});
const [nextItemOnQueue] = downloads;
const [nextItemOnQueue] = downloads.filter((game) => game.queued);
const downloadsToSeed = downloads.filter(
(download) =>
download.shouldSeed &&
download.downloader === Downloader.Torrent &&
download.progress === 1 &&
download.uri !== null
(game) =>
game.shouldSeed &&
game.downloader === Downloader.Torrent &&
game.progress === 1 &&
game.uri !== null
);
console.log("downloadsToSeed", downloadsToSeed);
await DownloadManager.startRPC(nextItemOnQueue, downloadsToSeed);
startMainLoop();