feat: mirros

This commit is contained in:
tresabhi committed 2025-04-01 15:32:37 -05:00
1 parent cb03a86cce
commit 8087752172
11 files changed
+193 -93

No files matched your search

@@ -1,3 +1,6 @@
import { fetchPB, type MessageFns } from '@blitzkit/core';
import type { APIRoute } from 'astro';
export async function blobMirror(url: string) {
if (import.meta.env.MODE === 'development') {
return Response.redirect(url);
@@ -7,3 +10,17 @@ export async function blobMirror(url: string) {
return new Response(blob, { headers: response.headers });
}
}
export function apiMirror(path: string) {
const get: APIRoute = () => blobMirror(`http://localhost:5000${path}`);
return get;
}
export function jsonMirror<Type>(path: string, message: MessageFns<Type>) {
const get: APIRoute = async () => {
return new Response(
JSON.stringify(await fetchPB(`http://localhost:5000${path}`, message)),
);
};
return get;
}
@@ -1,13 +1,10 @@
import { fetchTanksFull } from '@blitzkit/core';
import type { APIRoute } from 'astro';
import { TanksFull } from '@blitzkit/core';
import { jsonMirror } from '../../../core/blitzkit/blobMirror';
/**
* Returns meta data similar to tanks/[id].json but for all tanks as an array. There is no guarantee of order.
* Identical to tanks/full.pb but in JSON.
*
* @warning This is a large response. Consider using tanks/[id]/meta.json for individual tanks.
* @returns JSON.
*/
export const GET: APIRoute = async () => {
const tanksFull = await fetchTanksFull();
return Response.json(tanksFull.tanks);
};
export const GET = jsonMirror('/tanks/full.pb', TanksFull);
@@ -0,0 +1,8 @@
import { apiMirror } from '../../../core/blitzkit/blobMirror';
/**
* Returns meta data similar to tanks/[id].json but for all tanks as an array. There is no guarantee of order.
*
* @proto TanksFull
*/
export const GET = apiMirror('/tanks/full.pb');
@@ -1,12 +1,9 @@
import { fetchTanks } from '@blitzkit/core';
import type { APIRoute } from 'astro';
import { Tanks } from '@blitzkit/core';
import { jsonMirror } from '../../../core/blitzkit/blobMirror';
/**
* Returns a list of all tank ids. There is no guarantee of order.
* Identical to tanks/list.pb but in JSON.
*
* @returns JSON.
*/
export const GET: APIRoute = async () => {
const tanks = await fetchTanks();
return Response.json(tanks.tanks);
};
export const GET = jsonMirror('/tanks/list.pb', Tanks);
@@ -0,0 +1,8 @@
import { apiMirror } from '../../../core/blitzkit/blobMirror';
/**
* Returns a list of all tank ids. There is no guarantee of order.
*
* @returns JSON.
*/
export const GET = apiMirror('/tanks/list.pb');