mirror of
https://github.com/hydralauncher/hydra.git
synced 2025-03-09 15:40:26 +00:00
feat: add initial download handling in Python RPC and update spawn method to accept download parameters
This commit is contained in:
parent
35d14b33ca
commit
e463ee569a
3 changed files with 43 additions and 10 deletions
|
@ -11,6 +11,7 @@ app = Flask(__name__)
|
||||||
torrent_port = sys.argv[1]
|
torrent_port = sys.argv[1]
|
||||||
http_port = sys.argv[2]
|
http_port = sys.argv[2]
|
||||||
rpc_password = sys.argv[3]
|
rpc_password = sys.argv[3]
|
||||||
|
start_download_payload = sys.argv[4]
|
||||||
|
|
||||||
downloads = {}
|
downloads = {}
|
||||||
# This can be streamed down from Node
|
# This can be streamed down from Node
|
||||||
|
@ -18,6 +19,20 @@ downloading_game_id = -1
|
||||||
|
|
||||||
torrent_session = lt.session({'listen_interfaces': '0.0.0.0:{port}'.format(port=torrent_port)})
|
torrent_session = lt.session({'listen_interfaces': '0.0.0.0:{port}'.format(port=torrent_port)})
|
||||||
|
|
||||||
|
if start_download_payload:
|
||||||
|
initial_download = json.loads(urllib.parse.unquote(start_download_payload))
|
||||||
|
downloading_game_id = initial_download['game_id']
|
||||||
|
|
||||||
|
if initial_download['url'].startswith('magnet'):
|
||||||
|
torrent_downloader = TorrentDownloader(torrent_session)
|
||||||
|
downloads[initial_download['game_id']] = torrent_downloader
|
||||||
|
torrent_downloader.start_download(initial_download['url'], initial_download['save_path'], "")
|
||||||
|
else:
|
||||||
|
http_downloader = HttpDownloader()
|
||||||
|
downloads[initial_download['game_id']] = http_downloader
|
||||||
|
http_downloader.start_download(initial_download['url'], initial_download['save_path'], initial_download.get('header'))
|
||||||
|
|
||||||
|
|
||||||
def validate_rpc_password():
|
def validate_rpc_password():
|
||||||
"""Middleware to validate RPC password."""
|
"""Middleware to validate RPC password."""
|
||||||
header_password = request.headers.get('x-hydra-rpc-password')
|
header_password = request.headers.get('x-hydra-rpc-password')
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
import { DownloadManager, Ludusavi, startMainLoop } from "./services";
|
import { Ludusavi, startMainLoop } from "./services";
|
||||||
import {
|
import {
|
||||||
downloadQueueRepository,
|
downloadQueueRepository,
|
||||||
userPreferencesRepository,
|
userPreferencesRepository,
|
||||||
|
@ -10,7 +10,6 @@ import { uploadGamesBatch } from "./services/library-sync";
|
||||||
import { PythonRPC } from "./services/python-rpc";
|
import { PythonRPC } from "./services/python-rpc";
|
||||||
import { Aria2 } from "./services/aria2";
|
import { Aria2 } from "./services/aria2";
|
||||||
import { startSeedProcess } from "./services/seed";
|
import { startSeedProcess } from "./services/seed";
|
||||||
import { sleep } from "./helpers";
|
|
||||||
|
|
||||||
const loadState = async (userPreferences: UserPreferences | null) => {
|
const loadState = async (userPreferences: UserPreferences | null) => {
|
||||||
import("./events");
|
import("./events");
|
||||||
|
@ -36,12 +35,19 @@ const loadState = async (userPreferences: UserPreferences | null) => {
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
PythonRPC.spawn();
|
if (
|
||||||
await sleep(1000);
|
nextQueueItem?.game.status === "active" &&
|
||||||
// wait for python process to start
|
nextQueueItem?.game.id &&
|
||||||
|
nextQueueItem?.game.uri &&
|
||||||
if (nextQueueItem?.game.status === "active") {
|
nextQueueItem?.game.downloadPath
|
||||||
DownloadManager.startDownload(nextQueueItem.game);
|
) {
|
||||||
|
PythonRPC.spawn({
|
||||||
|
game_id: nextQueueItem.game.id,
|
||||||
|
url: nextQueueItem.game.uri,
|
||||||
|
save_path: nextQueueItem.game.downloadPath,
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
PythonRPC.spawn();
|
||||||
}
|
}
|
||||||
|
|
||||||
await startSeedProcess();
|
await startSeedProcess();
|
||||||
|
|
|
@ -9,6 +9,12 @@ import { logger } from "./logger";
|
||||||
import { Readable } from "node:stream";
|
import { Readable } from "node:stream";
|
||||||
import { app, dialog } from "electron";
|
import { app, dialog } from "electron";
|
||||||
|
|
||||||
|
interface StartDownloadPayload {
|
||||||
|
game_id: number;
|
||||||
|
url: string;
|
||||||
|
save_path: string;
|
||||||
|
}
|
||||||
|
|
||||||
const binaryNameByPlatform: Partial<Record<NodeJS.Platform, string>> = {
|
const binaryNameByPlatform: Partial<Record<NodeJS.Platform, string>> = {
|
||||||
darwin: "hydra-python-rpc",
|
darwin: "hydra-python-rpc",
|
||||||
linux: "hydra-python-rpc",
|
linux: "hydra-python-rpc",
|
||||||
|
@ -36,9 +42,15 @@ export class PythonRPC {
|
||||||
readable.on("data", logger.log);
|
readable.on("data", logger.log);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static spawn() {
|
public static spawn(initialDownload?: StartDownloadPayload) {
|
||||||
console.log([this.BITTORRENT_PORT, this.RPC_PORT, this.RPC_PASSWORD]);
|
console.log([this.BITTORRENT_PORT, this.RPC_PORT, this.RPC_PASSWORD]);
|
||||||
const commonArgs = [this.BITTORRENT_PORT, this.RPC_PORT, this.RPC_PASSWORD];
|
|
||||||
|
const commonArgs = [
|
||||||
|
this.BITTORRENT_PORT,
|
||||||
|
this.RPC_PORT,
|
||||||
|
this.RPC_PASSWORD,
|
||||||
|
initialDownload ? JSON.stringify(initialDownload) : "",
|
||||||
|
];
|
||||||
|
|
||||||
if (app.isPackaged) {
|
if (app.isPackaged) {
|
||||||
const binaryName = binaryNameByPlatform[process.platform]!;
|
const binaryName = binaryNameByPlatform[process.platform]!;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue