fix: moving downloader directly to parser

This commit is contained in:
Hydra 2024-05-04 15:09:43 +01:00
parent 4d32ff2ac2
commit 866ee7b30d
21 changed files with 1207 additions and 1463 deletions

View file

@ -18,7 +18,6 @@ import "./library/open-game";
import "./library/open-game-installer";
import "./library/remove-game";
import "./library/remove-game-from-library";
import "./misc/get-or-cache-image";
import "./misc/open-external";
import "./misc/show-open-dialog";
import "./torrenting/cancel-game-download";

View file

@ -3,7 +3,7 @@ import { gameRepository } from "@main/repository";
import { registerEvent } from "../register-event";
import type { GameShop } from "@types";
import { getImageBase64 } from "@main/helpers";
import { getFileBase64 } from "@main/helpers";
import { getSteamGameIconUrl } from "@main/services";
const addGameToLibrary = async (
@ -31,7 +31,7 @@ const addGameToLibrary = async (
}
);
} else {
const iconUrl = await getImageBase64(await getSteamGameIconUrl(objectID));
const iconUrl = await getFileBase64(await getSteamGameIconUrl(objectID));
return gameRepository.insert({
title,

View file

@ -1,40 +0,0 @@
import crypto from "node:crypto";
import fs from "node:fs";
import path from "node:path";
import { registerEvent } from "../register-event";
import { getFileBuffer } from "@main/helpers";
import { logger } from "@main/services";
import { imageCachePath } from "@main/constants";
const getOrCacheImage = async (
_event: Electron.IpcMainInvokeEvent,
url: string
) => {
if (!fs.existsSync(imageCachePath)) fs.mkdirSync(imageCachePath);
const extname = path.extname(url);
const checksum = crypto.createHash("sha256").update(url).digest("hex");
const cachePath = path.join(imageCachePath, `${checksum}${extname}`);
const cache = fs.existsSync(cachePath);
if (cache) return `hydra://${cachePath}`;
getFileBuffer(url).then((buffer) =>
fs.writeFile(cachePath, buffer, (err) => {
if (err) {
logger.error(`Failed to cache image`, err, {
method: "getOrCacheImage",
});
}
})
);
return url;
};
registerEvent(getOrCacheImage, {
name: "getOrCacheImage",
});

View file

@ -5,7 +5,7 @@ import { GameStatus } from "@main/constants";
import { registerEvent } from "../register-event";
import type { GameShop } from "@types";
import { getImageBase64 } from "@main/helpers";
import { getFileBase64 } from "@main/helpers";
import { In } from "typeorm";
const startGameDownload = async (
@ -72,7 +72,7 @@ const startGameDownload = async (
return game;
} else {
const iconUrl = await getImageBase64(await getSteamGameIconUrl(objectID));
const iconUrl = await getFileBase64(await getSteamGameIconUrl(objectID));
const createdGame = await gameRepository.save({
title,