fix: continue http downloads

This commit is contained in:
Zamitto 2024-12-23 18:36:14 -03:00
parent 53b0c0b08f
commit aa0321df8f
3 changed files with 37 additions and 46 deletions

View File

@ -124,8 +124,6 @@ def action():
action = data.get('action') action = data.get('action')
game_id = data.get('game_id') game_id = data.get('game_id')
print(data)
if action == 'start': if action == 'start':
url = data.get('url') url = data.get('url')

View File

@ -9,7 +9,6 @@ import { RealDebridClient } from "./services/download/real-debrid";
import { HydraApi } from "./services/hydra-api"; import { HydraApi } from "./services/hydra-api";
import { uploadGamesBatch } from "./services/library-sync"; import { uploadGamesBatch } from "./services/library-sync";
import { Aria2 } from "./services/aria2"; import { Aria2 } from "./services/aria2";
import { PythonRPC } from "./services/python-rpc";
const loadState = async (userPreferences: UserPreferences | null) => { const loadState = async (userPreferences: UserPreferences | null) => {
import("./events"); import("./events");
@ -43,11 +42,7 @@ const loadState = async (userPreferences: UserPreferences | null) => {
}, },
}); });
if (nextQueueItem?.game.status === "active") { await DownloadManager.startRPC(nextQueueItem?.game, seedList);
DownloadManager.startRPC(nextQueueItem.game, seedList);
} else {
PythonRPC.spawn();
}
startMainLoop(); startMainLoop();
}; };

View File

@ -24,23 +24,19 @@ import { logger } from "../logger";
export class DownloadManager { export class DownloadManager {
private static downloadingGameId: number | null = null; private static downloadingGameId: number | null = null;
public static startRPC(game: Game, initialSeeding?: Game[]) { public static async startRPC(game?: Game, initialSeeding?: Game[]) {
if (game && game.status === "active") { PythonRPC.spawn(
PythonRPC.spawn( game?.status === "active"
{ ? await this.getDownloadPayload(game).catch(() => undefined)
game_id: game.id, : undefined,
url: game.uri!, initialSeeding?.map((game) => ({
save_path: game.downloadPath!, game_id: game.id,
}, url: game.uri!,
initialSeeding?.map((game) => ({ save_path: game.downloadPath!,
game_id: game.id, }))
url: game.uri!, );
save_path: game.downloadPath!,
}))
);
this.downloadingGameId = game.id; this.downloadingGameId = game?.id ?? null;
}
} }
private static async getDownloadStatus() { private static async getDownloadStatus() {
@ -245,7 +241,7 @@ export class DownloadManager {
}); });
} }
static async startDownload(game: Game) { private static async getDownloadPayload(game: Game) {
switch (game.downloader) { switch (game.downloader) {
case Downloader.Gofile: { case Downloader.Gofile: {
const id = game!.uri!.split("/").pop(); const id = game!.uri!.split("/").pop();
@ -253,56 +249,58 @@ export class DownloadManager {
const token = await GofileApi.authorize(); const token = await GofileApi.authorize();
const downloadLink = await GofileApi.getDownloadLink(id!); const downloadLink = await GofileApi.getDownloadLink(id!);
await PythonRPC.rpc.post("/action", { return {
action: "start", action: "start",
game_id: game.id, game_id: game.id,
url: downloadLink, url: downloadLink,
save_path: game.downloadPath, save_path: game.downloadPath!,
header: `Cookie: accountToken=${token}`, header: `Cookie: accountToken=${token}`,
}); };
break;
} }
case Downloader.PixelDrain: { case Downloader.PixelDrain: {
const id = game!.uri!.split("/").pop(); const id = game!.uri!.split("/").pop();
await PythonRPC.rpc.post("/action", { return {
action: "start", action: "start",
game_id: game.id, game_id: game.id,
url: `https://pixeldrain.com/api/file/${id}?download`, url: `https://pixeldrain.com/api/file/${id}?download`,
save_path: game.downloadPath, save_path: game.downloadPath!,
}); };
break;
} }
case Downloader.Qiwi: { case Downloader.Qiwi: {
const downloadUrl = await QiwiApi.getDownloadUrl(game.uri!); const downloadUrl = await QiwiApi.getDownloadUrl(game.uri!);
await PythonRPC.rpc.post("/action", { return {
action: "start", action: "start",
game_id: game.id, game_id: game.id,
url: downloadUrl, url: downloadUrl,
save_path: game.downloadPath, save_path: game.downloadPath!,
}); };
break;
} }
case Downloader.Torrent: case Downloader.Torrent:
await PythonRPC.rpc.post("/action", { return {
action: "start", action: "start",
game_id: game.id, game_id: game.id,
url: game.uri, url: game.uri!,
save_path: game.downloadPath, save_path: game.downloadPath!,
}); };
break;
case Downloader.RealDebrid: { case Downloader.RealDebrid: {
const downloadUrl = await RealDebridClient.getDownloadUrl(game.uri!); const downloadUrl = await RealDebridClient.getDownloadUrl(game.uri!);
await PythonRPC.rpc.post("/action", { return {
action: "start", action: "start",
game_id: game.id, game_id: game.id,
url: downloadUrl, url: downloadUrl!,
save_path: game.downloadPath, save_path: game.downloadPath!,
}); };
} }
} }
}
static async startDownload(game: Game) {
const payload = await this.getDownloadPayload(game);
await PythonRPC.rpc.post("/action", payload);
this.downloadingGameId = game.id; this.downloadingGameId = game.id;
} }