mirror of
https://github.com/hydralauncher/hydra.git
synced 2025-03-09 15:40:26 +00:00
fix: moving downloader directly to parser
This commit is contained in:
parent
4d32ff2ac2
commit
866ee7b30d
21 changed files with 1207 additions and 1463 deletions
|
|
@ -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";
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -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",
|
||||
});
|
||||
|
|
@ -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,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue