fix: Prevent JAR file corruption during proxy downloads

Fixed binary file corruption when downloading through proxy by using PassThrough stream to preserve data integrity while tracking download progress.
This commit is contained in:
AMIAY
2026-02-01 17:35:25 +01:00
parent cd25f124bd
commit b1d01a2f34

View File

@@ -1,6 +1,7 @@
const crypto = require('crypto');
const axios = require('axios');
const https = require('https');
const { PassThrough } = require('stream');
const PROXY_URL = process.env.HF2P_PROXY_URL || 'your_proxy_url_here';
const SECRET_KEY = process.env.HF2P_SECRET_KEY || 'your_secret_key_here_for_jwt';
@@ -72,17 +73,22 @@ function getProxyDownloadStream(url, onData) {
return;
}
const totalSize = parseInt(response.headers['content-length'], 10);
let downloaded = 0;
response.on('data', (chunk) => {
downloaded += chunk.length;
if (onData) {
if (onData) {
const totalSize = parseInt(response.headers['content-length'], 10);
let downloaded = 0;
const passThrough = new PassThrough();
response.on('data', (chunk) => {
downloaded += chunk.length;
onData(chunk, downloaded, totalSize);
}
});
resolve(response);
});
response.pipe(passThrough);
resolve(passThrough);
} else {
resolve(response);
}
};
protocol.get(options, handleResponse).on('error', reject);