feat: detached cdn branch

This commit is contained in:
TrèsAbhi committed 2024-08-27 14:40:43 -05:00
1 parent ed041b78bb
commit 48dcbbc227
43 files changed
+267 -397

No files matched your search

+8 -2
View File
@@ -26,7 +26,10 @@ export function writeDVPL(buffer: Buffer) {
0,
);
return Buffer.concat([buffer, footerBuffer], buffer.length + 20);
return Buffer.concat(
[new Uint8Array(buffer), new Uint8Array(footerBuffer)],
buffer.length + 20,
);
} else {
output = output.subarray(0, compressedBlockSize);
const footerBuffer = toDVPLFooter(
@@ -36,7 +39,10 @@ export function writeDVPL(buffer: Buffer) {
2,
);
return Buffer.concat([output, footerBuffer], compressedBlockSize + 20);
return Buffer.concat(
[new Uint8Array(output), new Uint8Array(footerBuffer)],
compressedBlockSize + 20,
);
}
}
+5 -3
View File
@@ -1,6 +1,8 @@
import { ASSETS_REPO } from '../../constants/assets';
import isDev from './isDev';
import { assertSecrete } from './secrete';
export function asset(path: string, dev = isDev()) {
return `https://raw.githubusercontent.com/tresabhi/${ASSETS_REPO}/${dev ? 'dev' : 'main'}/${path}`;
export function asset(path: string) {
return `https://raw.githubusercontent.com/tresabhi/${ASSETS_REPO}/${assertSecrete(
process.env.NEXT_PUBLIC_ASSET_BRANCH,
)}/${path}`;
}
+3 -6
View File
@@ -1,11 +1,8 @@
import { ASSETS_REPO } from '../../constants/assets';
import commitMultipleFiles, { FileChange } from './commitMultipleFiles';
import { assertSecrete } from './secrete';
export async function commitAssets(
message: string,
changes: FileChange[],
production: boolean,
) {
export async function commitAssets(message: string, changes: FileChange[]) {
console.log(`Committing ${message}...`);
if (changes.length === 0) return;
@@ -13,7 +10,7 @@ export async function commitAssets(
await commitMultipleFiles(
'tresabhi',
ASSETS_REPO,
production ? 'main' : 'dev',
assertSecrete(process.env.NEXT_PUBLIC_ASSET_BRANCH),
`${message} - ${new Date().toDateString()}`,
changes,
);
+3 -4
View File
@@ -1,5 +1,4 @@
import { asset } from './asset';
import isDev from './isDev';
export interface DiscoveredIdsDefinitions {
time: number;
@@ -7,6 +6,6 @@ export interface DiscoveredIdsDefinitions {
count: number;
}
export const discoveredIdsDefinitions = fetch(
asset('ids/manifest.json', isDev()),
).then((response) => response.json() as Promise<DiscoveredIdsDefinitions>);
export const discoveredIdsDefinitions = fetch(asset('ids/manifest.json')).then(
(response) => response.json() as Promise<DiscoveredIdsDefinitions>,
);
+4 -4
View File
@@ -5,10 +5,10 @@ import { DidsReadStream } from '../streams/dids';
import { asset } from './asset';
import { DiscoveredIdsDefinitions } from './discoveredIdDefinitions';
export async function fetchPreDiscoveredIds(dev: boolean) {
export async function fetchPreDiscoveredIds() {
const idChunks: number[][] = [];
const manifest = (await fetch(asset('ids/manifest.json', dev)).then(
(response) => response.json(),
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`,
@@ -19,7 +19,7 @@ export async function fetchPreDiscoveredIds(dev: boolean) {
await Promise.all(
times(manifest.chunks, async (chunkIndex) => {
const preDiscovered = await fetch(
asset(`ids/${chunkIndex}.dids.lz4`, dev),
asset(`ids/${chunkIndex}.dids.lz4`),
).then(async (response) => {
const buffer = await response.arrayBuffer();
const decompressed = decompress(new Uint8Array(buffer)).buffer;
-23
View File
@@ -1,23 +0,0 @@
import { config } from 'dotenv';
config();
const devHostStartNames = [
'dev',
'beta',
'blitzkrieg-',
'localhost',
'betakrieg',
'devkrieg',
'blitzrinth-',
'blitzkit-',
];
export default function isDev() {
return (
process.env.NODE_ENV === 'development' ||
process.env.VERCEL_ENV === 'preview' ||
(typeof window !== 'undefined' &&
devHostStartNames.some((name) => window.location.host.startsWith(name)))
);
}
+4 -2
View File
@@ -1,7 +1,9 @@
import { throttling } from '@octokit/plugin-throttling';
import { Octokit } from '@octokit/rest';
import { secrets } from './secrets';
import { assertSecrete } from './secrete';
Octokit.plugin(throttling);
export const octokit = new Octokit({ auth: secrets.GH_TOKEN });
export const octokit = new Octokit({
auth: assertSecrete(process.env.GH_TOKEN),
});
+4 -2
View File
@@ -1,8 +1,10 @@
import { assertSecrete } from './secrete';
export function patreonLoginUrl() {
const params = new URLSearchParams({
response_type: 'code',
client_id: process.env.NEXT_PUBLIC_PATREON_CLIENT_ID as string,
redirect_uri: process.env.NEXT_PUBLIC_PATREON_REDIRECT_URI as string,
client_id: assertSecrete(process.env.NEXT_PUBLIC_PATREON_CLIENT_ID),
redirect_uri: assertSecrete(process.env.NEXT_PUBLIC_PATREON_REDIRECT_URI),
scope: 'identity',
});
+4
View File
@@ -0,0 +1,4 @@
export function assertSecrete(secrete?: string) {
if (secrete === undefined) throw new Error('Missing secret');
return secrete;
}
-27
View File
@@ -1,27 +0,0 @@
import { config } from 'dotenv';
config();
const SECRET_KEYS = [
'DISCORD_TOKEN',
'DISCORD_CLIENT_ID',
'GH_TOKEN',
'DATABASE_URL',
'WOTB_DLC_CDN',
] as const;
export type SECRET = typeof SECRET_KEYS extends readonly (infer T)[]
? T
: never;
export const secrets = SECRET_KEYS.reduce<Partial<Record<SECRET, string>>>(
(accumulator, key) => ({
...accumulator,
get [key](): string {
if (!(key in process.env)) throw new Error(`Secret ${key} not provided`);
return process.env[key]!;
},
}),
{},
) as Record<SECRET, string>;
+2 -2
View File
@@ -1,6 +1,6 @@
import { ShardingManager } from 'discord.js';
import { secrets } from '../blitzkit/secrets';
import { assertSecrete } from '../blitzkit/secrete';
export const manager = new ShardingManager('dist/bot/workers/bot.js', {
token: secrets.DISCORD_TOKEN,
token: assertSecrete(process.env.DISCORD_TOKEN),
});
+4 -6
View File
@@ -1,12 +1,10 @@
import { ASSETS_REPO } from '../../constants/assets';
import { GithubChangeBlob, createBlob } from '../blitzkit/createBlob';
import { octokit } from '../blitzkit/octokit';
import { assertSecrete } from '../blitzkit/secrete';
export class AssetCommit {
constructor(
public message: string,
public production: boolean,
) {}
constructor(public message: string) {}
private blobs: GithubChangeBlob[] = [];
async add(path: string, content: string, encoding: 'utf-8' | 'base64') {
@@ -28,7 +26,7 @@ export class AssetCommit {
await octokit.git.getRef({
owner: 'tresabhi',
repo: ASSETS_REPO,
ref: `heads/${this.production ? 'main' : 'dev'}`,
ref: `heads/${assertSecrete(process.env.NEXT_PUBLIC_ASSET_BRANCH)}`,
})
).data.object.sha;
const treeSha = (
@@ -56,7 +54,7 @@ export class AssetCommit {
await octokit.git.updateRef({
owner: 'tresabhi',
repo: ASSETS_REPO,
ref: `heads/${this.production ? 'main' : 'dev'}`,
ref: `heads/${assertSecrete(process.env.NEXT_PUBLIC_ASSET_BRANCH)}`,
sha: newCommitData.sha,
});
}