feat: adding torbox integration

This commit is contained in:
Chubby Granny Chaser 2024-12-25 21:39:59 +00:00
parent 83e662f633
commit 201d89e2c4
No known key found for this signature in database
9 changed files with 58 additions and 19 deletions

View File

@ -11,6 +11,7 @@ import { uploadGamesBatch } from "./services/library-sync";
import { Aria2 } from "./services/aria2";
import { Downloader } from "@shared";
import { IsNull, Not } from "typeorm";
import { TorBoxClient } from "./services/download/torbox";
const loadState = async (userPreferences: UserPreferences | null) => {
import("./events");
@ -21,6 +22,8 @@ const loadState = async (userPreferences: UserPreferences | null) => {
RealDebridClient.authorize(userPreferences?.realDebridApiToken);
}
TorBoxClient.authorize("7371d5ec-52fa-4b87-9052-0c8c96d947cc");
Ludusavi.addManifestToLudusaviConfig();
HydraApi.setupApi().then(() => {

View File

@ -20,6 +20,7 @@ import { QueryDeepPartialEntity } from "typeorm/query-builder/QueryPartialEntity
import { RealDebridClient } from "./real-debrid";
import path from "path";
import { logger } from "../logger";
import { TorBoxClient } from "./torbox";
export class DownloadManager {
private static downloadingGameId: number | null = null;
@ -29,6 +30,7 @@ export class DownloadManager {
game?.status === "active"
? await this.getDownloadPayload(game).catch(() => undefined)
: undefined,
initialSeeding?.map((game) => ({
game_id: game.id,
url: game.uri!,
@ -294,6 +296,18 @@ export class DownloadManager {
save_path: game.downloadPath!,
};
}
case Downloader.TorBox: {
const downloadUrl = await TorBoxClient.getDownloadUrl(game.uri!);
console.log(downloadUrl);
if (!downloadUrl) return;
return {
action: "start",
game_id: game.id,
url: downloadUrl,
save_path: game.downloadPath!,
};
}
}
}

View File

@ -20,7 +20,7 @@ export class TorBoxClient {
Authorization: `Bearer ${apiToken}`,
},
});
this.apiToken = apiToken;
this.apiToken = "7371d5ec-52fa-4b87-9052-0c8c96d947cc";
}
static async addMagnet(magnet: string) {
@ -55,22 +55,16 @@ export class TorBoxClient {
}
static async requestLink(id: number) {
const searchParams = new URLSearchParams({});
searchParams.set("token", this.apiToken);
searchParams.set("torrent_id", id.toString());
searchParams.set("zip_link", "true");
const searchParams = new URLSearchParams({
token: this.apiToken,
torrent_id: id.toString(),
zip_link: "true",
});
const response = await this.instance.get<TorBoxRequestLinkRequest>(
"/torrents/requestdl?" + searchParams.toString()
);
if (response.status !== 200) {
logger.error(response.data.error);
logger.error(response.data.detail);
return null;
}
return response.data.data;
}
@ -94,4 +88,9 @@ export class TorBoxClient {
const torrent = await this.addMagnet(magnetUri);
return torrent.torrent_id;
}
static async getDownloadUrl(uri: string) {
const id = await this.getTorrentId(uri);
return this.requestLink(id);
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

View File

@ -8,6 +8,7 @@ export const DOWNLOADER_NAME = {
[Downloader.Gofile]: "Gofile",
[Downloader.PixelDrain]: "PixelDrain",
[Downloader.Qiwi]: "Qiwi",
[Downloader.TorBox]: "TorBox",
};
export const MAX_MINUTES_TO_SHOW_IN_PLAYTIME = 120;

View File

@ -31,6 +31,8 @@ import {
XCircleIcon,
} from "@primer/octicons-react";
import torBoxLogo from "@renderer/assets/icons/torbox.webp";
export interface DownloadGroupProps {
library: LibraryGame[];
title: string;
@ -276,7 +278,28 @@ export function DownloadGroup({
/>
<div className={styles.downloadCoverContent}>
<Badge>{DOWNLOADER_NAME[game.downloader]}</Badge>
{game.downloader === Downloader.TorBox ? (
<div
style={{
display: "flex",
alignItems: "center",
background: "#11141b",
padding: `${SPACING_UNIT / 2}px ${SPACING_UNIT}px`,
borderRadius: "4px",
gap: 4,
border: `1px solid ${vars.color.border}`,
}}
>
<img
src={torBoxLogo}
alt="TorBox"
style={{ width: 13 }}
/>
<span style={{ fontSize: 10 }}>TorBox</span>
</div>
) : (
<Badge>{DOWNLOADER_NAME[game.downloader]}</Badge>
)}
</div>
</div>
</div>

View File

@ -68,11 +68,9 @@ export function DownloadSettingsModal({
return true;
});
/* Gives preference to Real Debrid */
const selectedDownloader = filteredDownloaders.includes(
Downloader.RealDebrid
)
? Downloader.RealDebrid
/* Gives preference to TorBox */
const selectedDownloader = filteredDownloaders.includes(Downloader.TorBox)
? Downloader.TorBox
: filteredDownloaders[0];
setSelectedDownloader(

View File

@ -4,6 +4,7 @@ export enum Downloader {
Gofile,
PixelDrain,
Qiwi,
TorBox,
}
export enum DownloadSourceStatus {

View File

@ -92,7 +92,7 @@ export const getDownloadersForUri = (uri: string) => {
return [Downloader.RealDebrid];
if (uri.startsWith("magnet:")) {
return [Downloader.Torrent, Downloader.RealDebrid];
return [Downloader.Torrent, Downloader.TorBox, Downloader.RealDebrid];
}
return [];