refactor(browser): share download request helper

This commit is contained in:
Peter Steinberger
2026-02-18 18:54:27 +00:00
parent 2863661bcc
commit 9362e0f9a9

View File

@@ -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<string, unknown>,
profile?: string,
): Promise<BrowserDownloadResult> {
const q = buildProfileQuery(profile);
return await fetchBrowserJson<BrowserDownloadResult>(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<BrowserDownloadResult> {
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<BrowserDownloadResult> {
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(