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"
);

View File

@ -125,12 +125,11 @@ export function Sidebar() {
});
}
if (game.download?.queued) return t("queued", { title: game.title });
if (game.download?.status === "paused")
return t("paused", { title: game.title });
if (game.download?.status === "active")
return t("queued", { title: game.title });
return game.title;
};

View File

@ -150,7 +150,7 @@ export function DownloadGroup({
return (
<>
<p>{formatDownloadProgress(download.progress)}</p>
{/* <p>{t(game.downloadQueue && lastPacket ? "queued" : "paused")}</p> */}
<p>{t(download.queued ? "queued" : "paused")}</p>
</>
);
}

View File

@ -68,7 +68,7 @@ export default function Downloads() {
return { ...prev, downloading: [...prev.downloading, next] };
/* Is either queued or paused */
if (next.download?.status === "paused")
if (next.download.queued || next.download?.status === "paused")
return { ...prev, queued: [...prev.queued, next] };
return { ...prev, complete: [...prev.complete, next] };

View File

@ -56,6 +56,7 @@ export interface Download {
fileSize: number | null;
shouldSeed: boolean;
status: DownloadStatus | null;
queued: boolean;
timestamp: number;
}