Skip to content
Permalink
Newer
Older
100644 54 lines (47 sloc) 1.46 KB
October 19, 2023 16:50
1
import { jsonError, jsonResponse } from "../../../common.js";
October 19, 2023 16:49
2
import { queryLogs } from "../../../gcloud.js";
3
4
export async function onRequestGet(context: RequestContext) {
5
const robloxUserReq = await fetch(
6
"https://users.roblox.com/v1/usernames/users",
7
{
8
body: JSON.stringify({
9
excludeBannedUsers: false,
10
usernames: [context.params.user as string],
11
}),
12
headers: {
13
"content-type": "application/json",
14
},
15
method: "POST",
October 19, 2023 16:50
16
},
October 19, 2023 16:49
17
);
18
19
if (!robloxUserReq.ok) {
20
console.log(await robloxUserReq.json());
October 19, 2023 16:50
21
return jsonError("Failed to resolve username", 500);
October 19, 2023 16:49
22
}
23
24
const { data: users }: { data: { [k: string]: any }[] } =
25
await robloxUserReq.json();
26
October 19, 2023 16:50
27
if (!users.length) return jsonError("No user found with that name", 400);
October 19, 2023 16:49
28
October 19, 2023 16:50
29
const thumbnailRequest = await fetch(
30
`https://thumbnails.roblox.com/v1/users/avatar?format=Png&size=250x250&userIds=${users[0].id}`,
October 19, 2023 16:49
31
);
October 19, 2023 16:50
32
33
const response = {
34
history: (await queryLogs(users[0].id, context)).sort((a, b) =>
35
a.entity.properties.executed_at.integerValue >
36
b.entity.properties.executed_at.integerValue
37
? 1
38
: -1,
39
),
40
user: {
41
avatar: thumbnailRequest.ok
42
? (
43
(await thumbnailRequest.json()) as {
44
data: { imageUrl: string }[];
45
}
46
).data[0].imageUrl
47
: null,
48
id: users[0].id,
49
name: users[0].name,
50
},
51
};
52
53
return jsonResponse(JSON.stringify(response));
October 19, 2023 16:49
54
}