From dc94a886e6108ed2f4473022639dd2dc59758df8 Mon Sep 17 00:00:00 2001 From: Chubby Granny Chaser Date: Tue, 2 Jul 2024 17:34:46 +0100 Subject: [PATCH 1/5] fix: sorting repacks modal --- src/main/data-source.ts | 1 - .../src/pages/game-details/modals/repacks-modal.tsx | 13 +++++++++---- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/src/main/data-source.ts b/src/main/data-source.ts index b47ce2c0..cafb052b 100644 --- a/src/main/data-source.ts +++ b/src/main/data-source.ts @@ -27,7 +27,6 @@ export const createDataSource = ( DownloadQueue, UserAuth, ], - synchronize: true, database: databasePath, ...options, }); diff --git a/src/renderer/src/pages/game-details/modals/repacks-modal.tsx b/src/renderer/src/pages/game-details/modals/repacks-modal.tsx index feae8e0e..d2d8f5d9 100644 --- a/src/renderer/src/pages/game-details/modals/repacks-modal.tsx +++ b/src/renderer/src/pages/game-details/modals/repacks-modal.tsx @@ -1,4 +1,4 @@ -import { useCallback, useContext, useEffect, useState } from "react"; +import { useCallback, useContext, useEffect, useMemo, useState } from "react"; import { useTranslation } from "react-i18next"; import parseTorrent from "parse-torrent"; @@ -12,6 +12,7 @@ import { format } from "date-fns"; import { DownloadSettingsModal } from "./download-settings-modal"; import { gameDetailsContext } from "@renderer/context"; import { Downloader } from "@shared"; +import { orderBy } from "lodash-es"; export interface RepacksModalProps { visible: boolean; @@ -38,16 +39,20 @@ export function RepacksModal({ const { t } = useTranslation("game_details"); + const sortedRepacks = useMemo(() => { + return orderBy(repacks, (repack) => repack.uploadDate, "desc"); + }, [repacks]); + const getInfoHash = useCallback(async () => { const torrent = await parseTorrent(game?.uri ?? ""); if (torrent.infoHash) setInfoHash(torrent.infoHash); }, [game]); useEffect(() => { - setFilteredRepacks(repacks); + setFilteredRepacks(sortedRepacks); if (game?.uri) getInfoHash(); - }, [repacks, visible, game, getInfoHash]); + }, [sortedRepacks, visible, game, getInfoHash]); const handleRepackClick = (repack: GameRepack) => { setRepack(repack); @@ -58,7 +63,7 @@ export function RepacksModal({ const term = event.target.value.toLocaleLowerCase(); setFilteredRepacks( - repacks.filter((repack) => { + sortedRepacks.filter((repack) => { const lowerCaseTitle = repack.title.toLowerCase(); const lowerCaseRepacker = repack.repacker.toLowerCase(); From 4e422bdf91c1e8b9dfa283da99df9625c499ec79 Mon Sep 17 00:00:00 2001 From: Chubby Granny Chaser Date: Thu, 4 Jul 2024 18:35:47 +0100 Subject: [PATCH 2/5] feat: migrating download source validation to worker thread --- .../validate-download-source.ts | 21 ++++++---------- src/main/main.ts | 2 +- src/main/workers/download-source.worker.ts | 24 ++++++++++++++++++- 3 files changed, 31 insertions(+), 16 deletions(-) diff --git a/src/main/events/download-sources/validate-download-source.ts b/src/main/events/download-sources/validate-download-source.ts index 122eb49c..fdb67961 100644 --- a/src/main/events/download-sources/validate-download-source.ts +++ b/src/main/events/download-sources/validate-download-source.ts @@ -1,17 +1,12 @@ import { registerEvent } from "../register-event"; -import axios from "axios"; import { downloadSourceRepository } from "@main/repository"; -import { downloadSourceSchema } from "../helpers/validators"; import { RepacksManager } from "@main/services"; +import { downloadSourceWorker } from "@main/workers"; const validateDownloadSource = async ( _event: Electron.IpcMainInvokeEvent, url: string ) => { - const response = await axios.get(url); - - const source = downloadSourceSchema.parse(response.data); - const existingSource = await downloadSourceRepository.findOne({ where: { url }, }); @@ -21,14 +16,12 @@ const validateDownloadSource = async ( const repacks = RepacksManager.repacks; - const existingUris = source.downloads - .flatMap((download) => download.uris) - .filter((uri) => repacks.some((repack) => repack.magnet === uri)); - - return { - name: source.name, - downloadCount: source.downloads.length - existingUris.length, - }; + return downloadSourceWorker.run( + { url, repacks }, + { + name: "validateDownloadSource", + } + ); }; registerEvent("validateDownloadSource", validateDownloadSource); diff --git a/src/main/main.ts b/src/main/main.ts index 1abd8c2f..4a48e6a7 100644 --- a/src/main/main.ts +++ b/src/main/main.ts @@ -15,7 +15,7 @@ import { uploadGamesBatch } from "./services/library-sync"; startMainLoop(); const loadState = async (userPreferences: UserPreferences | null) => { - await RepacksManager.updateRepacks(); + RepacksManager.updateRepacks(); import("./events"); diff --git a/src/main/workers/download-source.worker.ts b/src/main/workers/download-source.worker.ts index cc33dd38..066aa6f5 100644 --- a/src/main/workers/download-source.worker.ts +++ b/src/main/workers/download-source.worker.ts @@ -1,6 +1,7 @@ +import { Repack } from "@main/entity"; import { downloadSourceSchema } from "@main/events/helpers/validators"; import { DownloadSourceStatus } from "@shared"; -import type { DownloadSource } from "@types"; +import type { DownloadSource, GameRepack } from "@types"; import axios, { AxiosError, AxiosHeaders } from "axios"; import { z } from "zod"; @@ -48,3 +49,24 @@ export const getUpdatedRepacks = async (downloadSources: DownloadSource[]) => { return results; }; + +export const validateDownloadSource = async ({ + url, + repacks, +}: { + url: string; + repacks: GameRepack[]; +}) => { + const response = await axios.get(url); + + const source = downloadSourceSchema.parse(response.data); + + const existingUris = source.downloads + .flatMap((download) => download.uris) + .filter((uri) => repacks.some((repack) => repack.magnet === uri)); + + return { + name: source.name, + downloadCount: source.downloads.length - existingUris.length, + }; +}; From f706836a43a0d7c42217766c05b3eed48d0c2607 Mon Sep 17 00:00:00 2001 From: Chubby Granny Chaser Date: Thu, 4 Jul 2024 23:11:21 +0100 Subject: [PATCH 3/5] feat: adding directors cut filter --- src/shared/index.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/shared/index.ts b/src/shared/index.ts index ff556ad2..8f45be6b 100644 --- a/src/shared/index.ts +++ b/src/shared/index.ts @@ -53,8 +53,9 @@ export const removeDuplicateSpaces = (name: string) => export const formatName = pipe( removeReleaseYearFromName, - removeSymbolsFromName, removeSpecialEditionFromName, + (str) => str.replace(/DIRECTOR'S CUT/g, ""), + removeSymbolsFromName, removeDuplicateSpaces, (str) => str.trim() ); From 47ca2535e3a834ef3c6438147690b01f4cb4ceff Mon Sep 17 00:00:00 2001 From: Chubby Granny Chaser Date: Thu, 4 Jul 2024 23:12:20 +0100 Subject: [PATCH 4/5] feat: adding directors cut filter --- src/main/workers/download-source.worker.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/src/main/workers/download-source.worker.ts b/src/main/workers/download-source.worker.ts index 066aa6f5..5ec37c7f 100644 --- a/src/main/workers/download-source.worker.ts +++ b/src/main/workers/download-source.worker.ts @@ -1,4 +1,3 @@ -import { Repack } from "@main/entity"; import { downloadSourceSchema } from "@main/events/helpers/validators"; import { DownloadSourceStatus } from "@shared"; import type { DownloadSource, GameRepack } from "@types"; From fdefc0c165f837a8096cec5d3575a0ba45be5294 Mon Sep 17 00:00:00 2001 From: Chubby Granny Chaser Date: Thu, 4 Jul 2024 23:14:09 +0100 Subject: [PATCH 5/5] feat: adding directors cut filter --- src/main/data-source.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/data-source.ts b/src/main/data-source.ts index cafb052b..b47ce2c0 100644 --- a/src/main/data-source.ts +++ b/src/main/data-source.ts @@ -27,6 +27,7 @@ export const createDataSource = ( DownloadQueue, UserAuth, ], + synchronize: true, database: databasePath, ...options, });