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, shop: GameShop,
objectId: string 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; if (!download) return;
await downloadsSublevel.put(levelKeys.game(shop, objectId), { await downloadsSublevel.put(downloadKey, {
...download, ...download,
status: "seeding", status: "seeding",
shouldSeed: true, shouldSeed: true,

View file

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