Files
blitzkit/packages/website/src/pages/[...chunk_api]/flags/fade/[id].webp.ts
T

39 lines
1.1 KiB
TypeScript
Raw Normal View History

import sharp from "sharp";
2026-08-04 20:23:50 -05:00
import type { APIContext, GetStaticPathsItem } from "astro";
2026-08-06 20:10:29 -05:00
import { mixStaticPaths } from "../../../../core/blitzkit/mixStaticPaths";
import { vfs } from "../../../../core/blitzkit/vfs";
import { getStaticPaths as _getStaticPaths } from "../../_index";
2026-08-04 20:23:50 -05:00
export const getStaticPaths = mixStaticPaths(_getStaticPaths, async () => {
const paths: GetStaticPathsItem[] = [];
const fadedFiles = await vfs
.dir(`Data/Gfx/Lobby/flags`)
.then((files) =>
files.filter(
(flag) =>
flag.startsWith("flag_filter_") && flag.endsWith("@2x.packed.webp"),
),
);
for (const flag of fadedFiles) {
const path = `Data/Gfx/Lobby/flags/${flag}`;
const id = flag.match(/flag_filter_(.+)@2x\.packed\.webp/)![1];
paths.push({
params: { id },
props: { path },
});
}
return paths;
});
export async function GET({ props }: APIContext<{ path: string }>) {
const bytes = await sharp(new Uint8Array(await vfs.file(props.path)))
.trim({ background: { r: 0, g: 0, b: 0, alpha: 0 }, threshold: 1 })
.webp()
.toBuffer();
2026-08-04 20:23:50 -05:00
return new Response(new Uint8Array(bytes));
2026-08-04 20:23:50 -05:00
}