diff --git a/ts/linkPreviews/linkPreviewFetch.ts b/ts/linkPreviews/linkPreviewFetch.ts index 6932cd34fb5..7b3f9a7228e 100644 --- a/ts/linkPreviews/linkPreviewFetch.ts +++ b/ts/linkPreviews/linkPreviewFetch.ts @@ -54,7 +54,7 @@ const MAX_DATE = new Date(3000, 0, 1).valueOf(); const emptyContentType = { type: null, charset: null }; -type FetchFn = (href: string, init: RequestInit) => Promise; +export type FetchFn = (href: string, init: RequestInit) => Promise; export type LinkPreviewMetadata = { title: string; diff --git a/ts/textsecure/WebAPI.ts b/ts/textsecure/WebAPI.ts index 288e9d23e36..4b01644f6aa 100644 --- a/ts/textsecure/WebAPI.ts +++ b/ts/textsecure/WebAPI.ts @@ -999,6 +999,14 @@ export function initialize({ socketManager.authenticate({ username, password }); } + let fetchForLinkPreviews: linkPreviewFetch.FetchFn; + if (proxyUrl) { + const agent = new ProxyAgent(proxyUrl); + fetchForLinkPreviews = (href, init) => fetch(href, { ...init, agent }); + } else { + fetchForLinkPreviews = fetch; + } + // Thanks, function hoisting! return { getSocketStatus, @@ -1968,7 +1976,7 @@ export function initialize({ abortSignal: AbortSignal ) { return linkPreviewFetch.fetchLinkPreviewMetadata( - fetch, + fetchForLinkPreviews, href, abortSignal ); @@ -1978,7 +1986,11 @@ export function initialize({ href: string, abortSignal: AbortSignal ) { - return linkPreviewFetch.fetchLinkPreviewImage(fetch, href, abortSignal); + return linkPreviewFetch.fetchLinkPreviewImage( + fetchForLinkPreviews, + href, + abortSignal + ); } async function makeProxiedRequest(