mirror of
https://github.com/blitzkit/blitzkit.git
synced 2026-10-21 02:37:05 +02:00
feat: use buffers
This commit is contained in:
1 parent
c8bb1f190a
commit
c98c19dc36
26 files changed
+134
-269
No files matched your search
@@ -1,5 +0,0 @@
|
||||
import { MessageFns } from '../protos';
|
||||
|
||||
export function encodePB64<Type>(message: MessageFns<Type>, data: Type) {
|
||||
return Buffer.from(message.encode(data).finish()).toString('base64');
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
import { MessageFns } from '../protos';
|
||||
|
||||
export function encodePBBuffer<Type>(message: MessageFns<Type>, data: Type) {
|
||||
return Buffer.from(message.encode(data).finish());
|
||||
}
|
||||
@@ -1,3 +1,3 @@
|
||||
export * from './encodePB64';
|
||||
export * from './encodePBBuffer';
|
||||
export * from './fetchPB';
|
||||
export * from './pbMap';
|
||||
@@ -8,7 +8,7 @@ import {
|
||||
Samples,
|
||||
averageDefinitionsAllStatsKeys,
|
||||
emptySamples,
|
||||
encodePB64,
|
||||
encodePBBuffer,
|
||||
getAccountInfo,
|
||||
getTankStats,
|
||||
idToRegion,
|
||||
@@ -235,13 +235,11 @@ async function postWork() {
|
||||
commitAssets('averages', [
|
||||
{
|
||||
path: `averages/${latest}.pb`,
|
||||
content: encodePB64(AverageDefinitions, averageDefinitions),
|
||||
encoding: 'base64',
|
||||
content: encodePBBuffer(AverageDefinitions, averageDefinitions),
|
||||
},
|
||||
{
|
||||
path: 'averages/manifest.json',
|
||||
content: JSON.stringify(manifest),
|
||||
encoding: 'utf-8',
|
||||
content: Buffer.from(JSON.stringify(manifest), 'utf-8'),
|
||||
},
|
||||
]);
|
||||
}
|
||||
@@ -27,22 +27,19 @@ export async function boosterIcons() {
|
||||
.split('\n')[4]
|
||||
.split(' ')
|
||||
.map(Number);
|
||||
const content = (
|
||||
await image
|
||||
.clone()
|
||||
.extract({
|
||||
left: sizes[0],
|
||||
top: sizes[1],
|
||||
width: sizes[2],
|
||||
height: sizes[3],
|
||||
})
|
||||
.toBuffer()
|
||||
).toString('base64');
|
||||
const content = await image
|
||||
.clone()
|
||||
.extract({
|
||||
left: sizes[0],
|
||||
top: sizes[1],
|
||||
width: sizes[2],
|
||||
height: sizes[3],
|
||||
})
|
||||
.toBuffer();
|
||||
|
||||
changes.push({
|
||||
path: `icons/boosters/${name}.webp`,
|
||||
content,
|
||||
encoding: 'base64',
|
||||
});
|
||||
}),
|
||||
);
|
||||
|
||||
@@ -7,11 +7,10 @@ export async function camouflageIcons() {
|
||||
console.log('Building camouflage icons...');
|
||||
const content = await readDVPLFile(
|
||||
`${DATA}/Gfx/UI/Hangar/IconCamouflage.packed.webp.dvpl`,
|
||||
).then((content) => content.toString('base64'));
|
||||
);
|
||||
const changes: FileChange[] = [
|
||||
{
|
||||
content,
|
||||
encoding: 'base64',
|
||||
path: 'icons/camo.webp',
|
||||
},
|
||||
];
|
||||
|
||||
@@ -74,13 +74,10 @@ export async function consumableProvisionIcons() {
|
||||
const image = sharp(
|
||||
await readDVPLFile(`${DATA}/${configPath}.packed.webp.dvpl`),
|
||||
);
|
||||
const content = (
|
||||
await image.trim({ threshold: 100 }).toBuffer()
|
||||
).toString('base64');
|
||||
const content = await image.trim({ threshold: 100 }).toBuffer();
|
||||
|
||||
changes.push({
|
||||
path: `icons/consumables/${consumable.id}.webp`,
|
||||
encoding: 'base64',
|
||||
content,
|
||||
});
|
||||
} else {
|
||||
@@ -93,21 +90,18 @@ export async function consumableProvisionIcons() {
|
||||
.split('\n')[4]
|
||||
.split(' ')
|
||||
.map(Number);
|
||||
const content = (
|
||||
await consumablesTexture
|
||||
.clone()
|
||||
.extract({
|
||||
left: sizes[0],
|
||||
top: sizes[1],
|
||||
width: sizes[2],
|
||||
height: sizes[3],
|
||||
})
|
||||
.toBuffer()
|
||||
).toString('base64');
|
||||
const content = await consumablesTexture
|
||||
.clone()
|
||||
.extract({
|
||||
left: sizes[0],
|
||||
top: sizes[1],
|
||||
width: sizes[2],
|
||||
height: sizes[3],
|
||||
})
|
||||
.toBuffer();
|
||||
|
||||
changes.push({
|
||||
path: `icons/consumables/${consumable.id}.webp`,
|
||||
encoding: 'base64',
|
||||
content,
|
||||
});
|
||||
}
|
||||
@@ -147,13 +141,10 @@ export async function consumableProvisionIcons() {
|
||||
const image = sharp(
|
||||
await readDVPLFile(`${DATA}/${configPath}.packed.webp.dvpl`),
|
||||
);
|
||||
const content = (
|
||||
await image.trim({ threshold: 100 }).toBuffer()
|
||||
).toString('base64');
|
||||
const content = await image.trim({ threshold: 100 }).toBuffer();
|
||||
|
||||
changes.push({
|
||||
path: `icons/provisions/${provision.id}.webp`,
|
||||
encoding: 'base64',
|
||||
content,
|
||||
});
|
||||
} else {
|
||||
@@ -166,21 +157,18 @@ export async function consumableProvisionIcons() {
|
||||
.split('\n')[4]
|
||||
.split(' ')
|
||||
.map(Number);
|
||||
const content = (
|
||||
await provisionsTexture
|
||||
.clone()
|
||||
.extract({
|
||||
left: sizes[0],
|
||||
top: sizes[1],
|
||||
width: sizes[2],
|
||||
height: sizes[3],
|
||||
})
|
||||
.toBuffer()
|
||||
).toString('base64');
|
||||
const content = await provisionsTexture
|
||||
.clone()
|
||||
.extract({
|
||||
left: sizes[0],
|
||||
top: sizes[1],
|
||||
width: sizes[2],
|
||||
height: sizes[3],
|
||||
})
|
||||
.toBuffer();
|
||||
|
||||
changes.push({
|
||||
path: `icons/provisions/${provision.id}.webp`,
|
||||
encoding: 'base64',
|
||||
content,
|
||||
});
|
||||
}
|
||||
|
||||
@@ -29,17 +29,14 @@ export async function currencies() {
|
||||
|
||||
await Promise.all(
|
||||
ICONS.map(async ([file, name]) => {
|
||||
const content = (
|
||||
await sharp(
|
||||
await readDVPLFile(`${DATA}/Gfx/Lobby/currency/${file}.dvpl`),
|
||||
)
|
||||
.trim()
|
||||
.toBuffer()
|
||||
).toString('base64');
|
||||
const content = await sharp(
|
||||
await readDVPLFile(`${DATA}/Gfx/Lobby/currency/${file}.dvpl`),
|
||||
)
|
||||
.trim()
|
||||
.toBuffer();
|
||||
|
||||
changes.push({
|
||||
content,
|
||||
encoding: 'base64',
|
||||
path: `icons/currencies/${name}.webp`,
|
||||
});
|
||||
}),
|
||||
@@ -58,18 +55,15 @@ export async function currencies() {
|
||||
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()
|
||||
).toString('base64');
|
||||
const content = await sharp(imageRaw)
|
||||
.trim({
|
||||
threshold: 100,
|
||||
background: { r: 0, g: 0, b: 0, alpha: 0 },
|
||||
})
|
||||
.toBuffer();
|
||||
|
||||
changes.push({
|
||||
content,
|
||||
encoding: 'base64',
|
||||
path: `icons/currencies/${key}.webp`,
|
||||
});
|
||||
}),
|
||||
|
||||
@@ -7,7 +7,7 @@ import {
|
||||
ConsumableTankCategoryFilterCategory,
|
||||
Crew,
|
||||
CrewType,
|
||||
encodePB64,
|
||||
encodePBBuffer,
|
||||
EquipmentDefinitions,
|
||||
EquipmentSlot,
|
||||
GameDefinitions,
|
||||
@@ -1650,48 +1650,39 @@ export async function definitions() {
|
||||
|
||||
await commitAssets('definitions', [
|
||||
{
|
||||
content: encodePB64(GameDefinitions, gameDefinitions),
|
||||
encoding: 'base64',
|
||||
content: encodePBBuffer(GameDefinitions, gameDefinitions),
|
||||
path: 'definitions/game.pb',
|
||||
},
|
||||
{
|
||||
content: encodePB64(TankDefinitions, tankDefinitions),
|
||||
encoding: 'base64',
|
||||
content: encodePBBuffer(TankDefinitions, tankDefinitions),
|
||||
path: 'definitions/tanks.pb',
|
||||
},
|
||||
{
|
||||
content: encodePB64(ModelDefinitions, modelDefinitions),
|
||||
encoding: 'base64',
|
||||
content: encodePBBuffer(ModelDefinitions, modelDefinitions),
|
||||
path: 'definitions/models.pb',
|
||||
},
|
||||
{
|
||||
content: encodePB64(EquipmentDefinitions, equipmentDefinitions),
|
||||
encoding: 'base64',
|
||||
content: encodePBBuffer(EquipmentDefinitions, equipmentDefinitions),
|
||||
path: 'definitions/equipment.pb',
|
||||
},
|
||||
{
|
||||
content: encodePB64(ConsumableDefinitions, consumableDefinitions),
|
||||
encoding: 'base64',
|
||||
content: encodePBBuffer(ConsumableDefinitions, consumableDefinitions),
|
||||
path: 'definitions/consumables.pb',
|
||||
},
|
||||
{
|
||||
content: encodePB64(ProvisionDefinitions, provisionDefinitions),
|
||||
encoding: 'base64',
|
||||
content: encodePBBuffer(ProvisionDefinitions, provisionDefinitions),
|
||||
path: 'definitions/provisions.pb',
|
||||
},
|
||||
{
|
||||
content: encodePB64(SkillDefinitions, skillDefinitions),
|
||||
encoding: 'base64',
|
||||
content: encodePBBuffer(SkillDefinitions, skillDefinitions),
|
||||
path: 'definitions/skills.pb',
|
||||
},
|
||||
{
|
||||
content: encodePB64(MapDefinitions, mapDefinitions),
|
||||
encoding: 'base64',
|
||||
content: encodePBBuffer(MapDefinitions, mapDefinitions),
|
||||
path: 'definitions/maps.pb',
|
||||
},
|
||||
{
|
||||
content: encodePB64(CamouflageDefinitions, camouflageDefinitions),
|
||||
encoding: 'base64',
|
||||
content: encodePBBuffer(CamouflageDefinitions, camouflageDefinitions),
|
||||
path: 'definitions/camouflages.pb',
|
||||
},
|
||||
]);
|
||||
|
||||
@@ -59,31 +59,27 @@ export async function equipmentIcons() {
|
||||
const image = sharp(
|
||||
await readDVPLFile(`${DATA}/${configPathWebp}.packed.webp.dvpl`),
|
||||
);
|
||||
const content = (await image.trim().toBuffer()).toString('base64');
|
||||
const content = await image.trim().toBuffer();
|
||||
|
||||
changes.push({
|
||||
path: `icons/equipment/${optionalDevice.id}.webp`,
|
||||
encoding: 'base64',
|
||||
content,
|
||||
});
|
||||
} else {
|
||||
const config = await readStringDVPL(`${DATA}/${configPath}.dvpl`);
|
||||
const sizes = config.split('\n')[4].split(' ').map(Number);
|
||||
const content = (
|
||||
await image
|
||||
.clone()
|
||||
.extract({
|
||||
left: sizes[0],
|
||||
top: sizes[1],
|
||||
width: sizes[2],
|
||||
height: sizes[3],
|
||||
})
|
||||
.toBuffer()
|
||||
).toString('base64');
|
||||
const content = await image
|
||||
.clone()
|
||||
.extract({
|
||||
left: sizes[0],
|
||||
top: sizes[1],
|
||||
width: sizes[2],
|
||||
height: sizes[3],
|
||||
})
|
||||
.toBuffer();
|
||||
|
||||
changes.push({
|
||||
path: `icons/equipment/${optionalDevice.id}.webp`,
|
||||
encoding: 'base64',
|
||||
content,
|
||||
});
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}),
|
||||
|
||||
@@ -37,16 +37,15 @@ export async function gameModeBanners() {
|
||||
path = `/Gfx/UI/Hangar/GameTypes/battle-type_${name.toLowerCase()}`;
|
||||
}
|
||||
|
||||
const content = (
|
||||
await sharp(await readDVPLFile(`${DATA}${path}.packed.webp.dvpl`))
|
||||
.trim({ background: { r: 0, g: 0, b: 0, alpha: 0 } })
|
||||
.toBuffer()
|
||||
).toString('base64');
|
||||
const content = await sharp(
|
||||
await readDVPLFile(`${DATA}${path}.packed.webp.dvpl`),
|
||||
)
|
||||
.trim({ background: { r: 0, g: 0, b: 0, alpha: 0 } })
|
||||
.toBuffer();
|
||||
|
||||
changes.push({
|
||||
path: `icons/game_mode_banners/${id}.webp`,
|
||||
content,
|
||||
encoding: 'base64',
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -17,18 +17,15 @@ export async function moduleIcons() {
|
||||
.map(async (file) => {
|
||||
const nameRaw = file.match(/vehicle(.+)\.packed\.webp\.dvpl/)![1];
|
||||
const name = nameRaw[0].toLowerCase() + nameRaw.slice(1);
|
||||
const content = (
|
||||
await sharp(
|
||||
await readDVPLFile(`${DATA}/Gfx/UI/ModulesTechTree/${file}`),
|
||||
)
|
||||
.trim()
|
||||
.toBuffer()
|
||||
).toString('base64');
|
||||
const content = await sharp(
|
||||
await readDVPLFile(`${DATA}/Gfx/UI/ModulesTechTree/${file}`),
|
||||
)
|
||||
.trim()
|
||||
.toBuffer();
|
||||
|
||||
return {
|
||||
content,
|
||||
path: `icons/modules/${name}.webp`,
|
||||
encoding: 'base64',
|
||||
} satisfies FileChange;
|
||||
}),
|
||||
);
|
||||
|
||||
@@ -16,9 +16,7 @@ export async function shellIcons() {
|
||||
);
|
||||
|
||||
const changes = await Promise.all(
|
||||
(
|
||||
await readdir(`${DATA}/Gfx/Shared/tank-supply/ammunition/big`)
|
||||
)
|
||||
(await readdir(`${DATA}/Gfx/Shared/tank-supply/ammunition/big`))
|
||||
.filter((file) => file.endsWith('_l.txt.dvpl'))
|
||||
.map(async (file) => {
|
||||
const name = file.match(/(.+)_l\.txt\.dvpl/)![1];
|
||||
@@ -32,18 +30,15 @@ export async function shellIcons() {
|
||||
.map(Number);
|
||||
|
||||
return {
|
||||
content: (
|
||||
await image
|
||||
.clone()
|
||||
.extract({
|
||||
left: sizes[0],
|
||||
top: sizes[1],
|
||||
width: sizes[2],
|
||||
height: sizes[3],
|
||||
})
|
||||
.toBuffer()
|
||||
).toString('base64'),
|
||||
encoding: 'base64',
|
||||
content: await image
|
||||
.clone()
|
||||
.extract({
|
||||
left: sizes[0],
|
||||
top: sizes[1],
|
||||
width: sizes[2],
|
||||
height: sizes[3],
|
||||
})
|
||||
.toBuffer(),
|
||||
path: `icons/shells/${name}.webp`,
|
||||
} satisfies FileChange;
|
||||
}),
|
||||
|
||||
@@ -37,11 +37,10 @@ export async function skillIcons() {
|
||||
const name = icon.name.split('/').at(-1)!.replace(/_\d$/, '');
|
||||
const path = `${DATA}${icon.name.replace('~res:', '')}.packed.webp.dvpl`;
|
||||
const image = sharp(await readDVPLFile(path)).trim();
|
||||
const content = (await image.toBuffer()).toString('base64');
|
||||
const content = await image.toBuffer();
|
||||
|
||||
return {
|
||||
content,
|
||||
encoding: 'base64',
|
||||
path: `icons/skills/${name}.webp`,
|
||||
} satisfies FileChange;
|
||||
}),
|
||||
|
||||
@@ -32,10 +32,7 @@ export async function tankArmors() {
|
||||
|
||||
changes.push({
|
||||
path: `3d/tanks/armor/${id}.glb`,
|
||||
encoding: 'base64',
|
||||
content: Buffer.from(await nodeIO.writeBinary(model)).toString(
|
||||
'base64',
|
||||
),
|
||||
content: Buffer.from(await nodeIO.writeBinary(model)),
|
||||
});
|
||||
}),
|
||||
);
|
||||
|
||||
@@ -80,15 +80,13 @@ export async function tankIcons() {
|
||||
|
||||
if (big) {
|
||||
changes.push({
|
||||
content: big.toString('base64'),
|
||||
encoding: 'base64',
|
||||
content: big,
|
||||
path: `icons/tanks/big/${id}.webp`,
|
||||
});
|
||||
}
|
||||
if (small) {
|
||||
changes.push({
|
||||
content: small.toString('base64'),
|
||||
encoding: 'base64',
|
||||
content: small,
|
||||
path: `icons/tanks/small/${id}.webp`,
|
||||
});
|
||||
}
|
||||
|
||||
@@ -42,10 +42,7 @@ export async function tankModels() {
|
||||
|
||||
changes.push({
|
||||
path: `3d/tanks/models/${id}.glb`,
|
||||
content: Buffer.from(await nodeIO.writeBinary(model)).toString(
|
||||
'base64',
|
||||
),
|
||||
encoding: 'base64',
|
||||
content: Buffer.from(await nodeIO.writeBinary(model)),
|
||||
});
|
||||
}),
|
||||
);
|
||||
|
||||
@@ -1,64 +0,0 @@
|
||||
import { assertSecret } from '@blitzkit/core';
|
||||
import { GithubChangeBlob, createBlob } from './createBlob';
|
||||
import { octokit } from './octokit';
|
||||
|
||||
export class AssetCommit {
|
||||
constructor(public message: string) {}
|
||||
private blobs: GithubChangeBlob[] = [];
|
||||
|
||||
async add(path: string, content: string, encoding: 'utf-8' | 'base64') {
|
||||
console.log(`Blob: adding ${path}...`);
|
||||
|
||||
const blob = await createBlob(
|
||||
'tresabhi',
|
||||
assertSecret(process.env.PUBLIC_ASSET_REPO),
|
||||
{
|
||||
content,
|
||||
encoding,
|
||||
path,
|
||||
},
|
||||
);
|
||||
|
||||
this.blobs.push(blob!);
|
||||
}
|
||||
|
||||
async push() {
|
||||
if (this.blobs.length === 0) return;
|
||||
|
||||
const latestCommitSha = (
|
||||
await octokit.git.getRef({
|
||||
owner: 'tresabhi',
|
||||
repo: assertSecret(process.env.PUBLIC_ASSET_REPO),
|
||||
ref: `heads/${assertSecret(process.env.PUBLIC_ASSET_BRANCH)}`,
|
||||
})
|
||||
).data.object.sha;
|
||||
const treeSha = (
|
||||
await octokit.git.getCommit({
|
||||
owner: 'tresabhi',
|
||||
repo: assertSecret(process.env.PUBLIC_ASSET_REPO),
|
||||
commit_sha: latestCommitSha,
|
||||
})
|
||||
).data.tree.sha;
|
||||
const blobs: GithubChangeBlob[] = [];
|
||||
|
||||
const { data: treeData } = await octokit.git.createTree({
|
||||
owner: 'tresabhi',
|
||||
repo: assertSecret(process.env.PUBLIC_ASSET_REPO),
|
||||
base_tree: treeSha,
|
||||
tree: blobs,
|
||||
});
|
||||
const { data: newCommitData } = await octokit.git.createCommit({
|
||||
owner: 'tresabhi',
|
||||
repo: assertSecret(process.env.PUBLIC_ASSET_REPO),
|
||||
message: this.message,
|
||||
tree: treeData.sha,
|
||||
parents: [latestCommitSha],
|
||||
});
|
||||
await octokit.git.updateRef({
|
||||
owner: 'tresabhi',
|
||||
repo: assertSecret(process.env.PUBLIC_ASSET_REPO),
|
||||
ref: `heads/${assertSecret(process.env.PUBLIC_ASSET_BRANCH)}`,
|
||||
sha: newCommitData.sha,
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -7,7 +7,6 @@ export async function commitAssets(message: string, changes: FileChange[]) {
|
||||
if (changes.length === 0) return;
|
||||
|
||||
await commitMultipleFiles(
|
||||
'tresabhi',
|
||||
assertSecret(process.env.PUBLIC_ASSET_REPO),
|
||||
assertSecret(process.env.PUBLIC_ASSET_BRANCH),
|
||||
`${message} - ${new Date().toDateString()}`,
|
||||
|
||||
@@ -4,17 +4,16 @@ import { octokit } from './octokit';
|
||||
|
||||
export interface FileChange {
|
||||
path: string;
|
||||
content: string;
|
||||
encoding: 'utf-8' | 'base64';
|
||||
content: Buffer;
|
||||
}
|
||||
|
||||
export async function commitMultipleFiles(
|
||||
owner: string,
|
||||
repo: string,
|
||||
repoRaw: string,
|
||||
branch: string,
|
||||
message: string,
|
||||
changes: FileChange[],
|
||||
) {
|
||||
const [owner, repo] = repoRaw.split('/');
|
||||
const latestCommitSha = (
|
||||
await octokit.git.getRef({
|
||||
owner,
|
||||
|
||||
@@ -20,8 +20,8 @@ export const createBlob = throttle(
|
||||
await octokit.git.createBlob({
|
||||
owner,
|
||||
repo,
|
||||
content: change.content,
|
||||
encoding: change.encoding,
|
||||
content: change.content.toString('base64'),
|
||||
encoding: 'base64',
|
||||
})
|
||||
).data;
|
||||
|
||||
@@ -34,7 +34,6 @@ export const createBlob = throttle(
|
||||
} catch (error) {
|
||||
console.warn(
|
||||
`Failed blob ${change.path}; retrying in ${TIME_PER_BLOB}ms...`,
|
||||
// error,
|
||||
);
|
||||
|
||||
await new Promise((resolve) => setTimeout(resolve, TIME_PER_BLOB));
|
||||
|
||||
@@ -13,6 +13,7 @@ import {
|
||||
import { chunk, times, uniq } from 'lodash-es';
|
||||
import { compress, decompress } from 'lz4js';
|
||||
import { commitAssets } from './core/github/commitAssets';
|
||||
import { FileChange } from './core/github/commitMultipleFiles';
|
||||
|
||||
const CHUNK_SIZE = 2 ** 21;
|
||||
const RUN_TIME = 1000 * 60 * 60 * 5.5;
|
||||
@@ -139,24 +140,25 @@ function post() {
|
||||
`Chunk ${index} with ${chunk.length} ids (compressed: ${compressed.length}; uncompressed: ${buffer.length})`,
|
||||
);
|
||||
|
||||
const content = Buffer.from(compressed).toString('base64');
|
||||
const content = Buffer.from(compressed);
|
||||
|
||||
return {
|
||||
content,
|
||||
encoding: 'base64' as const,
|
||||
path: `ids/${index}.dids.lz4`,
|
||||
};
|
||||
} satisfies FileChange;
|
||||
});
|
||||
|
||||
commitAssets('discovered ids', [
|
||||
...files,
|
||||
{
|
||||
content: JSON.stringify({
|
||||
chunks: idsChunked.length,
|
||||
count: ids.length,
|
||||
time: Date.now(),
|
||||
} satisfies DiscoveredIdsDefinitions),
|
||||
encoding: 'utf-8',
|
||||
content: Buffer.from(
|
||||
JSON.stringify({
|
||||
chunks: idsChunked.length,
|
||||
count: ids.length,
|
||||
time: Date.now(),
|
||||
} satisfies DiscoveredIdsDefinitions),
|
||||
'utf-8',
|
||||
),
|
||||
path: 'ids/manifest.json',
|
||||
},
|
||||
]);
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import {
|
||||
asset,
|
||||
encodePB64,
|
||||
encodePBBuffer,
|
||||
Reviews,
|
||||
toUniqueId,
|
||||
Video,
|
||||
@@ -126,8 +126,7 @@ for (const tank of tanksSanitized) {
|
||||
|
||||
await commitAssets('reviews', [
|
||||
{
|
||||
content: encodePB64(Reviews, reviews),
|
||||
encoding: 'base64',
|
||||
content: encodePBBuffer(Reviews, reviews),
|
||||
path: 'definitions/reviews.pb',
|
||||
},
|
||||
]);
|
||||
@@ -1,6 +1,6 @@
|
||||
'use client';
|
||||
|
||||
import { idToRegion } from '@blitzkit/core';
|
||||
import { assertSecret, idToRegion } from '@blitzkit/core';
|
||||
import { Button, Flex, Heading, Link, Text } from '@radix-ui/themes';
|
||||
import { useEffect, useState } from 'react';
|
||||
import { App } from '../stores/app';
|
||||
@@ -81,9 +81,9 @@ function Content() {
|
||||
fetch(
|
||||
`https://api.worldoftanks.${idToRegion(
|
||||
wargaming.id,
|
||||
)}/wot/auth/prolongate/?application_id=${
|
||||
import.meta.env.PUBLIC_WARGAMING_APPLICATION_ID
|
||||
}&access_token=${wargaming.token}`,
|
||||
)}/wot/auth/prolongate/?application_id=${assertSecret(
|
||||
import.meta.env.PUBLIC_WARGAMING_APPLICATION_ID,
|
||||
)}&access_token=${wargaming.token}`,
|
||||
)
|
||||
.then((response) => response.json() as Promise<Extension>)
|
||||
.then((json) => {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
---
|
||||
import { fetchGameDefinitions } from '@blitzkit/core';
|
||||
import { assertSecret, fetchGameDefinitions } from '@blitzkit/core';
|
||||
import { Code, Flex, Heading, Link, Text } from '@radix-ui/themes';
|
||||
import packageJson from '../../../../package.json';
|
||||
|
||||
@@ -134,7 +134,7 @@ const gameDefinitions = await fetchGameDefinitions();
|
||||
{gameDefinitions.version}
|
||||
</Code>
|
||||
<Code size="2" color="gray">
|
||||
{import.meta.env.PUBLIC_ASSET_BRANCH}
|
||||
{assertSecret(import.meta.env.PUBLIC_ASSET_BRANCH)}
|
||||
</Code>
|
||||
</Flex>
|
||||
</Flex>
|
||||
@@ -150,7 +150,7 @@ const gameDefinitions = await fetchGameDefinitions();
|
||||
</Code>
|
||||
<Text size="2" color="gray"> CDN </Text>
|
||||
<Code size="2" color="gray">
|
||||
{import.meta.env.PUBLIC_ASSET_BRANCH}
|
||||
{assertSecret(import.meta.env.PUBLIC_ASSET_BRANCH)}
|
||||
</Code>
|
||||
</Flex>
|
||||
</Flex>
|
||||
Reference in new issue
Block a user