feat: migrate to asset uploader

This commit is contained in:
TrèsAbhi committed 2025-10-23 21:22:21 -05:00
1 parent 797307fb81
commit a3bb023309
29 files changed
+764 -1003

No files matched your search

+49 -52
View File
@@ -1,66 +1,63 @@
import { assertSecret, BlitzGlossary } from '@blitzkit/core';
import sharp from 'sharp';
import { readDVPLFile } from '../../src/core/blitz/readDVPLFile';
import { commitAssets } from '../core/github/commitAssets';
import { FileChange } from '../core/github/commitMultipleFiles';
import { DATA } from './constants';
import { assertSecret, BlitzGlossary } from "@blitzkit/core";
import sharp from "sharp";
import { readDVPLFile } from "../../src/core/blitz/readDVPLFile";
import { AssetUploader } from "../core/github/assetUploader";
import { DATA } 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'],
["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...');
console.log("Building currency icons...");
const changes: FileChange[] = [];
using uploader = new AssetUploader("currency icons");
await Promise.all(
ICONS.map(async ([file, name]) => {
const content = await sharp(
await readDVPLFile(`${DATA}/Gfx/Lobby/currency/${file}`),
)
.trim()
.toBuffer();
for (const [file, name] of ICONS) {
const content = await sharp(
await readDVPLFile(`${DATA}/Gfx/Lobby/currency/${file}`)
)
.trim()
.toBuffer();
changes.push({
content,
path: `icons/currencies/${name}.webp`,
});
}),
);
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>);
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}`))
);
await Promise.all(
Object.entries(glossary)
.filter(([key]) => /^prx_season_\d+$/.test(key))
.map(async ([key, item]) => {
if (item.image_url === null) throw new Error(`No image_url for ${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();
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();
changes.push({
content,
path: `icons/currencies/${key}.webp`,
});
}),
);
await uploader.add({
content,
path: `icons/currencies/${key}.webp`,
});
}
await commitAssets('currency icons', changes);
await uploader.flush();
}