mirror of
https://github.com/blitzkit/blitzkit.git
synced 2026-10-24 03:59:50 +02:00
feat: some more docs
This commit is contained in:
1 parent
5feec9bf1e
commit
551108e047
8 files changed
+45
-7
No files matched your search
@@ -29,12 +29,11 @@ interface Props {
|
|||||||
const { value, locale } = Astro.props;
|
const { value, locale } = Astro.props;
|
||||||
const strings = await api.strings(locale);
|
const strings = await api.strings(locale);
|
||||||
|
|
||||||
|
const lang = "ts";
|
||||||
const roots = ["src/protos", "../closed/protos"];
|
const roots = ["src/protos", "../closed/protos"];
|
||||||
|
|
||||||
const lang = "ts";
|
const [route, name] = value.split(".");
|
||||||
|
const path = resolve(`${roots[0]}/${route}.ts`);
|
||||||
const name = "Avatar";
|
|
||||||
const path = resolve(`${roots[0]}/${value}.ts`);
|
|
||||||
|
|
||||||
const program = createProgram([path], {});
|
const program = createProgram([path], {});
|
||||||
const source = program.getSourceFile(path);
|
const source = program.getSourceFile(path);
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
import type { Strings } from "@blitzkit/i18n";
|
import type { Strings } from "@blitzkit/i18n";
|
||||||
import locales from "@blitzkit/i18n/locales.json";
|
import locales from "@blitzkit/i18n/locales.json";
|
||||||
import type { Avatar } from "../../protos/avatar";
|
import type { Avatar } from "../../protos/avatar";
|
||||||
|
import type { AvatarList } from "../../protos/avatar_list";
|
||||||
import type { Avatars } from "../../protos/avatars";
|
import type { Avatars } from "../../protos/avatars";
|
||||||
import type { Background } from "../../protos/background";
|
import type { Background } from "../../protos/background";
|
||||||
import type { Backgrounds } from "../../protos/backgrounds";
|
import type { Backgrounds } from "../../protos/backgrounds";
|
||||||
@@ -130,6 +131,16 @@ export abstract class AbstractAPI {
|
|||||||
return this._avatarsCache;
|
return this._avatarsCache;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private _avatarListCache: AvatarList | undefined;
|
||||||
|
protected abstract _avatarList(): Promise<AvatarList>;
|
||||||
|
async avatarList() {
|
||||||
|
if (this._avatarListCache === undefined) {
|
||||||
|
this._avatarListCache = await this._avatarList();
|
||||||
|
}
|
||||||
|
|
||||||
|
return this._avatarListCache;
|
||||||
|
}
|
||||||
|
|
||||||
private _backgroundCache: Record<string, Background> = {};
|
private _backgroundCache: Record<string, Background> = {};
|
||||||
protected abstract _background(id: string): Promise<Background>;
|
protected abstract _background(id: string): Promise<Background>;
|
||||||
async background(id: string) {
|
async background(id: string) {
|
||||||
|
|||||||
@@ -193,6 +193,13 @@ export class ServerAPI extends AbstractAPI {
|
|||||||
return { avatars };
|
return { avatars };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected async _avatarList() {
|
||||||
|
const avatars = await this.avatars();
|
||||||
|
const list = Object.keys(avatars.avatars);
|
||||||
|
|
||||||
|
return { list };
|
||||||
|
}
|
||||||
|
|
||||||
protected async _avatar(id: string) {
|
protected async _avatar(id: string) {
|
||||||
const avatar = this.metadata.item(`ProfileAvatarEntity.${id}`);
|
const avatar = this.metadata.item(`ProfileAvatarEntity.${id}`);
|
||||||
const name = avatar.name;
|
const name = avatar.name;
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ export const getStaticPaths = (async () => {
|
|||||||
*
|
*
|
||||||
* @see avatars/list.json for all avatar ids.
|
* @see avatars/list.json for all avatar ids.
|
||||||
* @see avatars/[id].webp for avatar images.
|
* @see avatars/[id].webp for avatar images.
|
||||||
* @type avatar
|
* @type avatar.Avatar
|
||||||
*/
|
*/
|
||||||
export async function GET({ params }: APIContext<never, { id: string }>) {
|
export async function GET({ params }: APIContext<never, { id: string }>) {
|
||||||
const avatar = await api.avatar(params.id);
|
const avatar = await api.avatar(params.id);
|
||||||
|
|||||||
@@ -4,6 +4,12 @@ import { imageProxy } from "../../../core/api/imageProxy";
|
|||||||
|
|
||||||
export { getStaticPaths } from "./[id].json";
|
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<never, { id: string }>) {
|
export async function GET({ params }: APIContext<never, { id: string }>) {
|
||||||
const avatar = await api.avatar(params.id);
|
const avatar = await api.avatar(params.id);
|
||||||
return await imageProxy(avatar.profile_avatar!.avatar);
|
return await imageProxy(avatar.profile_avatar!.avatar);
|
||||||
|
|||||||
@@ -1,5 +1,11 @@
|
|||||||
import { api } from "../../../core/api/dynamic";
|
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() {
|
export async function GET() {
|
||||||
const avatars = await api.avatars();
|
const avatars = await api.avatars();
|
||||||
return Response.json(avatars);
|
return Response.json(avatars);
|
||||||
|
|||||||
@@ -1,7 +1,9 @@
|
|||||||
import { api } from "../../../core/api/dynamic";
|
import { api } from "../../../core/api/dynamic";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @type avatar_list.AvatarList
|
||||||
|
*/
|
||||||
export async function GET() {
|
export async function GET() {
|
||||||
const { avatars } = await api.avatars();
|
const list = await api.avatarList();
|
||||||
const list = avatars.map((avatar) => avatar.name);
|
|
||||||
return Response.json(list);
|
return Response.json(list);
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
syntax = "proto3";
|
||||||
|
|
||||||
|
package blitzkit;
|
||||||
|
|
||||||
|
message AvatarList {
|
||||||
|
repeated string list = 1;
|
||||||
|
}
|
||||||
Reference in new issue
Block a user