Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
car-crushers-portal/functions/api/game-bans/[user]/history.ts
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
54 lines (47 sloc)
1.46 KB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
const thumbnailRequest = await fetch( | |
`https://thumbnails.roblox.com/v1/users/avatar?format=Png&size=250x250&userIds=${users[0].id}`, | |
); | |
const response = { | |
history: (await queryLogs(users[0].id, context)).sort((a, b) => | |
a.entity.properties.executed_at.integerValue > | |
b.entity.properties.executed_at.integerValue | |
? 1 | |
: -1, | |
), | |
user: { | |
avatar: thumbnailRequest.ok | |
? ( | |
(await thumbnailRequest.json()) as { | |
data: { imageUrl: string }[]; | |
} | |
).data[0].imageUrl | |
: null, | |
id: users[0].id, | |
name: users[0].name, | |
}, | |
}; | |
return jsonResponse(JSON.stringify(response)); | |
} |