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')
game_id = data.get('game_id')
print(data)
if action == 'start':
url = data.get('url')

View File

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

View File

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