feat: remote catalog

This commit is contained in:
TrèsAbhi committed 2025-05-28 18:32:04 -05:00
1 parent e7386ff766
commit 5e9aa99755
17 files changed
+109 -67

No files matched your search

@@ -0,0 +1,6 @@
import { fetchMetadata } from '@blitzkit/closed';
import { CatalogAccessor } from 'packages/core/src';
export const catalog = new CatalogAccessor(
await fetchMetadata().then((data) => data.catalog_items),
).injectBlitzkit();
@@ -1,3 +0,0 @@
import { DiscreteMetadataAccessor } from 'packages/core/src';
export const discreteMetadata = new DiscreteMetadataAccessor('/api/catalog');
@@ -0,0 +1,4 @@
import { RemoteCatalogAccessor } from 'packages/core/src';
import { api } from '../blitzkit/api';
export const remoteCatalog = new RemoteCatalogAccessor(api('catalog'));
@@ -1,9 +0,0 @@
import { requestAutoProxyClient, unpackMetadata } from '@blitzkit/closed';
import type { GetPackedMetadataAsyncResponse } from '@blitzkit/closed/src/unreal/protos/auto_legacy_proxy_client';
import { UnpackedMetadataAccessor } from 'packages/core/src';
export const unpackedMetadata = new UnpackedMetadataAccessor(
await requestAutoProxyClient<GetPackedMetadataAsyncResponse>(
'GetPackedMetadataAsyncRequest',
).then(unpackMetadata),
).injectBlitzkit();
@@ -0,0 +1,11 @@
let base: string;
if (import.meta.env.DEV) {
base = 'http://localhost:4321';
} else {
base = import.meta.env.SITE;
}
export function api(path: string) {
return `${base}/api/${path}`;
}
@@ -0,0 +1,20 @@
import { TankCatalogComponent } from '@protos/blitz_static_tank_component';
import { BlitzkitAllTanksComponent } from '@protos/blitzkit_static_all_tanks_component';
import { CatalogAccessor } from 'packages/core/src';
import { remoteCatalog } from 'packages/website-ue/src/core/blitz/remoteCatalog';
const data = await remoteCatalog
.get('BlitzKitAllTanksEntity.blitzkit_all_tanks')
.then((components) =>
components.get(BlitzkitAllTanksComponent, 'blitzkitAllTanksComponent'),
);
export function Page() {
const tankCatalog = new CatalogAccessor(data.tanks);
const content = tankCatalog
.get('TankEntity.A92_M60')
.get(TankCatalogComponent, 'tankCatalogComponent');
return <pre children={JSON.stringify(content, null, 2)} />;
}
@@ -1,23 +1,9 @@
---
import { CatalogItemsComponent } from '@protos/blitz_static_catalog_items_group_component';
import { BlitzKitAllTankEntities } from '@protos/blitzkit_static_all_tank_entities';
import { unpackedMetadata } from '../../../core/blitz/unpackedMetadata';
import { Page } from './_index';
export { getStaticPaths } from '../index.astro';
const { locale } = Astro.props;
const allTanks = unpackedMetadata
.get('CatalogItemsGroupEntity.all_tanks')
.get(CatalogItemsComponent, 'catalogItemsGroupComponent');
const allTankEntities = unpackedMetadata
.get('BlitzKitAllTankEntities.all_tanks')
.get(BlitzKitAllTankEntities, 'blitzkitAllTankEntitiesComponent');
---
<pre>
{JSON.stringify(allTankEntities.tanks.map(tank=>({
tank: tank.catalog_id,
components: tank.components.map(component=>component.key)
})), null, 2)}
</pre>
<Page client:load />
@@ -0,0 +1,18 @@
import type { APIRoute, GetStaticPaths, GetStaticPathsItem } from 'astro';
import { catalog } from 'packages/website-ue/src/core/blitz/catalog';
export const getStaticPaths: GetStaticPaths = () => {
const paths: GetStaticPathsItem[] = [];
for (const item in catalog.items) {
paths.push({ params: { item } });
}
return paths;
};
export const GET: APIRoute<{}, { item: string }> = ({ params }) => {
return new Response(catalog.get(params.item).encode(), {
headers: { 'Content-Type': 'application/octet-stream' },
});
};