refactor: remove unnecessary download key deletion in game installer actions and simplify file size handling in download manager

This commit is contained in:
Moyasee
2026-01-25 10:40:38 +02:00
parent c9afd65536
commit d4bd8f7bf1
6 changed files with 18 additions and 14 deletions

View File

@@ -22,7 +22,6 @@ const getGameInstallerActionType = async (
); );
if (!fs.existsSync(gamePath)) { if (!fs.existsSync(gamePath)) {
await downloadsSublevel.del(downloadKey);
return "open-folder"; return "open-folder";
} }

View File

@@ -38,7 +38,6 @@ const openGameInstaller = async (
); );
if (!fs.existsSync(gamePath)) { if (!fs.existsSync(gamePath)) {
await downloadsSublevel.del(downloadKey);
return true; return true;
} }

View File

@@ -2,7 +2,6 @@ import { registerEvent } from "../register-event";
import type { Download, StartGameDownloadPayload } from "@types"; import type { Download, StartGameDownloadPayload } from "@types";
import { DownloadManager, HydraApi, logger } from "@main/services"; import { DownloadManager, HydraApi, logger } from "@main/services";
import { createGame } from "@main/services/library-sync"; import { createGame } from "@main/services/library-sync";
import { parseBytes } from "@shared";
import { downloadsSublevel, gamesSublevel, levelKeys } from "@main/level"; import { downloadsSublevel, gamesSublevel, levelKeys } from "@main/level";
import { handleDownloadError, prepareGameEntry } from "@main/helpers"; import { handleDownloadError, prepareGameEntry } from "@main/helpers";
@@ -18,7 +17,6 @@ const startGameDownload = async (
downloader, downloader,
uri, uri,
automaticallyExtract, automaticallyExtract,
fileSize,
} = payload; } = payload;
const gameKey = levelKeys.game(shop, objectId); const gameKey = levelKeys.game(shop, objectId);
@@ -48,7 +46,7 @@ const startGameDownload = async (
downloader, downloader,
uri, uri,
folderName: null, folderName: null,
fileSize: parseBytes(fileSize ?? null), fileSize: null,
shouldSeed: false, shouldSeed: false,
timestamp: Date.now(), timestamp: Date.now(),
queued: true, queued: true,

View File

@@ -21,7 +21,7 @@ import { RealDebridClient } from "./real-debrid";
import path from "node:path"; import path from "node:path";
import { logger } from "../logger"; import { logger } from "../logger";
import { db, downloadsSublevel, gamesSublevel, levelKeys } from "@main/level"; import { db, downloadsSublevel, gamesSublevel, levelKeys } from "@main/level";
import { sortBy } from "lodash-es"; import { orderBy } from "lodash-es";
import { TorBoxClient } from "./torbox"; import { TorBoxClient } from "./torbox";
import { GameFilesManager } from "../game-files-manager"; import { GameFilesManager } from "../game-files-manager";
import { HydraDebridClient } from "./hydra-debrid"; import { HydraDebridClient } from "./hydra-debrid";
@@ -323,7 +323,8 @@ export class DownloadManager {
this.sendProgressUpdate(progress, status, game); this.sendProgressUpdate(progress, status, game);
if (progress === 1) { const isComplete = progress === 1 || download.status === "complete";
if (isComplete) {
await this.handleDownloadCompletion(download, game, gameId); await this.handleDownloadCompletion(download, game, gameId);
} }
} }
@@ -422,10 +423,10 @@ export class DownloadManager {
.values() .values()
.all() .all()
.then((games) => .then((games) =>
sortBy( orderBy(
games.filter((game) => game.status === "paused" && game.queued), games.filter((game) => game.status === "paused" && game.queued),
"timestamp", ["timestamp"],
"DESC" ["desc"]
) )
); );

View File

@@ -320,10 +320,17 @@ export class JsHttpDownloader {
return null; return null;
} }
let progress = 0;
if (this.status === "complete") {
progress = 1;
} else if (this.fileSize > 0) {
progress = this.bytesDownloaded / this.fileSize;
}
return { return {
folderName: this.folderName, folderName: this.folderName,
fileSize: this.fileSize, fileSize: this.fileSize,
progress: this.fileSize > 0 ? this.bytesDownloaded / this.fileSize : 0, progress,
downloadSpeed: this.downloadSpeed, downloadSpeed: this.downloadSpeed,
numPeers: 0, numPeers: 0,
numSeeds: 0, numSeeds: 0,

View File

@@ -47,9 +47,9 @@ function hexToRgb(hex: string): [number, number, number] {
if (h.length === 3) { if (h.length === 3) {
h = h[0] + h[0] + h[1] + h[1] + h[2] + h[2]; h = h[0] + h[0] + h[1] + h[1] + h[2] + h[2];
} }
const r = parseInt(h.substring(0, 2), 16) || 0; const r = Number.parseInt(h.substring(0, 2), 16) || 0;
const g = parseInt(h.substring(2, 4), 16) || 0; const g = Number.parseInt(h.substring(2, 4), 16) || 0;
const b = parseInt(h.substring(4, 6), 16) || 0; const b = Number.parseInt(h.substring(4, 6), 16) || 0;
return [r, g, b]; return [r, g, b];
} }