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