currencies

This commit is contained in:
tresabhi committed 2026-08-04 14:12:32 -05:00
1 parent 33ebbbeb65
commit 48c4a4c76d
2 files changed
+80 -62

No files matched your search

@@ -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<BlitzGlossary>)
.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();
}
@@ -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<BlitzGlossary>)
.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);
}