mirror of
https://github.com/openclaw/openclaw.git
synced 2026-04-03 03:03:24 -04:00
refactor(browser): share download request helper
This commit is contained in:
@@ -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(
|
||||
|
||||
Reference in New Issue
Block a user