40 lines
1.0 KiB
TypeScript
40 lines
1.0 KiB
TypeScript
import { jsonError, jsonResponse } from "../../../common.js";
|
|
import { queryLogs } from "../../../gcloud.js";
|
|
|
|
export async function onRequestGet(context: RequestContext) {
|
|
const robloxUserReq = await fetch(
|
|
"https://users.roblox.com/v1/usernames/users",
|
|
{
|
|
body: JSON.stringify({
|
|
excludeBannedUsers: false,
|
|
usernames: [context.params.user as string],
|
|
}),
|
|
headers: {
|
|
"content-type": "application/json",
|
|
},
|
|
method: "POST",
|
|
},
|
|
);
|
|
|
|
if (!robloxUserReq.ok) {
|
|
console.log(await robloxUserReq.json());
|
|
return jsonError("Failed to resolve username", 500);
|
|
}
|
|
|
|
const { data: users }: { data: { [k: string]: any }[] } =
|
|
await robloxUserReq.json();
|
|
|
|
if (!users.length) return jsonError("No user found with that name", 400);
|
|
|
|
return jsonResponse(
|
|
JSON.stringify(
|
|
(await queryLogs(users[0].id, context)).sort((a, b) =>
|
|
a.entity.properties.executed_at.integerValue >
|
|
b.entity.properties.executed_at.integerValue
|
|
? 1
|
|
: -1,
|
|
),
|
|
),
|
|
);
|
|
}
|