1 | |
2 | type Actimo = { |
3 | apiKey: string |
4 | } |
5 |
|
6 | export async function main(auth: Actimo, id: string, body: { files?: string[] }) { |
7 | const url = new URL(`https://actimo.com/api/v1/academy/${id}/image`) |
8 |
|
9 | const formData = new FormData() |
10 |
|
11 | for (const [k, v] of Object.entries(body)) { |
12 | if (v !== undefined && k !== undefined) { |
13 | formData.append(k, String(v)) |
14 | } |
15 | } |
16 |
|
17 | const response = await fetch(url, { |
18 | method: 'PUT', |
19 | headers: { |
20 | 'api-key': auth.apiKey |
21 | }, |
22 | body: formData |
23 | }) |
24 |
|
25 | if (!response.ok) { |
26 | const text = await response.text() |
27 | throw new Error(`${response.status} ${text}`) |
28 | } |
29 |
|
30 | return await response.json() |
31 | } |
32 |
|