src/utils/roblox.ts (view raw)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
import config from "@/config";
import type {
BLApiResponse,
GetUserResponse,
ThumbnailResponse,
} from "@/types/roblox";
export async function getRobloxUser(userId: string): Promise<{
user: GetUserResponse;
thumbnail: ThumbnailResponse;
}> {
const getUserUrl = `https://apis.roblox.com/cloud/v2/users/${userId}`;
const getThumbnailUrl = `https://apis.roblox.com/cloud/v2/users/${userId}:generateThumbnail`;
const [userRes, thumbnailRes] = await Promise.all([
fetch(getUserUrl, {
headers: {
"Content-Type": "application/json",
"x-api-key": config.data.roblox.apiKey,
},
}),
fetch(getThumbnailUrl, {
headers: {
"Content-Type": "application/json",
"x-api-key": config.data.roblox.apiKey,
},
}),
]);
const [userData, thumbnailData] = await Promise.all([
userRes.json(),
thumbnailRes.json(),
]);
return { user: userData, thumbnail: thumbnailData };
}
export async function getConnectedRobloxUser(
discordId: string,
): Promise<BLApiResponse> {
const getUserUrl = `https://api.blox.link/v4/public/discord-to-roblox/${discordId}`;
const response = await fetch(getUserUrl, {
headers: {
Authorization: config.data.bloxlink.token,
},
});
return await response.json();
}
|