From fc003841b00a2017886cc82cfadb019dc3ae2736 Mon Sep 17 00:00:00 2001 From: Zamitto <167933696+zamitto@users.noreply.github.com> Date: Sat, 1 Feb 2025 16:23:26 -0300 Subject: [PATCH] feat: merge adjustments --- src/main/events/auth/sign-out.ts | 1 - ...50111182229_add_torbox_api_token_column.ts | 17 -- .../services/download/download-manager.ts | 10 +- src/main/services/process-watcher.ts | 2 +- .../src/pages/downloads/download-group.tsx | 6 +- .../pages/settings/settings-debrid-input.tsx | 186 ------------------ src/types/index.ts | 18 -- 7 files changed, 10 insertions(+), 230 deletions(-) delete mode 100644 src/main/migrations/20250111182229_add_torbox_api_token_column.ts delete mode 100644 src/renderer/src/pages/settings/settings-debrid-input.tsx diff --git a/src/main/events/auth/sign-out.ts b/src/main/events/auth/sign-out.ts index e7f90aa5..2ab5e458 100644 --- a/src/main/events/auth/sign-out.ts +++ b/src/main/events/auth/sign-out.ts @@ -1,6 +1,5 @@ import { registerEvent } from "../register-event"; import { DownloadManager, HydraApi, gamesPlaytime } from "@main/services"; -import { PythonRPC } from "@main/services/python-rpc"; import { db, downloadsSublevel, gamesSublevel, levelKeys } from "@main/level"; const signOut = async (_event: Electron.IpcMainInvokeEvent) => { diff --git a/src/main/migrations/20250111182229_add_torbox_api_token_column.ts b/src/main/migrations/20250111182229_add_torbox_api_token_column.ts deleted file mode 100644 index fc1904fd..00000000 --- a/src/main/migrations/20250111182229_add_torbox_api_token_column.ts +++ /dev/null @@ -1,17 +0,0 @@ -import type { HydraMigration } from "@main/knex-client"; -import type { Knex } from "knex"; - -export const AddTorBoxApiToken: HydraMigration = { - name: "AddTorBoxApiToken", - up: (knex: Knex) => { - return knex.schema.alterTable("user_preferences", (table) => { - return table.string("torBoxApiToken").nullable(); - }); - }, - - down: async (knex: Knex) => { - return knex.schema.alterTable("user_preferences", (table) => { - return table.dropColumn("torBoxApiToken"); - }); - }, -}; diff --git a/src/main/services/download/download-manager.ts b/src/main/services/download/download-manager.ts index e6ae91e2..c0145b41 100644 --- a/src/main/services/download/download-manager.ts +++ b/src/main/services/download/download-manager.ts @@ -271,7 +271,7 @@ export class DownloadManager { }; } case Downloader.PixelDrain: { - const id = game.uri!.split("/").pop(); + const id = download.uri.split("/").pop(); const name = await axios .get(`https://pixeldrain.com/api/file/${id}/info`) @@ -281,7 +281,7 @@ export class DownloadManager { action: "start", game_id: downloadId, url: `https://pixeldrain.com/api/file/${id}?download`, - save_path: game.downloadPath!, + save_path: download.downloadPath, out: name, }; } @@ -326,15 +326,15 @@ export class DownloadManager { }; } case Downloader.TorBox: { - const { name, url } = await TorBoxClient.getDownloadInfo(game.uri!); + const { name, url } = await TorBoxClient.getDownloadInfo(download.uri); console.log(url, name); if (!url) return; return { action: "start", - game_id: game.id, + game_id: downloadId, url, - save_path: game.downloadPath!, + save_path: download.downloadPath, out: name, }; } diff --git a/src/main/services/process-watcher.ts b/src/main/services/process-watcher.ts index bfa5cc19..0cf4605f 100644 --- a/src/main/services/process-watcher.ts +++ b/src/main/services/process-watcher.ts @@ -285,7 +285,7 @@ const onCloseGame = (game: Game) => { if (game.remoteId) { // create backup // todo: check for hydra cloud? - createBackup(game.objectID, game.shop, ""); + createBackup(game.objectId, game.shop, ""); updateGamePlaytime( game, diff --git a/src/renderer/src/pages/downloads/download-group.tsx b/src/renderer/src/pages/downloads/download-group.tsx index 85ace39b..68794650 100644 --- a/src/renderer/src/pages/downloads/download-group.tsx +++ b/src/renderer/src/pages/downloads/download-group.tsx @@ -300,7 +300,7 @@ export function DownloadGroup({ />
- {game.downloader === Downloader.TorBox ? ( + {game.download?.downloader === Downloader.TorBox ? (
TorBox
) : ( - {DOWNLOADER_NAME[game.downloader]} + + {DOWNLOADER_NAME[game.download!.downloader]} + )}
diff --git a/src/renderer/src/pages/settings/settings-debrid-input.tsx b/src/renderer/src/pages/settings/settings-debrid-input.tsx deleted file mode 100644 index 5223e378..00000000 --- a/src/renderer/src/pages/settings/settings-debrid-input.tsx +++ /dev/null @@ -1,186 +0,0 @@ -import { useContext, useEffect, useMemo, useState } from "react"; -import { Trans, useTranslation } from "react-i18next"; -import { Button, CheckboxField, Link, TextField } from "@renderer/components"; -import * as styles from "./settings-debrid.css"; -import { useAppSelector, useToast } from "@renderer/hooks"; -import { SPACING_UNIT } from "@renderer/theme.css"; -import { settingsContext } from "@renderer/context"; -import { DebridServices } from "@types"; - -const REAL_DEBRID_API_TOKEN_URL = "https://real-debrid.com/apitoken"; -const TORBOX_API_TOKEN_URL = "https://torbox.app/settings"; - -interface SettingsDebridForm { - useRealDebrid: boolean; - realDebridApiToken: string | null; - useTorBox: boolean; - torBoxApiToken: string | null; -} - -export interface SettingsDebridProps { - service: DebridServices; - form: SettingsDebridForm; - setForm: (SettingsDebridForm) => void; -} - -export function SettingsDebridInput({ - service, - form, - setForm, -}: SettingsDebridProps) { - const userPreferences = useAppSelector( - (state) => state.userPreferences.value - ); - - const { updateUserPreferences } = useContext(settingsContext); - - const [isLoading, setIsLoading] = useState(false); - - const { showSuccessToast, showErrorToast } = useToast(); - - const { t } = useTranslation("settings"); - - useEffect(() => { - if (userPreferences) { - setForm({ - useRealDebrid: Boolean(userPreferences.realDebridApiToken), - realDebridApiToken: userPreferences.realDebridApiToken ?? null, - useTorBox: Boolean(userPreferences.torBoxApiToken), - torBoxApiToken: userPreferences.torBoxApiToken ?? null, - }); - } - }, [userPreferences]); - - const handleFormSubmit: React.FormEventHandler = async ( - event - ) => { - setIsLoading(true); - event.preventDefault(); - - try { - if (form.useRealDebrid) { - const user = await window.electron.authenticateRealDebrid( - form.realDebridApiToken! - ); - - if (user.type === "free") { - showErrorToast( - t("real_debrid_free_account_error", { username: user.username }) - ); - - return; - } else { - showSuccessToast( - t("real_debrid_linked_message", { username: user.username }) - ); - } - } else { - showSuccessToast(t("changes_saved")); - } - - updateUserPreferences({ - realDebridApiToken: form.useRealDebrid ? form.realDebridApiToken : null, - }); - } catch (err) { - showErrorToast(t("real_debrid_invalid_token")); - } finally { - setIsLoading(false); - } - }; - - const useDebridService = useMemo(() => { - if (service === "RealDebrid") { - return form.useRealDebrid; - } - - if (service === "TorBox") { - return form.useTorBox; - } - - return false; - }, [form, service]); - - const debridApiToken = useMemo(() => { - if (service === "RealDebrid") { - return form.realDebridApiToken; - } - - if (service === "TorBox") { - return form.torBoxApiToken; - } - - return null; - }, [form, service]); - - const onChangeCheckbox = () => { - if (service === "RealDebrid") { - setForm((prev) => ({ - ...prev, - useRealDebrid: !form.useRealDebrid, - })); - } - - if (service === "TorBox") { - setForm((prev) => ({ - ...prev, - useTorBox: !form.useTorBox, - })); - } - }; - - const onChangeInput = (event: React.ChangeEvent) => { - if (service === "RealDebrid") { - setForm((prev) => ({ - ...prev, - realDebridApiToken: event.target.value, - })); - } - - if (service === "TorBox") { - setForm((prev) => ({ - ...prev, - torBoxApiToken: event.target.value, - })); - } - }; - - const isButtonDisabled = - (form.useRealDebrid && !form.realDebridApiToken) || isLoading; - - return ( -
- - - {useDebridService && ( - - {t("save")} - - } - hint={ - - - - } - /> - )} - - ); -} diff --git a/src/types/index.ts b/src/types/index.ts index f436551f..75000f36 100644 --- a/src/types/index.ts +++ b/src/types/index.ts @@ -55,24 +55,6 @@ export interface GameRunning { sessionDurationInMillis: number; } -export interface DownloadProgress { - downloadSpeed: number; - timeRemaining: number; - numPeers: number; - numSeeds: number; - isDownloadingMetadata: boolean; - isCheckingFiles: boolean; - progress: number; - gameId: number; - game: LibraryGame; -} - -export interface SeedingStatus { - gameId: number; - status: GameStatus; - uploadSpeed: number; -} - export interface UserPreferences { downloadsPath: string | null; language: string;