Build your personal knowledge base with Trilium Notes
TypeScript electronelectron-appknowledge-baseknowledge-graphknowledge-managementknowledge-management-graphlocal-firstnote-managmentnote-takernote-takingnotebooknotesnotes-apppersonal-knowledge-basepersonal-wikiscriptableself-hostedself-hostingwiki
server-esm: Handle proxy agent
Elian Doranda0829245fe7
diff --git a/src/services/request.ts b/src/services/request.tsindex fe057024cd..687e686d8a 100644--- a/src/services/request.ts+++ b/src/services/request.ts@@ -33,7 +33,7 @@ interface Client {request(opts: ClientOpts): Request;}-function exec<T>(opts: ExecOpts): Promise<T> {+async function exec<T>(opts: ExecOpts): Promise<T> {const client = getClient(opts);// hack for cases where electron.net does not work, but we don't want to set proxy@@ -47,7 +47,7 @@ function exec<T>(opts: ExecOpts): Promise<T> {requestId: 'n/a'};- const proxyAgent = getProxyAgent(opts);+ const proxyAgent = await getProxyAgent(opts);const parsedTargetUrl = url.parse(opts.url);return new Promise((resolve, reject) => {@@ -137,7 +137,7 @@ function exec<T>(opts: ExecOpts): Promise<T> {});}-function getImage(imageUrl: string): Promise<Buffer> {+async function getImage(imageUrl: string): Promise<Buffer> {const proxyConf = syncOptions.getSyncProxy();const opts: ClientOpts = {method: 'GET',@@ -146,7 +146,7 @@ function getImage(imageUrl: string): Promise<Buffer> {};const client = getClient(opts);- const proxyAgent = getProxyAgent(opts);+ const proxyAgent = await getProxyAgent(opts);const parsedTargetUrl = url.parse(opts.url);return new Promise<Buffer>((resolve, reject) => {@@ -189,7 +189,7 @@ function getImage(imageUrl: string): Promise<Buffer> {const HTTP = 'http:', HTTPS = 'https:';-function getProxyAgent(opts: ClientOpts) {+async function getProxyAgent(opts: ClientOpts) {if (!opts.proxy) {return null;}@@ -201,8 +201,8 @@ function getProxyAgent(opts: ClientOpts) {}const AgentClass = HTTP === protocol- ? require('http-proxy-agent').HttpProxyAgent- : require('https-proxy-agent').HttpsProxyAgent;+ ? (await import('http-proxy-agent')).HttpProxyAgent+ : (await import('https-proxy-agent')).HttpsProxyAgent;return new AgentClass(opts.proxy);}