feat: some more apis

This commit is contained in:
TrèsAbhi committed 2026-01-12 13:20:08 -06:00
1 parent 5a1a0c59f1
commit fae1a89402
5 files changed
+57 -56

No files matched your search

@@ -1,5 +1,11 @@
---
import "@radix-ui/colors/amber-dark.css";
import {
createProgram,
displayPartsToString,
forEachChild,
isFunctionDeclaration,
} from "typescript";
import BaseLayout from "../../../layouts/BaseLayout.astro";
export { getStaticPaths } from "../index.astro";
@@ -15,38 +21,26 @@ const paths: {
documentation: string;
}[] = [];
// for (const fullPath in globbed) {
// const relativePath = `.${fullPath}`;
// const path = fullPath.slice(root.length + 1, -3);
// const program = createProgram([relativePath], {});
// const source = program.getSourceFile(relativePath);
// if (!source) throw new Error(`Could not find source for ${fullPath}`);
// const checker = program.getTypeChecker();
// const getter = forEachChild(source, (node) => {
// if (!isFunctionDeclaration(node) || node.name?.text !== "GET") return;
// return checker.getSymbolAtLocation(node.name);
// });
// const documentationComment = getter?.getDocumentationComment(checker);
// if (!documentationComment) continue;
// const documentation = displayPartsToString(documentationComment);
// if (documentation.length === 0) continue;
// paths.push({ path, documentation });
// }
for (const fullPath in globbed) {
if (!fullPath.endsWith(".ts")) continue;
const mdPath = fullPath.replace(".ts", ".md");
const documentation = globbed[mdPath] as string;
if (!documentation) continue;
const relativePath = `.${fullPath}`;
const path = fullPath.slice(root.length + 1, -3);
const program = createProgram([relativePath], {});
const source = program.getSourceFile(relativePath);
if (!source) throw new Error(`Could not find source for ${fullPath}`);
const checker = program.getTypeChecker();
const getter = forEachChild(source, (node) => {
if (!isFunctionDeclaration(node) || node.name?.text !== "GET") return;
return checker.getSymbolAtLocation(node.name);
});
const documentationComment = getter?.getDocumentationComment(checker);
if (!documentationComment) continue;
const documentation = displayPartsToString(documentationComment);
if (documentation.length === 0) continue;
paths.push({ path, documentation });
}
@@ -4,9 +4,6 @@ import { imageProxy } from "../../../core/api/imageProxy";
export { getStaticPaths } from "./[id].json";
/**
* One day I will write documentation for this
*/
export async function GET({ params }: APIContext<never, { id: string }>) {
const background = await api.background(params.id);
return await imageProxy(background.profile_background!.background);
@@ -2,8 +2,9 @@ import { TankClass, TankType } from "@blitzkit/core";
import { Nation } from "@protos/blitz_static_tank_component";
import type { APIContext, GetStaticPaths } from "astro";
import { GunType } from "../../../core/tankopedia/characteristics";
import { GET as _GET } from "./all.json";
const enums = {
export const ENUMS = {
nation: Nation,
"tank-class": TankClass,
"tank-type": TankType,
@@ -11,29 +12,12 @@ const enums = {
};
export const getStaticPaths = (() => {
return Object.keys(enums).map((name) => ({ params: { enum: name } }));
return Object.keys(ENUMS).map((name) => ({ params: { enum: name } }));
}) satisfies GetStaticPaths;
/**
* Enumerations used within BlitzKit, for nominal development reference only.
*
* DO NOT programmatically use this API as it is designed solely for human
* reference.
*
* DO NOT blindly copy entries as naming conventions vary. Most enums come
* directly from the game which uses a SCREAMING_SNAKE_CASE convention while
* BlitzKit uses PascalCase.
*/
export function GET({
export async function GET({
params,
}: APIContext<never, { enum: keyof typeof enums }>) {
const map: Record<number, string> = {};
for (const key in enums[params.enum]) {
const value = enums[params.enum][key];
if (typeof value !== "string") continue;
map[key] = value;
}
return Response.json(map);
}: APIContext<never, { enum: keyof typeof ENUMS }>) {
const enums = (await _GET().json()) as Record<string, Record<number, string>>;
return Response.json(enums[params.enum]);
}
@@ -0,0 +1,20 @@
import { ENUMS } from "./[enum].json";
export function GET() {
const enums: Record<string, Record<number, string>> = {};
for (const name in ENUMS) {
const _enum = ENUMS[name as keyof typeof ENUMS];
const map: Record<number, string> = {};
for (const key in _enum) {
const value = _enum[key];
if (typeof value !== "string") continue;
map[key] = value;
}
enums[name] = map;
}
return Response.json(enums);
}
@@ -0,0 +1,6 @@
import { ENUMS } from "./[enum].json";
export function GET() {
const list = Object.keys(ENUMS);
return Response.json(list);
}