Proxy support for external network access
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import "missing-native-js-functions";
|
||||
import fetch from "node-fetch";
|
||||
import ProxyAgent from 'proxy-agent';
|
||||
import readline from "readline";
|
||||
import fs from "fs/promises";
|
||||
import path from "path";
|
||||
@@ -52,7 +53,8 @@ async function download(url: string, dir: string) {
|
||||
try {
|
||||
// TODO: use file stream instead of buffer (to prevent crash because of high memory usage for big files)
|
||||
// TODO check file hash
|
||||
const response = await fetch(url);
|
||||
const agent = new ProxyAgent();
|
||||
const response = await fetch(url, { agent });
|
||||
const buffer = await response.buffer();
|
||||
const tempDir = await fs.mkdtemp("fosscord");
|
||||
fs.writeFile(path.join(tempDir, "Fosscord.zip"), buffer);
|
||||
@@ -72,7 +74,8 @@ async function getCurrentVersion(dir: string) {
|
||||
|
||||
async function getLatestVersion(url: string) {
|
||||
try {
|
||||
const response = await fetch(url);
|
||||
const agent = new ProxyAgent();
|
||||
const response = await fetch(url, { agent });
|
||||
const content = await response.json();
|
||||
return content.version;
|
||||
} catch (error) {
|
||||
|
||||
Reference in New Issue
Block a user