feat: some more apis

This commit is contained in:
tresabhi committed 2025-03-18 23:53:52 -05:00
1 parent 4b5ee9db09
commit 8d4933dd60
11 files changed
+108 -120

No files matched your search

+1
View File
@@ -48,4 +48,5 @@ export * from './metaSortTank';
export * from './romanize'; export * from './romanize';
export * from './tank'; export * from './tank';
export * from './tanks'; export * from './tanks';
export * from './tanksFull';
export * from './youtubers'; export * from './youtubers';
+7
View File
@@ -0,0 +1,7 @@
import { fetchPB } from '../protobuf';
import { TanksFull } from '../protos';
import { asset } from './asset';
export function fetchTanksFull() {
return fetchPB(asset('definitions/tanks-full.pb'), TanksFull);
}
+1 -1
View File
@@ -18,7 +18,7 @@ export interface I18n_LocalesEntry {
value: string; value: string;
} }
function createBaseI18n(): I18n { export function createBaseI18n(): I18n {
return { locales: {} }; return { locales: {} };
} }
+1 -1
View File
@@ -6,7 +6,7 @@
/* eslint-disable */ /* eslint-disable */
import { BinaryReader, BinaryWriter } from "@bufbuild/protobuf/wire"; import { BinaryReader, BinaryWriter } from "@bufbuild/protobuf/wire";
import { I18n } from "./i18n"; import { I18n, createBaseI18n } from "./i18n";
export const protobufPackage = "blitzkit"; export const protobufPackage = "blitzkit";
+1 -1
View File
@@ -138,7 +138,7 @@ export const apiTool: Tool = {
button: { button: {
color: 'indigo', color: 'indigo',
}, },
image: '0bWE5hC', image: 'dIfvWnV',
}; };
export const TOOLS: Tool[] = [ export const TOOLS: Tool[] = [
@@ -1,5 +1,5 @@
--- ---
import { Code, Flex, Heading, Link } from '@radix-ui/themes'; import { Code, Flex, Heading, Separator } from '@radix-ui/themes';
import { PageWrapper } from '../../../components/PageWrapper'; import { PageWrapper } from '../../../components/PageWrapper';
import { apiTool } from '../../../constants/tools'; import { apiTool } from '../../../constants/tools';
import ToolLayout from '../../../layouts/ToolLayout.astro'; import ToolLayout from '../../../layouts/ToolLayout.astro';
@@ -12,7 +12,7 @@ interface Tag {
description?: string; description?: string;
} }
const getDocsRegex = /\/\*\*\n(( \*(.+)?\n?)+)\n \*\/\nexport const GET/gm; const getDocsRegex = /\/\*\*\n(( \*(.+)?\n?)+)\n \*\/\nexport const GET/;
const multiLineCommentPrefixRegex = /^ \* ?/gm; const multiLineCommentPrefixRegex = /^ \* ?/gm;
const tagRegex = /(@[^\s]+)(?:\s(.+))?/; const tagRegex = /(@[^\s]+)(?:\s(.+))?/;
const firstWordRegex = /(\S+)(?:\s(.+))?/; const firstWordRegex = /(\S+)(?:\s(.+))?/;
@@ -22,7 +22,7 @@ const glob = import.meta.glob('/src/pages/api/**/*.ts', {
query: '?raw', query: '?raw',
import: 'default', import: 'default',
}); });
const apis: { let apis: {
path: string; path: string;
content: string; content: string;
comment: string; comment: string;
@@ -31,7 +31,7 @@ const apis: {
for (const rawPath in glob) { for (const rawPath in glob) {
const content = (glob[rawPath] as string).replaceAll('\r', ''); const content = (glob[rawPath] as string).replaceAll('\r', '');
const regexExecution = getDocsRegex.exec(content); const regexExecution = content.match(getDocsRegex);
const commentRaw = regexExecution?.[1]; const commentRaw = regexExecution?.[1];
if (!commentRaw) continue; if (!commentRaw) continue;
@@ -45,7 +45,7 @@ for (const rawPath in glob) {
const tags: Tag[] = []; const tags: Tag[] = [];
commentWithTags.split('\n').forEach((line) => { commentWithTags.split('\n').forEach((line) => {
const match = tagRegex.exec(line); const match = line.match(tagRegex);
if (match) { if (match) {
const tag = match[1]; const tag = match[1];
@@ -54,7 +54,7 @@ for (const rawPath in glob) {
let description: string | undefined; let description: string | undefined;
if (tag === '@param') { if (tag === '@param') {
const firstWordMatch = firstWordRegex.exec(descriptionRaw)!; const firstWordMatch = descriptionRaw.match(firstWordRegex)!;
discriminator = firstWordMatch[1]; discriminator = firstWordMatch[1];
description = firstWordMatch[2]; description = firstWordMatch[2];
} else { } else {
@@ -75,53 +75,63 @@ for (const rawPath in glob) {
apis.push({ path, content, comment, tags }); apis.push({ path, content, comment, tags });
} }
apis.sort((a, b) => a.path.localeCompare(b.path));
--- ---
<ToolLayout tool={apiTool}> <ToolLayout tool={apiTool}>
<PageWrapper py="9"> <PageWrapper py="9">
{ <Flex direction="column" gap="6">
apis.map((api) => ( {
<Flex direction="column" gap="5"> apis.map((api, index) => (
<Link href={api.path}> <>
<Heading> <Flex direction="column" gap="5">
<Code variant="ghost">{api.path}</Code> <Heading>
</Heading> <Code variant="ghost" color="iris" highContrast>
</Link> {api.path}
</Code>
</Heading>
<Code <Code
color="gray" color="gray"
variant="ghost" variant="ghost"
highContrast highContrast
style={{ whiteSpace: 'pre-wrap' }} style={{ whiteSpace: 'pre-wrap' }}
> >
{api.comment} {api.comment}
</Code> </Code>
{api.tags.length > 0 && ( {api.tags.length > 0 && (
<Flex direction="column" gap="2"> <Flex direction="column" gap="2">
{api.tags.map(({ tag, description, discriminator }) => ( {api.tags.map(({ tag, description, discriminator }) => (
<Flex gap="2" align="center"> <Flex gap="2">
<Code color="ruby" variant="solid"> <Code color="iris" variant="solid">
{tag} {tag}
</Code> </Code>
{discriminator && ( {discriminator && (
<Code color="gray" variant="solid" highContrast> <Code color="gray" variant="solid" highContrast>
{discriminator} {discriminator}
</Code> </Code>
)} )}
{description && ( {description && (
<Code color="gray" variant="ghost"> <Code mt="calc(1em / 8)" color="gray" variant="ghost">
{description} {description}
</Code> </Code>
)} )}
</Flex>
))}
</Flex> </Flex>
))} )}
</Flex> </Flex>
)}
</Flex> {index < apis.length - 1 && (
)) <Separator size="4" style={{ height: 0.5 }} />
} )}
</>
))
}
</Flex>
</PageWrapper> </PageWrapper>
</ToolLayout> </ToolLayout>
@@ -1,43 +0,0 @@
import { TankSandbox } from '../../../../../components/Tankopedia/HeroSection/components/TankSandbox';
import { awaitableModelDefinitions } from '../../../../../core/awaitables/modelDefinitions';
import { awaitableProvisionDefinitions } from '../../../../../core/awaitables/provisionDefinitions';
import { awaitableTankDefinitions } from '../../../../../core/awaitables/tankDefinitions';
import { LocaleProvider } from '../../../../../hooks/useLocale';
import { App } from '../../../../../stores/app';
import { Duel } from '../../../../../stores/duel';
import { TankopediaEphemeral } from '../../../../../stores/tankopediaEphemeral';
import { TankopediaPersistent } from '../../../../../stores/tankopediaPersistent';
const [provisionDefinitions, tankDefinitions, modelDefinitions] =
await Promise.all([
awaitableProvisionDefinitions,
awaitableTankDefinitions,
awaitableModelDefinitions,
]);
interface PageProps {
id: number;
}
export function Page({ id }: PageProps) {
const tank = tankDefinitions.tanks[id];
const model = modelDefinitions.models[id];
return (
<LocaleProvider locale="en">
<App.Provider>
<TankopediaPersistent.Provider>
<Duel.Provider data={{ provisionDefinitions, tank }}>
<TankopediaEphemeral.Provider data={model}>
<Content />
</TankopediaEphemeral.Provider>
</Duel.Provider>
</TankopediaPersistent.Provider>
</App.Provider>
</LocaleProvider>
);
}
function Content() {
return <TankSandbox naked thicknessRange={{ value: 0 }} />;
}
@@ -1,30 +0,0 @@
---
import { assertSecret } from '@blitzkit/core';
import type { GetStaticPaths } from 'astro';
import { getStaticPaths as tankopediaGetStaticPaths } from '../../../../[...locale]/tools/tankopedia/[id]/index.astro';
import { Page } from './_index';
export const getStaticPaths = (async () => {
if (assertSecret(import.meta.env.MODE) === 'development') {
return await tankopediaGetStaticPaths();
} else {
return [];
}
}) satisfies GetStaticPaths;
const { id } = Astro.params;
---
<html>
<head>
<style is:global>
body {
margin: 0;
}
</style>
</head>
<body>
<Page {id} client:load />
</body>
</html>
@@ -0,0 +1,18 @@
import { fetchTank, fetchTanks } from '@blitzkit/core';
import type { APIRoute, GetStaticPaths } from 'astro';
export const getStaticPaths = (async () => {
const tanks = await fetchTanks();
return tanks.tanks.map((id) => ({ params: { id } }));
}) satisfies GetStaticPaths;
/**
* Returns the meta data on a tank which includes its modules, characteristics, ancestry, descendants, equipment, characteristics, etc. However, this does not include information on the tank model.
*
* @param avatar The avatar id.
* @returns A webp image.
*/
export const GET: APIRoute<{}, { id: string }> = async ({ params }) => {
const tank = await fetchTank(params.id);
return Response.json(tank);
};
@@ -0,0 +1,13 @@
import { fetchTanksFull } from '@blitzkit/core';
import type { APIRoute } from 'astro';
/**
* Returns meta data similar to tanks/[id].json but for all tanks as an array. There is no guarantee of order.
*
* @warning This is a large response. Consider using tanks/[id].json for individual tanks.
* @returns JSON.
*/
export const GET: APIRoute = async () => {
const tanksFull = await fetchTanksFull();
return Response.json(tanksFull.tanks);
};
@@ -0,0 +1,12 @@
import { fetchTanks } from '@blitzkit/core';
import type { APIRoute } from 'astro';
/**
* Returns a list of all tank ids. There is no guarantee of order.
*
* @returns JSON.
*/
export const GET: APIRoute = async () => {
const tanks = await fetchTanks();
return Response.json(tanks.tanks);
};