chore: improving download queue

This commit is contained in:
Chubby Granny Chaser 2025-01-22 01:39:22 +00:00
parent f387560836
commit 549481f85a
No known key found for this signature in database
9 changed files with 25 additions and 12 deletions

View file

@ -19,6 +19,7 @@ const pauseGameDownload = async (
await downloadsSublevel.put(gameKey, {
...download,
status: "paused",
queued: false,
});
}
};

View file

@ -31,6 +31,7 @@ const resumeGameDownload = async (
...download,
status: "active",
timestamp: Date.now(),
queued: true,
});
}
};

View file

@ -72,6 +72,7 @@ const startGameDownload = async (
fileSize: null,
shouldSeed: false,
timestamp: Date.now(),
queued: true,
};
await downloadsSublevel.put(gameKey, download);

View file

@ -1,4 +1,10 @@
import { DownloadManager, logger, Ludusavi, startMainLoop } from "./services";
import {
Crypto,
DownloadManager,
logger,
Ludusavi,
startMainLoop,
} from "./services";
import { RealDebridClient } from "./services/download/real-debrid";
import { HydraApi } from "./services/hydra-api";
import { uploadGamesBatch } from "./services/library-sync";
@ -34,7 +40,11 @@ const loadState = async (userPreferences: UserPreferences | null) => {
.values()
.all()
.then((games) => {
return sortBy(games, "timestamp", "DESC");
return sortBy(
games.filter((game) => game.queued),
"timestamp",
"DESC"
);
});
const [nextItemOnQueue] = downloads;
@ -137,8 +147,8 @@ const migrateFromSqlite = async () => {
await db.put<string, Auth>(
levelKeys.auth,
{
accessToken: users[0].accessToken,
refreshToken: users[0].refreshToken,
accessToken: Crypto.encrypt(users[0].accessToken),
refreshToken: Crypto.encrypt(users[0].refreshToken),
tokenExpirationTimestamp: users[0].tokenExpirationTimestamp,
},
{

View file

@ -137,12 +137,14 @@ export class DownloadManager {
...download,
status: "seeding",
shouldSeed: true,
queued: false,
});
} else {
downloadsSublevel.put(gameId, {
...download,
status: "complete",
shouldSeed: false,
queued: false,
});
this.cancelDownload(gameId);
@ -153,9 +155,7 @@ export class DownloadManager {
.all()
.then((games) => {
return sortBy(
games.filter(
(game) => !["complete", "seeding"].includes(game.status!)
),
games.filter((game) => game.status === "paused" && game.queued),
"timestamp",
"DESC"
);