From b1dde446b2cb6507311b5a6d019bb71baa1606bf Mon Sep 17 00:00:00 2001 From: Zamitto <167933696+zamitto@users.noreply.github.com> Date: Sun, 12 Jan 2025 11:00:20 -0300 Subject: [PATCH] feat: few adjustments --- src/main/services/download/torbox.ts | 12 ++++++++---- src/types/index.ts | 2 +- src/types/torbox.types.ts | 4 ++-- 3 files changed, 11 insertions(+), 7 deletions(-) diff --git a/src/main/services/download/torbox.ts b/src/main/services/download/torbox.ts index f0af52eb..b0d339dd 100644 --- a/src/main/services/download/torbox.ts +++ b/src/main/services/download/torbox.ts @@ -10,19 +10,19 @@ import type { export class TorBoxClient { private static instance: AxiosInstance; private static readonly baseURL = "https://api.torbox.app/v1/api"; - public static apiToken: string; + private static apiToken: string; static authorize(apiToken: string) { + this.apiToken = apiToken; this.instance = axios.create({ baseURL: this.baseURL, headers: { Authorization: `Bearer ${apiToken}`, }, }); - this.apiToken = apiToken; } - static async addMagnet(magnet: string) { + private static async addMagnet(magnet: string) { const form = new FormData(); form.append("magnet", magnet); @@ -31,6 +31,10 @@ export class TorBoxClient { form ); + if (!response.data.success) { + throw new Error(response.data.detail); + } + return response.data.data; } @@ -74,7 +78,7 @@ export class TorBoxClient { return response.data.data; } - static async getTorrentIdAndName(magnetUri: string) { + private static async getTorrentIdAndName(magnetUri: string) { const userTorrents = await this.getAllTorrentsFromUser(); const { infoHash } = await parseTorrent(magnetUri); diff --git a/src/types/index.ts b/src/types/index.ts index 92cc566e..b6fcbbb4 100644 --- a/src/types/index.ts +++ b/src/types/index.ts @@ -163,7 +163,7 @@ export interface UserPreferences { repackUpdatesNotificationsEnabled: boolean; achievementNotificationsEnabled: boolean; realDebridApiToken: string | null; - torboxApiToken: string | null; + torBoxApiToken: string | null; preferQuitInsteadOfHiding: boolean; runAtStartup: boolean; startMinimized: boolean; diff --git a/src/types/torbox.types.ts b/src/types/torbox.types.ts index 51e8bd12..ee72600a 100644 --- a/src/types/torbox.types.ts +++ b/src/types/torbox.types.ts @@ -54,14 +54,14 @@ export interface TorBoxTorrentInfo { export interface TorBoxTorrentInfoRequest { success: boolean; detail: string; - error: string; + error: string | null; data: TorBoxTorrentInfo[]; } export interface TorBoxAddTorrentRequest { success: boolean; detail: string; - error: string; + error: string | null; data: { torrent_id: number; name: string;