From 48c4a4c76df60b1c244c4b0971488892e5268400 Mon Sep 17 00:00:00 2001 From: tresabhi <43380238+tresabhi@users.noreply.github.com> Date: Tue, 4 Aug 2026 14:12:32 -0500 Subject: [PATCH] currencies --- .../scripts/src/buildAssets/currencies.ts | 62 -------------- .../icons/currencies/[id].webp.ts | 80 +++++++++++++++++++ 2 files changed, 80 insertions(+), 62 deletions(-) delete mode 100644 packages/scripts/src/buildAssets/currencies.ts create mode 100644 packages/website/src/pages/[...chunk_api]/icons/currencies/[id].webp.ts diff --git a/packages/scripts/src/buildAssets/currencies.ts b/packages/scripts/src/buildAssets/currencies.ts deleted file mode 100644 index 78d10ede1..000000000 --- a/packages/scripts/src/buildAssets/currencies.ts +++ /dev/null @@ -1,62 +0,0 @@ -import { assertSecret, BlitzGlossary } from "@blitzkit/core"; -import sharp from "sharp"; -import { AssetUploader } from "../core/github/assetUploader"; -import { vfs } from "./constants"; - -const ICONS = [ - ["currency_silver_m.packed.webp", "silver"], - ["currency_premium_xl.packed.webp", "premium"], - ["currency_gold_m.packed.webp", "gold"], - ["currency_free-xp_xl.packed.webp", "free-xp"], - ["currency_elite-xp_xl.packed.webp", "elite-xp"], - ["currency_crew-xp_xl.packed.webp", "crew-xp"], - ["currency_battle-xp_xl.packed.webp", "xp"], -]; - -export async function currencies() { - console.log("Building currency icons..."); - - using uploader = new AssetUploader("currency icons"); - - for (const [file, name] of ICONS) { - const content = await sharp( - await vfs.file(`Data/Gfx/Lobby/currency/${file}`), - ) - .trim() - .toBuffer(); - - await uploader.add({ - content, - path: `icons/currencies/${name}.webp`, - }); - } - - const glossary = await fetch(assertSecret(import.meta.env.WOTB_GLOSSARY)) - .then((response) => response.json() as Promise) - .then((glossary) => - Object.values(glossary) - .entries() - .filter(([key]) => /^prx_season_\d+$/.test(`${key}`)), - ); - - for (const [key, item] of glossary) { - if (item.image_url === null) throw new Error(`No image_url for ${key}`); - - const imageRaw = await fetch(item.image_url).then((response) => - response.arrayBuffer(), - ); - const content = await sharp(imageRaw) - .trim({ - threshold: 100, - background: { r: 0, g: 0, b: 0, alpha: 0 }, - }) - .toBuffer(); - - await uploader.add({ - content, - path: `icons/currencies/${key}.webp`, - }); - } - - await uploader.flush(); -} diff --git a/packages/website/src/pages/[...chunk_api]/icons/currencies/[id].webp.ts b/packages/website/src/pages/[...chunk_api]/icons/currencies/[id].webp.ts new file mode 100644 index 000000000..f6581c798 --- /dev/null +++ b/packages/website/src/pages/[...chunk_api]/icons/currencies/[id].webp.ts @@ -0,0 +1,80 @@ +import { assertSecret, type BlitzGlossary } from "@blitzkit/core"; +import type { APIContext, GetStaticPathsItem } from "astro"; +import sharp from "sharp"; +import { mixStaticPaths } from "../../../../core/blitzkit/mixStaticPaths"; +import { vfs } from "../../../../core/blitzkit/vfs"; +import { getStaticPaths as _getStaticPaths } from "../../_index"; + +const ICONS = [ + ["currency_silver_m.packed.webp", "silver"], + ["currency_premium_xl.packed.webp", "premium"], + ["currency_gold_m.packed.webp", "gold"], + ["currency_free-xp_xl.packed.webp", "free-xp"], + ["currency_elite-xp_xl.packed.webp", "elite-xp"], + ["currency_crew-xp_xl.packed.webp", "crew-xp"], + ["currency_battle-xp_xl.packed.webp", "xp"], +]; + +export const getStaticPaths = mixStaticPaths(_getStaticPaths, async () => { + const paths: GetStaticPathsItem[] = []; + + console.log("Building currency icons..."); + + for (const [file, id] of ICONS) { + paths.push({ + params: { id }, + props: { + local: true, + source: `Data/Gfx/Lobby/currency/${file}`, + }, + }); + } + + const glossary = await fetch(assertSecret(import.meta.env.WOTB_GLOSSARY)) + .then((response) => response.json() as Promise) + .then((glossary) => + Object.values(glossary) + .entries() + .filter(([key]) => /^prx_season_\d+$/.test(`${key}`)), + ); + + for (const [id, item] of glossary) { + if (!item.image_url) continue; + + paths.push({ + params: { id }, + props: { + local: false, + source: item.image_url, + }, + }); + } + + return paths; +}); + +export async function GET({ + props, +}: APIContext<{ local: boolean; source: string }>) { + let buffer: Buffer; + + if (props.local) { + buffer = await sharp(await vfs.file(props.source)) + .trim() + .toBuffer(); + } else { + const imageRaw = await fetch(props.source).then((response) => + response.arrayBuffer(), + ); + buffer = await sharp(imageRaw) + .trim({ + threshold: 100, + background: { r: 0, g: 0, b: 0, alpha: 0 }, + }) + .toBuffer(); + } + + const bytes = new Uint8Array(buffer); + + return new Response(bytes); +}