mirror of
https://github.com/blitzkit/blitzkit.git
synced 2026-10-21 18:57:03 +02:00
feat: some more apis
This commit is contained in:
1 parent
4b5ee9db09
commit
8d4933dd60
11 files changed
+108
-120
No files matched your search
@@ -48,4 +48,5 @@ export * from './metaSortTank';
|
||||
export * from './romanize';
|
||||
export * from './tank';
|
||||
export * from './tanks';
|
||||
export * from './tanksFull';
|
||||
export * from './youtubers';
|
||||
@@ -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);
|
||||
}
|
||||
@@ -18,7 +18,7 @@ export interface I18n_LocalesEntry {
|
||||
value: string;
|
||||
}
|
||||
|
||||
function createBaseI18n(): I18n {
|
||||
export function createBaseI18n(): I18n {
|
||||
return { locales: {} };
|
||||
}
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
|
||||
/* eslint-disable */
|
||||
import { BinaryReader, BinaryWriter } from "@bufbuild/protobuf/wire";
|
||||
import { I18n } from "./i18n";
|
||||
import { I18n, createBaseI18n } from "./i18n";
|
||||
|
||||
export const protobufPackage = "blitzkit";
|
||||
|
||||
|
||||
@@ -138,7 +138,7 @@ export const apiTool: Tool = {
|
||||
button: {
|
||||
color: 'indigo',
|
||||
},
|
||||
image: '0bWE5hC',
|
||||
image: 'dIfvWnV',
|
||||
};
|
||||
|
||||
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 { apiTool } from '../../../constants/tools';
|
||||
import ToolLayout from '../../../layouts/ToolLayout.astro';
|
||||
@@ -12,7 +12,7 @@ interface Tag {
|
||||
description?: string;
|
||||
}
|
||||
|
||||
const getDocsRegex = /\/\*\*\n(( \*(.+)?\n?)+)\n \*\/\nexport const GET/gm;
|
||||
const getDocsRegex = /\/\*\*\n(( \*(.+)?\n?)+)\n \*\/\nexport const GET/;
|
||||
const multiLineCommentPrefixRegex = /^ \* ?/gm;
|
||||
const tagRegex = /(@[^\s]+)(?:\s(.+))?/;
|
||||
const firstWordRegex = /(\S+)(?:\s(.+))?/;
|
||||
@@ -22,7 +22,7 @@ const glob = import.meta.glob('/src/pages/api/**/*.ts', {
|
||||
query: '?raw',
|
||||
import: 'default',
|
||||
});
|
||||
const apis: {
|
||||
let apis: {
|
||||
path: string;
|
||||
content: string;
|
||||
comment: string;
|
||||
@@ -31,7 +31,7 @@ const apis: {
|
||||
|
||||
for (const rawPath in glob) {
|
||||
const content = (glob[rawPath] as string).replaceAll('\r', '');
|
||||
const regexExecution = getDocsRegex.exec(content);
|
||||
const regexExecution = content.match(getDocsRegex);
|
||||
const commentRaw = regexExecution?.[1];
|
||||
|
||||
if (!commentRaw) continue;
|
||||
@@ -45,7 +45,7 @@ for (const rawPath in glob) {
|
||||
|
||||
const tags: Tag[] = [];
|
||||
commentWithTags.split('\n').forEach((line) => {
|
||||
const match = tagRegex.exec(line);
|
||||
const match = line.match(tagRegex);
|
||||
|
||||
if (match) {
|
||||
const tag = match[1];
|
||||
@@ -54,7 +54,7 @@ for (const rawPath in glob) {
|
||||
let description: string | undefined;
|
||||
|
||||
if (tag === '@param') {
|
||||
const firstWordMatch = firstWordRegex.exec(descriptionRaw)!;
|
||||
const firstWordMatch = descriptionRaw.match(firstWordRegex)!;
|
||||
discriminator = firstWordMatch[1];
|
||||
description = firstWordMatch[2];
|
||||
} else {
|
||||
@@ -75,53 +75,63 @@ for (const rawPath in glob) {
|
||||
|
||||
apis.push({ path, content, comment, tags });
|
||||
}
|
||||
|
||||
apis.sort((a, b) => a.path.localeCompare(b.path));
|
||||
---
|
||||
|
||||
<ToolLayout tool={apiTool}>
|
||||
<PageWrapper py="9">
|
||||
{
|
||||
apis.map((api) => (
|
||||
<Flex direction="column" gap="5">
|
||||
<Link href={api.path}>
|
||||
<Heading>
|
||||
<Code variant="ghost">{api.path}</Code>
|
||||
</Heading>
|
||||
</Link>
|
||||
<Flex direction="column" gap="6">
|
||||
{
|
||||
apis.map((api, index) => (
|
||||
<>
|
||||
<Flex direction="column" gap="5">
|
||||
<Heading>
|
||||
<Code variant="ghost" color="iris" highContrast>
|
||||
{api.path}
|
||||
</Code>
|
||||
</Heading>
|
||||
|
||||
<Code
|
||||
color="gray"
|
||||
variant="ghost"
|
||||
highContrast
|
||||
style={{ whiteSpace: 'pre-wrap' }}
|
||||
>
|
||||
{api.comment}
|
||||
</Code>
|
||||
<Code
|
||||
color="gray"
|
||||
variant="ghost"
|
||||
highContrast
|
||||
style={{ whiteSpace: 'pre-wrap' }}
|
||||
>
|
||||
{api.comment}
|
||||
</Code>
|
||||
|
||||
{api.tags.length > 0 && (
|
||||
<Flex direction="column" gap="2">
|
||||
{api.tags.map(({ tag, description, discriminator }) => (
|
||||
<Flex gap="2" align="center">
|
||||
<Code color="ruby" variant="solid">
|
||||
{tag}
|
||||
</Code>
|
||||
{api.tags.length > 0 && (
|
||||
<Flex direction="column" gap="2">
|
||||
{api.tags.map(({ tag, description, discriminator }) => (
|
||||
<Flex gap="2">
|
||||
<Code color="iris" variant="solid">
|
||||
{tag}
|
||||
</Code>
|
||||
|
||||
{discriminator && (
|
||||
<Code color="gray" variant="solid" highContrast>
|
||||
{discriminator}
|
||||
</Code>
|
||||
)}
|
||||
{discriminator && (
|
||||
<Code color="gray" variant="solid" highContrast>
|
||||
{discriminator}
|
||||
</Code>
|
||||
)}
|
||||
|
||||
{description && (
|
||||
<Code color="gray" variant="ghost">
|
||||
{description}
|
||||
</Code>
|
||||
)}
|
||||
{description && (
|
||||
<Code mt="calc(1em / 8)" color="gray" variant="ghost">
|
||||
{description}
|
||||
</Code>
|
||||
)}
|
||||
</Flex>
|
||||
))}
|
||||
</Flex>
|
||||
))}
|
||||
)}
|
||||
</Flex>
|
||||
)}
|
||||
</Flex>
|
||||
))
|
||||
}
|
||||
|
||||
{index < apis.length - 1 && (
|
||||
<Separator size="4" style={{ height: 0.5 }} />
|
||||
)}
|
||||
</>
|
||||
))
|
||||
}
|
||||
</Flex>
|
||||
</PageWrapper>
|
||||
</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);
|
||||
};
|
||||
Reference in new issue
Block a user