fix: types

This commit is contained in:
TrèsAbhi committed 2024-09-07 21:45:00 -05:00
1 parent 9ae8b0ac49
commit 3c80a43435
255 files changed
+797 -838

No files matched your search

@@ -0,0 +1,16 @@
import { assertSecret } from '@blitzkit/core';
import commitMultipleFiles, { FileChange } from './commitMultipleFiles';
export async function commitAssets(message: string, changes: FileChange[]) {
console.log(`Committing ${message}...`);
if (changes.length === 0) return;
await commitMultipleFiles(
'tresabhi',
assertSecret(process.env.NEXT_PUBLIC_ASSET_REPO),
assertSecret(process.env.NEXT_PUBLIC_ASSET_BRANCH),
`${message} - ${new Date().toDateString()}`,
changes,
);
}
@@ -0,0 +1,66 @@
import ProgressBar from 'progress';
import {
GithubChangeBlob,
createBlob,
} from '../../../../website/src/core/blitzkit/createBlob';
import { octokit } from '../../../../website/src/core/blitzkit/octokit';
export interface FileChange {
path: string;
content: string;
encoding: 'utf-8' | 'base64';
}
export default async function commitMultipleFiles(
owner: string,
repo: string,
branch: string,
message: string,
changes: FileChange[],
) {
const latestCommitSha = (
await octokit.git.getRef({
owner,
repo,
ref: `heads/${branch}`,
})
).data.object.sha;
const treeSha = (
await octokit.git.getCommit({
owner,
repo,
commit_sha: latestCommitSha,
})
).data.tree.sha;
const blobs: GithubChangeBlob[] = [];
const bar = new ProgressBar('Blobs :bar', changes.length);
for (const changeIndexString in changes) {
const changeIndex = parseInt(changeIndexString);
const change = changes[changeIndex];
const createdBlob = await createBlob(owner, repo, change);
blobs.push(createdBlob!);
bar.tick();
}
const { data: treeData } = await octokit.git.createTree({
owner,
repo,
base_tree: treeSha,
tree: blobs,
});
const { data: newCommitData } = await octokit.git.createCommit({
owner,
repo,
message,
tree: treeData.sha,
parents: [latestCommitSha],
});
await octokit.git.updateRef({
owner,
repo,
ref: `heads/${branch}`,
sha: newCommitData.sha,
force: true,
});
}
@@ -0,0 +1,36 @@
import { asset, DidsReadStream } from '@blitzkit/core';
import { times } from 'lodash';
import { decompress } from 'lz4js';
import ProgressBar from 'progress';
import { DiscoveredIdsDefinitions } from '../../../../website/src/core/blitzkit/discoveredIdDefinitions';
export async function fetchPreDiscoveredIds() {
const idChunks: number[][] = [];
const manifest = (await fetch(asset('ids/manifest.json')).then((response) =>
response.json(),
)) as DiscoveredIdsDefinitions;
const bar = new ProgressBar(
`Fetching ${manifest.count.toLocaleString()} ids in ${
manifest.chunks
} chunks :bar`,
manifest.chunks,
);
bar.render();
await Promise.all(
times(manifest.chunks, async (chunkIndex) => {
const preDiscovered = await fetch(
asset(`ids/${chunkIndex}.dids.lz4`),
).then(async (response) => {
const buffer = await response.arrayBuffer();
const decompressed = decompress(new Uint8Array(buffer)).buffer;
return new DidsReadStream(decompressed as ArrayBuffer).dids();
});
idChunks.push(preDiscovered);
bar.tick();
}),
);
return idChunks.sort((a, b) => a[0] - b[0]).flat();
}