From 551108e04766233092a38871f2ef51ac36259c96 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tr=C3=A8sAbhi?= <43380238+tresabhi@users.noreply.github.com> Date: Fri, 20 Mar 2026 19:13:37 -0500 Subject: [PATCH] feat: some more docs --- packages/website-ue/src/components/ApiMacroType.astro | 7 +++---- packages/website-ue/src/core/api/abstract.ts | 11 +++++++++++ packages/website-ue/src/core/api/server.ts | 7 +++++++ .../website-ue/src/pages/api/avatars/[id].json.ts | 2 +- .../website-ue/src/pages/api/avatars/[id].webp.ts | 6 ++++++ packages/website-ue/src/pages/api/avatars/all.json.ts | 6 ++++++ .../website-ue/src/pages/api/avatars/list.json.ts | 6 ++++-- packages/website-ue/src/protos/avatar_list.proto | 7 +++++++ 8 files changed, 45 insertions(+), 7 deletions(-) create mode 100644 packages/website-ue/src/protos/avatar_list.proto diff --git a/packages/website-ue/src/components/ApiMacroType.astro b/packages/website-ue/src/components/ApiMacroType.astro index 4d1448690..6a88928a4 100644 --- a/packages/website-ue/src/components/ApiMacroType.astro +++ b/packages/website-ue/src/components/ApiMacroType.astro @@ -29,12 +29,11 @@ interface Props { const { value, locale } = Astro.props; const strings = await api.strings(locale); +const lang = "ts"; const roots = ["src/protos", "../closed/protos"]; -const lang = "ts"; - -const name = "Avatar"; -const path = resolve(`${roots[0]}/${value}.ts`); +const [route, name] = value.split("."); +const path = resolve(`${roots[0]}/${route}.ts`); const program = createProgram([path], {}); const source = program.getSourceFile(path); diff --git a/packages/website-ue/src/core/api/abstract.ts b/packages/website-ue/src/core/api/abstract.ts index 9d34ed01f..f0ba8ef21 100644 --- a/packages/website-ue/src/core/api/abstract.ts +++ b/packages/website-ue/src/core/api/abstract.ts @@ -1,6 +1,7 @@ import type { Strings } from "@blitzkit/i18n"; import locales from "@blitzkit/i18n/locales.json"; import type { Avatar } from "../../protos/avatar"; +import type { AvatarList } from "../../protos/avatar_list"; import type { Avatars } from "../../protos/avatars"; import type { Background } from "../../protos/background"; import type { Backgrounds } from "../../protos/backgrounds"; @@ -130,6 +131,16 @@ export abstract class AbstractAPI { return this._avatarsCache; } + private _avatarListCache: AvatarList | undefined; + protected abstract _avatarList(): Promise; + async avatarList() { + if (this._avatarListCache === undefined) { + this._avatarListCache = await this._avatarList(); + } + + return this._avatarListCache; + } + private _backgroundCache: Record = {}; protected abstract _background(id: string): Promise; async background(id: string) { diff --git a/packages/website-ue/src/core/api/server.ts b/packages/website-ue/src/core/api/server.ts index f50a8bc41..9ecf745c9 100644 --- a/packages/website-ue/src/core/api/server.ts +++ b/packages/website-ue/src/core/api/server.ts @@ -193,6 +193,13 @@ export class ServerAPI extends AbstractAPI { return { avatars }; } + protected async _avatarList() { + const avatars = await this.avatars(); + const list = Object.keys(avatars.avatars); + + return { list }; + } + protected async _avatar(id: string) { const avatar = this.metadata.item(`ProfileAvatarEntity.${id}`); const name = avatar.name; diff --git a/packages/website-ue/src/pages/api/avatars/[id].json.ts b/packages/website-ue/src/pages/api/avatars/[id].json.ts index 1903a2570..faf652337 100644 --- a/packages/website-ue/src/pages/api/avatars/[id].json.ts +++ b/packages/website-ue/src/pages/api/avatars/[id].json.ts @@ -16,7 +16,7 @@ export const getStaticPaths = (async () => { * * @see avatars/list.json for all avatar ids. * @see avatars/[id].webp for avatar images. - * @type avatar + * @type avatar.Avatar */ export async function GET({ params }: APIContext) { const avatar = await api.avatar(params.id); diff --git a/packages/website-ue/src/pages/api/avatars/[id].webp.ts b/packages/website-ue/src/pages/api/avatars/[id].webp.ts index 3b521a3db..17be5413e 100644 --- a/packages/website-ue/src/pages/api/avatars/[id].webp.ts +++ b/packages/website-ue/src/pages/api/avatars/[id].webp.ts @@ -4,6 +4,12 @@ import { imageProxy } from "../../../core/api/imageProxy"; export { getStaticPaths } from "./[id].json"; +/** + * Returns an avatar image based on its `id` in the `webp` format. + * + * @see avatars/list.json for all avatar ids. + * @see avatars/[id].json for data on all avatar. + */ export async function GET({ params }: APIContext) { const avatar = await api.avatar(params.id); return await imageProxy(avatar.profile_avatar!.avatar); diff --git a/packages/website-ue/src/pages/api/avatars/all.json.ts b/packages/website-ue/src/pages/api/avatars/all.json.ts index 6f88b1564..6ba1229cf 100644 --- a/packages/website-ue/src/pages/api/avatars/all.json.ts +++ b/packages/website-ue/src/pages/api/avatars/all.json.ts @@ -1,5 +1,11 @@ import { api } from "../../../core/api/dynamic"; +/** + * Identical to `avatars/[id].json`, but returns data on all avatars at once, + * mapped by `id`. Beware, the returned `JSON` is large. + * + * @type avatars.Avatars + */ export async function GET() { const avatars = await api.avatars(); return Response.json(avatars); diff --git a/packages/website-ue/src/pages/api/avatars/list.json.ts b/packages/website-ue/src/pages/api/avatars/list.json.ts index 34e650ea7..bab43c012 100644 --- a/packages/website-ue/src/pages/api/avatars/list.json.ts +++ b/packages/website-ue/src/pages/api/avatars/list.json.ts @@ -1,7 +1,9 @@ import { api } from "../../../core/api/dynamic"; +/** + * @type avatar_list.AvatarList + */ export async function GET() { - const { avatars } = await api.avatars(); - const list = avatars.map((avatar) => avatar.name); + const list = await api.avatarList(); return Response.json(list); } diff --git a/packages/website-ue/src/protos/avatar_list.proto b/packages/website-ue/src/protos/avatar_list.proto new file mode 100644 index 000000000..73728234f --- /dev/null +++ b/packages/website-ue/src/protos/avatar_list.proto @@ -0,0 +1,7 @@ +syntax = "proto3"; + +package blitzkit; + +message AvatarList { + repeated string list = 1; +} \ No newline at end of file