fix: fixing multiple connections

This commit is contained in:
Chubby Granny Chaser
2025-04-09 07:57:00 +01:00
parent 7fd0894b56
commit 1835adf8b4
6 changed files with 66 additions and 50 deletions

View File

@@ -1,48 +1,61 @@
import aria2p
class HttpDownloader:
def __init__(self):
self.download = None
self.aria2 = aria2p.API(
aria2p.Client(
host="http://localhost",
port=6800,
secret=""
)
)
def __init__(self):
self.download = None
self.aria2 = aria2p.API(
aria2p.Client(
host="http://localhost",
port=6800,
secret=""
)
)
def start_download(self, url: str, save_path: str, header: str, out: str = None):
if self.download:
self.aria2.resume([self.download])
else:
downloads = self.aria2.add(url, options={"header": header, "dir": save_path, "out": out})
self.download = downloads[0]
def pause_download(self):
if self.download:
self.aria2.pause([self.download])
def cancel_download(self):
if self.download:
self.aria2.remove([self.download])
self.download = None
def start_download(self, url: str, save_path: str, header: str, out: str = None, allow_multiple_connections: bool = False):
if self.download:
self.aria2.resume([self.download])
else:
options = {
"header": header,
"dir": save_path,
"out": out
}
def get_download_status(self):
if self.download == None:
return None
if allow_multiple_connections:
options.update({
"split": "16",
"max-connection-per-server": "16",
"min-split-size": "1M"
})
downloads = self.aria2.add(url, options=options)
self.download = downloads[0]
def pause_download(self):
if self.download:
self.aria2.pause([self.download])
def cancel_download(self):
if self.download:
self.aria2.remove([self.download])
self.download = None
download = self.aria2.get_download(self.download.gid)
def get_download_status(self):
if self.download == None:
return None
response = {
'folderName': download.name,
'fileSize': download.total_length,
'progress': download.completed_length / download.total_length if download.total_length else 0,
'downloadSpeed': download.download_speed,
'numPeers': 0,
'numSeeds': 0,
'status': download.status,
'bytesDownloaded': download.completed_length,
}
download = self.aria2.get_download(self.download.gid)
return response
response = {
'folderName': download.name,
'fileSize': download.total_length,
'progress': download.completed_length / download.total_length if download.total_length else 0,
'downloadSpeed': download.download_speed,
'numPeers': 0,
'numSeeds': 0,
'status': download.status,
'bytesDownloaded': download.completed_length,
}
return response

View File

@@ -147,11 +147,11 @@ def action():
torrent_downloader.start_download(url, data['save_path'])
else:
if existing_downloader and isinstance(existing_downloader, HttpDownloader):
existing_downloader.start_download(url, data['save_path'], data.get('header'), data.get('out'))
existing_downloader.start_download(url, data['save_path'], data.get('header'), data.get('out'), data.get('allow_multiple_connections', False))
else:
http_downloader = HttpDownloader()
downloads[game_id] = http_downloader
http_downloader.start_download(url, data['save_path'], data.get('header'), data.get('out'))
http_downloader.start_download(url, data['save_path'], data.get('header'), data.get('out'), data.get('allow_multiple_connections', False))
downloading_game_id = game_id

View File

@@ -123,3 +123,10 @@ const copyAria2 = () => {
copyAria2();
downloadLudusavi();
if (process.platform !== "win32") {
const binariesPath = path.join(__dirname, "..", "binaries");
fs.chmodSync(path.join(binariesPath, "7zz"), 0o755);
fs.chmodSync(path.join(binariesPath, "7zzs"), 0o755);
}

View File

@@ -45,13 +45,13 @@ export class SevenZip {
args.push("-o" + outputPath);
}
console.log(this.binaryPath, args);
const child = cp.execFile(this.binaryPath, args, {
cwd,
});
child.once("exit", (code) => {
console.log("EXIT CALLED", code, filePath);
if (code === 0) {
successCb();
return;

View File

@@ -16,12 +16,6 @@ export class Aria2 {
"--rpc-listen-all",
"--file-allocation=none",
"--allow-overwrite=true",
"-s",
"16",
"-x",
"16",
"-k",
"1M",
],
{ stdio: "inherit", windowsHide: true }
);

View File

@@ -371,6 +371,7 @@ export class DownloadManager {
game_id: downloadId,
url: downloadUrl,
save_path: download.downloadPath,
allow_multiple_connections: true,
};
}
case Downloader.TorBox: {
@@ -383,6 +384,7 @@ export class DownloadManager {
url,
save_path: download.downloadPath,
out: name,
allow_multiple_connections: true,
};
}
}