From de483da51caf12cb0d0fc5a3b2fcbb81432db95e Mon Sep 17 00:00:00 2001 From: Moyasee Date: Sat, 3 Jan 2026 01:08:25 +0200 Subject: [PATCH] fix: handle download not found exception in HttpDownloader and enforce IPv4 in HTTP agents --- python_rpc/http_downloader.py | 7 ++++++- src/main/services/aria2.ts | 1 + src/main/services/hosters/buzzheavier.ts | 14 ++++++++++++++ src/main/services/hosters/vikingfile.ts | 4 ++++ src/main/services/python-rpc.ts | 4 ++++ 5 files changed, 29 insertions(+), 1 deletion(-) diff --git a/python_rpc/http_downloader.py b/python_rpc/http_downloader.py index 723f6d4b..40428bd7 100644 --- a/python_rpc/http_downloader.py +++ b/python_rpc/http_downloader.py @@ -1,4 +1,5 @@ import aria2p +from aria2p.client import ClientException as DownloadNotFound class HttpDownloader: def __init__(self): @@ -36,7 +37,11 @@ class HttpDownloader: if self.download == None: return None - download = self.aria2.get_download(self.download.gid) + try: + download = self.aria2.get_download(self.download.gid) + except DownloadNotFound: + self.download = None + return None response = { 'folderName': download.name, diff --git a/src/main/services/aria2.ts b/src/main/services/aria2.ts index f3f49018..438008b2 100644 --- a/src/main/services/aria2.ts +++ b/src/main/services/aria2.ts @@ -21,6 +21,7 @@ export class Aria2 { "--rpc-listen-all", "--file-allocation=none", "--allow-overwrite=true", + "--disable-ipv6", ], { stdio: "inherit", windowsHide: true } ); diff --git a/src/main/services/hosters/buzzheavier.ts b/src/main/services/hosters/buzzheavier.ts index 9ef2d830..5aa209b4 100644 --- a/src/main/services/hosters/buzzheavier.ts +++ b/src/main/services/hosters/buzzheavier.ts @@ -1,4 +1,6 @@ import axios from "axios"; +import http from "http"; +import https from "https"; import { HOSTER_USER_AGENT, extractHosterFilename, @@ -28,6 +30,12 @@ export class BuzzheavierApi { await axios.get(baseUrl, { headers: { "User-Agent": HOSTER_USER_AGENT }, timeout: 30000, + httpAgent: new http.Agent({ + family: 4, // Force IPv4 + }), + httpsAgent: new https.Agent({ + family: 4, // Force IPv4 + }), }); const downloadUrl = `${baseUrl}/download`; @@ -43,6 +51,12 @@ export class BuzzheavierApi { validateStatus: (status) => status === 200 || status === 204 || status === 301 || status === 302, timeout: 30000, + httpAgent: new http.Agent({ + family: 4, // Force IPv4 + }), + httpsAgent: new https.Agent({ + family: 4, // Force IPv4 + }), }); const hxRedirect = headResponse.headers["hx-redirect"]; diff --git a/src/main/services/hosters/vikingfile.ts b/src/main/services/hosters/vikingfile.ts index ae09bba2..5f97a767 100644 --- a/src/main/services/hosters/vikingfile.ts +++ b/src/main/services/hosters/vikingfile.ts @@ -1,4 +1,5 @@ import axios from "axios"; +import https from "https"; import { logger } from "../logger"; interface UnlockResponse { @@ -33,6 +34,9 @@ export class VikingFileApi { maxRedirects: 0, validateStatus: (status) => status === 301 || status === 302 || status === 200, + httpsAgent: new https.Agent({ + family: 4, // Force IPv4 + }), }); if ( diff --git a/src/main/services/python-rpc.ts b/src/main/services/python-rpc.ts index 2a1dce79..919f6e7e 100644 --- a/src/main/services/python-rpc.ts +++ b/src/main/services/python-rpc.ts @@ -1,4 +1,5 @@ import axios from "axios"; +import http from "http"; import cp from "node:child_process"; import fs from "node:fs"; @@ -31,6 +32,9 @@ export class PythonRPC { public static readonly RPC_PORT = "8084"; public static readonly rpc = axios.create({ baseURL: `http://localhost:${this.RPC_PORT}`, + httpAgent: new http.Agent({ + family: 4, // Force IPv4 + }), }); private static pythonProcess: cp.ChildProcess | null = null;