0

Refresh gravatar

by
Published Oct 17, 2025
Script discourse Verified

The script

Submitted by hugo697 Bun
Verified 235 days ago
1
//native
2
type Discourse = {
3
  apiKey: string;
4
  defaultHost: string;
5
  apiUsername: string;
6
};
7
/**
8
 * Refresh gravatar
9
 *
10
 */
11
export async function main(auth: Discourse, username: string) {
12
  const url = new URL(
13
    `https://${auth.defaultHost}/user_avatar/${username}/refresh_gravatar.json`,
14
  );
15

16
  const response = await fetch(url, {
17
    method: "POST",
18
    headers: {
19
      "API-KEY": auth.apiKey,
20
      "API-USERNAME": auth.apiUsername,
21
    },
22
    body: undefined,
23
  });
24
  if (!response.ok) {
25
    const text = await response.text();
26
    throw new Error(`${response.status} ${text}`);
27
  }
28
  return await response.json();
29
}
30