Permalink
Newer
100644
54 lines (47 sloc)
1.46 KB
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
},
17
);
18
19
if (!robloxUserReq.ok) {
20
console.log(await robloxUserReq.json());
22
}
23
24
const { data: users }: { data: { [k: string]: any }[] } =
25
await robloxUserReq.json();
26
29
const thumbnailRequest = await fetch(
30
`https://thumbnails.roblox.com/v1/users/avatar?format=Png&size=250x250&userIds=${users[0].id}`,
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));