feat: adding torbox integration

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

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);
}
}