From 9362e0f9a948ad7b7eda7aa82badce2e9405103e Mon Sep 17 00:00:00 2001 From: Peter Steinberger Date: Wed, 18 Feb 2026 18:54:27 +0000 Subject: [PATCH] refactor(browser): share download request helper --- src/browser/client-actions-core.ts | 59 +++++++++++++++++------------- 1 file changed, 33 insertions(+), 26 deletions(-) diff --git a/src/browser/client-actions-core.ts b/src/browser/client-actions-core.ts index cce39c03e27..72e27cd9afa 100644 --- a/src/browser/client-actions-core.ts +++ b/src/browser/client-actions-core.ts @@ -88,6 +88,23 @@ export type BrowserDownloadPayload = { path: string; }; +type BrowserDownloadResult = { ok: true; targetId: string; download: BrowserDownloadPayload }; + +async function postDownloadRequest( + baseUrl: string | undefined, + route: "/wait/download" | "/download", + body: Record, + profile?: string, +): Promise { + const q = buildProfileQuery(profile); + return await fetchBrowserJson(withBaseUrl(baseUrl, `${route}${q}`), { + method: "POST", + headers: { "Content-Type": "application/json" }, + body: JSON.stringify(body), + timeoutMs: 20000, + }); +} + export async function browserNavigate( baseUrl: string | undefined, opts: { @@ -165,22 +182,17 @@ export async function browserWaitForDownload( timeoutMs?: number; profile?: string; }, -): Promise<{ ok: true; targetId: string; download: BrowserDownloadPayload }> { - const q = buildProfileQuery(opts.profile); - return await fetchBrowserJson<{ - ok: true; - targetId: string; - download: BrowserDownloadPayload; - }>(withBaseUrl(baseUrl, `/wait/download${q}`), { - method: "POST", - headers: { "Content-Type": "application/json" }, - body: JSON.stringify({ +): Promise { + return await postDownloadRequest( + baseUrl, + "/wait/download", + { targetId: opts.targetId, path: opts.path, timeoutMs: opts.timeoutMs, - }), - timeoutMs: 20000, - }); + }, + opts.profile, + ); } export async function browserDownload( @@ -192,23 +204,18 @@ export async function browserDownload( timeoutMs?: number; profile?: string; }, -): Promise<{ ok: true; targetId: string; download: BrowserDownloadPayload }> { - const q = buildProfileQuery(opts.profile); - return await fetchBrowserJson<{ - ok: true; - targetId: string; - download: BrowserDownloadPayload; - }>(withBaseUrl(baseUrl, `/download${q}`), { - method: "POST", - headers: { "Content-Type": "application/json" }, - body: JSON.stringify({ +): Promise { + return await postDownloadRequest( + baseUrl, + "/download", + { targetId: opts.targetId, ref: opts.ref, path: opts.path, timeoutMs: opts.timeoutMs, - }), - timeoutMs: 20000, - }); + }, + opts.profile, + ); } export async function browserAct(