Forked from neverstew/alias
March 11, 2024
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import { API_URL } from "https://esm.town/v/std/API_URL?v=5";
export async function alias<P extends Params>(params: P): Promise<Result<P>> {
const username = params.username;
let url = `${API_URL}/v1/alias/${username}`;
if ("valName" in params)
url = url + `/${params.valName}`;
const headers: HeadersInit = {};
if ("valName" in params && params.token)
headers.Authorization = `Bearer ${params.token}`;
return await (await fetch(url, { headers })).json();
}
type UserParams = {
username: string;
};
type ValParams = {
username: string;
valName: string;
token?: string;
};
type Params = UserParams | ValParams;
type UserResult = {
id: string;
username: string;
bio: string;
profileImageUrl: string;
};
type ValResult = {
id: string;
author: {
id: string;
username: string;
};
name: string;
code: string;
public: boolean;
privacy: "public" | "private";
version: number;
runEndAt: string;
runStartAt: string;
logs: any[];
output: object;
error: object | null;
readme: string | null;
likeCount: number;
referenceCount: number;
};
type Result<T> = T extends ValParams ? ValResult
: T extends UserParams ? UserResult
: never;
Val Town is a social website to write and deploy JavaScript.
Build APIs and schedule functions from your browser.
Comments
Nobody has commented on this val yet: be the first!
March 11, 2024