1 |
|
2 | * list workers |
3 | * |
4 | */ |
5 | export async function main( |
6 | page: string | undefined, |
7 | per_page: string | undefined, |
8 | ping_since: string | undefined |
9 | ) { |
10 | const url = new URL(`${BASE_URL}/api/workers/list`); |
11 | for (const [k, v] of [ |
12 | ["page", page], |
13 | ["per_page", per_page], |
14 | ["ping_since", ping_since], |
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 |
|