1 | |
2 | type Discourse = { |
3 | apiKey: string; |
4 | defaultHost: string; |
5 | apiUsername: string; |
6 | }; |
7 | |
8 | * Update a group |
9 | * |
10 | */ |
11 | export async function main( |
12 | auth: Discourse, |
13 | id: string, |
14 | body: { |
15 | group: { |
16 | name: string; |
17 | full_name?: string; |
18 | bio_raw?: string; |
19 | usernames?: string; |
20 | owner_usernames?: string; |
21 | automatic_membership_email_domains?: string; |
22 | visibility_level?: number; |
23 | primary_group?: false | true; |
24 | flair_icon?: string; |
25 | flair_upload_id?: number; |
26 | flair_bg_color?: string; |
27 | public_admission?: false | true; |
28 | public_exit?: false | true; |
29 | default_notification_level?: number; |
30 | muted_category_ids?: number[]; |
31 | regular_category_ids?: number[]; |
32 | watching_category_ids?: number[]; |
33 | tracking_category_ids?: number[]; |
34 | watching_first_post_category_ids?: number[]; |
35 | }; |
36 | }, |
37 | ) { |
38 | const url = new URL(`https://${auth.defaultHost}/groups/${id}.json`); |
39 |
|
40 | const response = await fetch(url, { |
41 | method: "PUT", |
42 | headers: { |
43 | "Content-Type": "application/json", |
44 | "API-KEY": auth.apiKey, |
45 | "API-USERNAME": auth.apiUsername, |
46 | }, |
47 | body: JSON.stringify(body), |
48 | }); |
49 | if (!response.ok) { |
50 | const text = await response.text(); |
51 | throw new Error(`${response.status} ${text}`); |
52 | } |
53 | return await response.json(); |
54 | } |
55 |
|