feat: few adjustments

This commit is contained in:
Zamitto 2025-01-12 11:00:20 -03:00
parent db2e31b8cc
commit b1dde446b2
3 changed files with 11 additions and 7 deletions

View File

@ -10,19 +10,19 @@ import type {
export class TorBoxClient { export class TorBoxClient {
private static instance: AxiosInstance; private static instance: AxiosInstance;
private static readonly baseURL = "https://api.torbox.app/v1/api"; private static readonly baseURL = "https://api.torbox.app/v1/api";
public static apiToken: string; private static apiToken: string;
static authorize(apiToken: string) { static authorize(apiToken: string) {
this.apiToken = apiToken;
this.instance = axios.create({ this.instance = axios.create({
baseURL: this.baseURL, baseURL: this.baseURL,
headers: { headers: {
Authorization: `Bearer ${apiToken}`, Authorization: `Bearer ${apiToken}`,
}, },
}); });
this.apiToken = apiToken;
} }
static async addMagnet(magnet: string) { private static async addMagnet(magnet: string) {
const form = new FormData(); const form = new FormData();
form.append("magnet", magnet); form.append("magnet", magnet);
@ -31,6 +31,10 @@ export class TorBoxClient {
form form
); );
if (!response.data.success) {
throw new Error(response.data.detail);
}
return response.data.data; return response.data.data;
} }
@ -74,7 +78,7 @@ export class TorBoxClient {
return response.data.data; return response.data.data;
} }
static async getTorrentIdAndName(magnetUri: string) { private static async getTorrentIdAndName(magnetUri: string) {
const userTorrents = await this.getAllTorrentsFromUser(); const userTorrents = await this.getAllTorrentsFromUser();
const { infoHash } = await parseTorrent(magnetUri); const { infoHash } = await parseTorrent(magnetUri);

View File

@ -163,7 +163,7 @@ export interface UserPreferences {
repackUpdatesNotificationsEnabled: boolean; repackUpdatesNotificationsEnabled: boolean;
achievementNotificationsEnabled: boolean; achievementNotificationsEnabled: boolean;
realDebridApiToken: string | null; realDebridApiToken: string | null;
torboxApiToken: string | null; torBoxApiToken: string | null;
preferQuitInsteadOfHiding: boolean; preferQuitInsteadOfHiding: boolean;
runAtStartup: boolean; runAtStartup: boolean;
startMinimized: boolean; startMinimized: boolean;

View File

@ -54,14 +54,14 @@ export interface TorBoxTorrentInfo {
export interface TorBoxTorrentInfoRequest { export interface TorBoxTorrentInfoRequest {
success: boolean; success: boolean;
detail: string; detail: string;
error: string; error: string | null;
data: TorBoxTorrentInfo[]; data: TorBoxTorrentInfo[];
} }
export interface TorBoxAddTorrentRequest { export interface TorBoxAddTorrentRequest {
success: boolean; success: boolean;
detail: string; detail: string;
error: string; error: string | null;
data: { data: {
torrent_id: number; torrent_id: number;
name: string; name: string;