This commit is contained in:
lilezek
2024-05-04 12:07:44 +02:00
29 changed files with 1212 additions and 1208 deletions

View File

@@ -8,7 +8,7 @@ import { stateManager } from "@main/state-manager";
const { Index } = flexSearch;
const repacksIndex = new Index();
const steamGamesIndex = new Index();
const steamGamesIndex = new Index({ tokenize: "forward" });
const repacks = stateManager.getValue("repacks");
const steamGames = stateManager.getValue("steamGames");

View File

@@ -1,32 +1,35 @@
import { imageCacheRepository } from "@main/repository";
import crypto from "node:crypto";
import fs from "node:fs";
import path from "node:path";
import { registerEvent } from "../register-event";
import { getImageBase64 } from "@main/helpers";
import { getFileBuffer } from "@main/helpers";
import { logger } from "@main/services";
import { imageCachePath } from "@main/constants";
const getOrCacheImage = async (
_event: Electron.IpcMainInvokeEvent,
url: string
) => {
const cache = await imageCacheRepository.findOne({
where: {
url,
},
});
if (!fs.existsSync(imageCachePath)) fs.mkdirSync(imageCachePath);
if (cache) return cache.data;
const extname = path.extname(url);
getImageBase64(url).then((data) =>
imageCacheRepository
.save({
url,
data,
})
.catch(() => {
logger.error(`Failed to cache image "${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;