mirror of
https://github.com/blitzkit/blitzkit.git
synced 2026-10-23 19:49:50 +02:00
feat: some more apis
This commit is contained in:
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 "@radix-ui/colors/amber-dark.css";
|
||||||
|
import {
|
||||||
|
createProgram,
|
||||||
|
displayPartsToString,
|
||||||
|
forEachChild,
|
||||||
|
isFunctionDeclaration,
|
||||||
|
} from "typescript";
|
||||||
import BaseLayout from "../../../layouts/BaseLayout.astro";
|
import BaseLayout from "../../../layouts/BaseLayout.astro";
|
||||||
|
|
||||||
export { getStaticPaths } from "../index.astro";
|
export { getStaticPaths } from "../index.astro";
|
||||||
@@ -15,38 +21,26 @@ const paths: {
|
|||||||
documentation: string;
|
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) {
|
for (const fullPath in globbed) {
|
||||||
if (!fullPath.endsWith(".ts")) continue;
|
const relativePath = `.${fullPath}`;
|
||||||
|
|
||||||
const mdPath = fullPath.replace(".ts", ".md");
|
|
||||||
const documentation = globbed[mdPath] as string;
|
|
||||||
|
|
||||||
if (!documentation) continue;
|
|
||||||
|
|
||||||
const path = fullPath.slice(root.length + 1, -3);
|
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 });
|
paths.push({ path, documentation });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -4,9 +4,6 @@ import { imageProxy } from "../../../core/api/imageProxy";
|
|||||||
|
|
||||||
export { getStaticPaths } from "./[id].json";
|
export { getStaticPaths } from "./[id].json";
|
||||||
|
|
||||||
/**
|
|
||||||
* One day I will write documentation for this
|
|
||||||
*/
|
|
||||||
export async function GET({ params }: APIContext<never, { id: string }>) {
|
export async function GET({ params }: APIContext<never, { id: string }>) {
|
||||||
const background = await api.background(params.id);
|
const background = await api.background(params.id);
|
||||||
return await imageProxy(background.profile_background!.background);
|
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 { Nation } from "@protos/blitz_static_tank_component";
|
||||||
import type { APIContext, GetStaticPaths } from "astro";
|
import type { APIContext, GetStaticPaths } from "astro";
|
||||||
import { GunType } from "../../../core/tankopedia/characteristics";
|
import { GunType } from "../../../core/tankopedia/characteristics";
|
||||||
|
import { GET as _GET } from "./all.json";
|
||||||
|
|
||||||
const enums = {
|
export const ENUMS = {
|
||||||
nation: Nation,
|
nation: Nation,
|
||||||
"tank-class": TankClass,
|
"tank-class": TankClass,
|
||||||
"tank-type": TankType,
|
"tank-type": TankType,
|
||||||
@@ -11,29 +12,12 @@ const enums = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
export const getStaticPaths = (() => {
|
export const getStaticPaths = (() => {
|
||||||
return Object.keys(enums).map((name) => ({ params: { enum: name } }));
|
return Object.keys(ENUMS).map((name) => ({ params: { enum: name } }));
|
||||||
}) satisfies GetStaticPaths;
|
}) satisfies GetStaticPaths;
|
||||||
|
|
||||||
/**
|
export async function GET({
|
||||||
* 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({
|
|
||||||
params,
|
params,
|
||||||
}: APIContext<never, { enum: keyof typeof enums }>) {
|
}: APIContext<never, { enum: keyof typeof ENUMS }>) {
|
||||||
const map: Record<number, string> = {};
|
const enums = (await _GET().json()) as Record<string, Record<number, string>>;
|
||||||
|
return Response.json(enums[params.enum]);
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
@@ -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);
|
||||||
|
}
|
||||||
Reference in new issue
Block a user