feat: use buffers

This commit is contained in:
TrèsAbhi committed 2024-10-21 18:32:52 -05:00
1 parent c8bb1f190a
commit c98c19dc36
26 files changed
+134 -269

No files matched your search

+14 -28
View File
@@ -1,6 +1,5 @@
import { readdir } from 'fs/promises';
import sharp from 'sharp';
import { readBase64DVPL } from '../core/blitz/readBase64DVPL';
import { readDVPLFile } from '../core/blitz/readDVPLFile';
import { commitAssets } from '../core/github/commitAssets';
import { FileChange } from '../core/github/commitMultipleFiles';
@@ -11,9 +10,7 @@ export async function flags() {
const changes = [
...(await Promise.all(
(
await readdir(`${DATA}/Gfx/Lobby/flags`)
)
(await readdir(`${DATA}/Gfx/Lobby/flags`))
.filter(
(flag) =>
flag.startsWith('flag_profile-stat_') &&
@@ -23,63 +20,52 @@ export async function flags() {
const image = sharp(
await readDVPLFile(`${DATA}/Gfx/Lobby/flags/${flag}`),
);
const content = (
await image.trim({ threshold: 100 }).toBuffer()
).toString('base64');
const content = await image.trim({ threshold: 100 }).toBuffer();
const name = flag.match(/flag_profile-stat_(.+)\.packed\.webp/)![1];
return {
content,
encoding: 'base64',
path: `flags/circle/${name}.webp`,
} satisfies FileChange;
}),
)),
...(await Promise.all(
(
await readdir(`${DATA}/Gfx/Lobby/flags`)
)
(await readdir(`${DATA}/Gfx/Lobby/flags`))
.filter(
(flag) =>
flag.startsWith('flag_tutor-tank_') &&
!flag.endsWith('@2x.packed.webp.dvpl'),
)
.map(async (flag) => {
const content = await readBase64DVPL(
`${DATA}/Gfx/Lobby/flags/${flag}`,
);
const content = await readDVPLFile(`${DATA}/Gfx/Lobby/flags/${flag}`);
const name = flag.match(/flag_tutor-tank_(.+)\.packed\.webp/)![1];
return {
content,
encoding: 'base64',
path: `flags/scratched/${name}.webp`,
content,
} satisfies FileChange;
}),
)),
...(await Promise.all(
(
await readdir(`${DATA}/Gfx/Lobby/flags`)
)
(await readdir(`${DATA}/Gfx/Lobby/flags`))
.filter(
(flag) =>
flag.startsWith('flag_filter_') &&
flag.endsWith('@2x.packed.webp.dvpl'),
)
.map(async (flag) => {
const content = (
await sharp(await readDVPLFile(`${DATA}/Gfx/Lobby/flags/${flag}`))
.trim({
threshold: 100,
background: { r: 0, g: 0, b: 0, alpha: 0 },
})
.toBuffer()
).toString('base64');
const content = await sharp(
await readDVPLFile(`${DATA}/Gfx/Lobby/flags/${flag}`),
)
.trim({
threshold: 100,
background: { r: 0, g: 0, b: 0, alpha: 0 },
})
.toBuffer();
const name = flag.match(/flag_filter_(.+)@2x\.packed\.webp/)![1];
return {
content,
encoding: 'base64',
path: `flags/fade_small/${name}.webp`,
} satisfies FileChange;
}),