get top hub scripts

Script windmill Verified

by admin ยท 10/22/2023

The script

Submitted by admin Typescript (fetch-only)
Verified 370 days ago
1
/**
2
 * get top hub scripts
3
 *
4
 */
5
export async function main(
6
  limit: string | undefined,
7
  app: string | undefined,
8
  kind: string | undefined
9
) {
10
  const url = new URL(`${BASE_URL}/api/scripts/hub/top`);
11
  for (const [k, v] of [
12
    ["limit", limit],
13
    ["app", app],
14
    ["kind", kind],
15
  ]) {
16
    if (v !== undefined && v !== "") {
17
      url.searchParams.append(k, v);
18
    }
19
  }
20
  const response = await fetch(url, {
21
    method: "GET",
22
    headers: {
23
      Authorization: "Bearer " + WM_TOKEN,
24
    },
25
    body: undefined,
26
  });
27
  if (!response.ok) {
28
    const text = await response.text();
29
    throw new Error(`${response.status} ${text}`);
30
  }
31
  return await response.json();
32
}
33