File size: 586 Bytes
ac64cdc
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
import { query } from "$app/server";
import typia from "typia";

type AvatarJson = {
	avatarUrl: string;
};

export const getAvatarUrl = query(
	typia.createValidate<string | undefined>(),
	async (orgName): Promise<string | undefined> => {
		if (!orgName) return;
		const url = `https://huggingface.co/api/organizations/${orgName}/avatar`;
		const res = await fetch(url);
		if (!res.ok) {
			throw new Error(`Error getting avatar url for org: ${orgName}`);
		}

		const json = await res.json();
		typia.assert<AvatarJson>(json);
		const { avatarUrl } = json;
		return avatarUrl;
	},
);