fix: possible fix for pixel drain and torbox cancel download

This commit is contained in:
Zamitto 2024-12-25 23:15:58 -03:00
parent c9ae543d3e
commit 6ea1f9034b
7 changed files with 31 additions and 25 deletions

View file

@ -2,7 +2,6 @@ import { registerEvent } from "../register-event";
import { DownloadManager, HydraApi, gamesPlaytime } from "@main/services";
import { dataSource } from "@main/data-source";
import { DownloadQueue, Game, UserAuth, UserSubscription } from "@main/entity";
import { PythonRPC } from "@main/services/python-rpc";
const signOut = async (_event: Electron.IpcMainInvokeEvent) => {
const databaseOperations = dataSource
@ -27,9 +26,6 @@ const signOut = async (_event: Electron.IpcMainInvokeEvent) => {
/* Cancels any ongoing downloads */
DownloadManager.cancelDownload();
/* Disconnects libtorrent */
PythonRPC.kill();
HydraApi.handleSignOut();
await Promise.all([

View file

@ -21,6 +21,7 @@ import { RealDebridClient } from "./real-debrid";
import path from "path";
import { logger } from "../logger";
import { TorBoxClient } from "./torbox";
import axios from "axios";
export class DownloadManager {
private static downloadingGameId: number | null = null;
@ -262,11 +263,16 @@ export class DownloadManager {
case Downloader.PixelDrain: {
const id = game!.uri!.split("/").pop();
const name = await axios
.get(`https://pixeldrain.com/api/file/${id}/info`)
.then((res) => res.data.name as string);
return {
action: "start",
game_id: game.id,
url: `https://pixeldrain.com/api/file/${id}?download`,
save_path: game.downloadPath!,
out: name,
};
}
case Downloader.Qiwi: {
@ -297,15 +303,16 @@ export class DownloadManager {
};
}
case Downloader.TorBox: {
const downloadUrl = await TorBoxClient.getDownloadUrl(game.uri!);
console.log(downloadUrl);
const { name, url } = await TorBoxClient.getDownloadInfo(game.uri!);
console.log(url, name);
if (!downloadUrl) return;
if (!url) return;
return {
action: "start",
game_id: game.id,
url: downloadUrl,
url,
save_path: game.downloadPath!,
out: name,
};
}
}

View file

@ -74,7 +74,7 @@ export class TorBoxClient {
return response.data.data;
}
static async getTorrentId(magnetUri: string) {
static async getTorrentIdAndName(magnetUri: string) {
const userTorrents = await this.getAllTorrentsFromUser();
const { infoHash } = await parseTorrent(magnetUri);
@ -82,14 +82,15 @@ export class TorBoxClient {
(userTorrent) => userTorrent.hash === infoHash
);
if (userTorrent) return userTorrent.id;
if (userTorrent) return { id: userTorrent.id, name: userTorrent.name };
const torrent = await this.addMagnet(magnetUri);
return torrent.torrent_id;
return { id: torrent.torrent_id, name: torrent.name };
}
static async getDownloadUrl(uri: string) {
const id = await this.getTorrentId(uri);
return this.requestLink(id);
static async getDownloadInfo(uri: string) {
const { id, name } = await this.getTorrentIdAndName(uri);
const url = await this.requestLink(id);
return { url, name: `${name}.zip` };
}
}

View file

@ -66,6 +66,7 @@ export interface TorBoxAddTorrentRequest {
torrent_id: number;
name: string;
hash: string;
size: number;
};
}