mirror of
https://github.com/blitzkit/blitzkit.git
synced 2026-10-22 03:07:04 +02:00
feat: detached cdn branch
This commit is contained in:
1 parent
ed041b78bb
commit
48dcbbc227
43 files changed
+267
-397
No files matched your search
@@ -1,11 +1,18 @@
|
||||
import { NextResponse } from 'next/server';
|
||||
import { assertSecrete } from '../../../../../core/blitzkit/secrete';
|
||||
|
||||
export async function GET(
|
||||
request: Request,
|
||||
{ params }: { params: { code: string } },
|
||||
) {
|
||||
const response = await fetch(
|
||||
`https://www.patreon.com/api/oauth2/token?code=${params.code}&grant_type=authorization_code&client_id=${process.env.NEXT_PUBLIC_PATREON_CLIENT_ID}&client_secret=${process.env.PATREON_CLIENT_SECRET}&redirect_uri=${process.env.NEXT_PUBLIC_PATREON_REDIRECT_URI}`,
|
||||
`https://www.patreon.com/api/oauth2/token?code=${
|
||||
params.code
|
||||
}&grant_type=authorization_code&client_id=${assertSecrete(
|
||||
process.env.NEXT_PUBLIC_PATREON_CLIENT_ID,
|
||||
)}&client_secret=${assertSecrete(
|
||||
process.env.PATREON_CLIENT_SECRET,
|
||||
)}&redirect_uri=${assertSecrete(process.env.NEXT_PUBLIC_PATREON_REDIRECT_URI)}`,
|
||||
{
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { NextResponse } from 'next/server';
|
||||
import { assertSecrete } from '../../../../../core/blitzkit/secrete';
|
||||
|
||||
interface PatreonMembershipResponse {
|
||||
data: {
|
||||
@@ -68,7 +69,7 @@ export async function GET(
|
||||
(item) =>
|
||||
item.type === 'member' &&
|
||||
item.relationships.campaign.data.id ===
|
||||
process.env.PATREON_CAMPAIGN_ID &&
|
||||
assertSecrete(process.env.PATREON_CAMPAIGN_ID) &&
|
||||
item.attributes.patron_status === 'active_patron',
|
||||
),
|
||||
);
|
||||
|
||||
@@ -1,11 +1,16 @@
|
||||
import { NextResponse } from 'next/server';
|
||||
import { assertSecrete } from '../../../../../core/blitzkit/secrete';
|
||||
|
||||
export async function GET(
|
||||
request: Request,
|
||||
{ params }: { params: { token: string } },
|
||||
) {
|
||||
const response = await fetch(
|
||||
`https://www.patreon.com/api/oauth2/token?grant_type=refresh_token&refresh_token=${params.token}&client_id=${process.env.NEXT_PUBLIC_PATREON_CLIENT_ID}&client_secret=${process.env.PATREON_CLIENT_SECRET}`,
|
||||
`https://www.patreon.com/api/oauth2/token?grant_type=refresh_token&refresh_token=${
|
||||
params.token
|
||||
}&client_id=${assertSecrete(
|
||||
process.env.NEXT_PUBLIC_PATREON_CLIENT_ID,
|
||||
)}&client_secret=${assertSecrete(process.env.PATREON_CLIENT_SECRET)}`,
|
||||
{ method: 'POST' },
|
||||
);
|
||||
const json = await response.json();
|
||||
|
||||
@@ -3,7 +3,7 @@ import Markdown from 'markdown-to-jsx';
|
||||
import { use } from 'react';
|
||||
import { Link } from '../../../../components/Link';
|
||||
import PageWrapper from '../../../../components/PageWrapper';
|
||||
import isDev from '../../../../core/blitzkit/isDev';
|
||||
import { assertSecrete } from '../../../../core/blitzkit/secrete';
|
||||
|
||||
export default function Page({
|
||||
params,
|
||||
@@ -12,7 +12,9 @@ export default function Page({
|
||||
}) {
|
||||
const markdown = use(
|
||||
fetch(
|
||||
`https://raw.githubusercontent.com/tresabhi/blitzkit/${isDev() ? 'dev' : 'main'}/docs/${params.directory}/${params.document}.md`,
|
||||
`https://raw.githubusercontent.com/tresabhi/blitzkit/${assertSecrete(
|
||||
process.env.NEXT_PUBLIC_ASSET_BRANCH,
|
||||
)}/docs/${params.directory}/${params.document}.md`,
|
||||
).then((response) => response.text()),
|
||||
);
|
||||
|
||||
|
||||
@@ -1,31 +1,32 @@
|
||||
'use client';
|
||||
|
||||
import { Flex, Heading, Text, Theme } from '@radix-ui/themes';
|
||||
import { Code, Flex, Heading, Text, Theme } from '@radix-ui/themes';
|
||||
import { use } from 'react';
|
||||
import packageJson from '../../../package.json';
|
||||
import { gameDefinitions } from '../../core/blitzkit/gameDefinitions';
|
||||
import { Link } from '../Link';
|
||||
|
||||
export function Footer() {
|
||||
const awaitedGameDefinitions = use(gameDefinitions);
|
||||
|
||||
return (
|
||||
<Theme radius="none">
|
||||
<Flex
|
||||
justify="center"
|
||||
gap="3"
|
||||
gap="6"
|
||||
p="6"
|
||||
style={{
|
||||
backgroundColor: 'var(--color-panel)',
|
||||
}}
|
||||
direction="column"
|
||||
align="center"
|
||||
style={{ backgroundColor: 'var(--color-panel)' }}
|
||||
>
|
||||
<Flex
|
||||
align="center"
|
||||
justify="between"
|
||||
maxWidth="640px"
|
||||
maxWidth="40rem"
|
||||
width="100%"
|
||||
flexGrow="1"
|
||||
gap="5"
|
||||
position="relative"
|
||||
direction={{
|
||||
initial: 'column',
|
||||
sm: 'row',
|
||||
}}
|
||||
direction={{ initial: 'column', sm: 'row' }}
|
||||
>
|
||||
<Flex
|
||||
direction="column"
|
||||
@@ -34,12 +35,7 @@ export function Footer() {
|
||||
sm: 'start',
|
||||
}}
|
||||
>
|
||||
<Heading>
|
||||
BlitzKit{' '}
|
||||
<Text color="gray" size="1" weight="regular">
|
||||
{packageJson.version}
|
||||
</Text>
|
||||
</Heading>
|
||||
<Heading>BlitzKit </Heading>
|
||||
|
||||
<Text color="gray">Everything World of Tanks Blitz</Text>
|
||||
</Flex>
|
||||
@@ -131,6 +127,53 @@ export function Footer() {
|
||||
</Flex>
|
||||
</Flex>
|
||||
</Flex>
|
||||
|
||||
<Flex gap="5" display={{ initial: 'flex', sm: 'none' }}>
|
||||
<Flex direction="column" justify="between" align="end">
|
||||
<Text size="2" color="gray">
|
||||
BlitzKit
|
||||
</Text>
|
||||
<Text size="2" color="gray">
|
||||
WoT Blitz
|
||||
</Text>
|
||||
<Text size="2" color="gray">
|
||||
CDN
|
||||
</Text>
|
||||
</Flex>
|
||||
|
||||
<Flex direction="column" justify="between" align="start">
|
||||
<Code size="2" color="gray">
|
||||
{packageJson.version}
|
||||
</Code>
|
||||
<Code size="2" color="gray">
|
||||
{awaitedGameDefinitions.version}
|
||||
</Code>
|
||||
<Code size="2" color="gray">
|
||||
{process.env.NEXT_PUBLIC_ASSET_BRANCH}
|
||||
</Code>
|
||||
</Flex>
|
||||
</Flex>
|
||||
|
||||
<Flex gap="2" align="center" display={{ initial: 'none', sm: 'flex' }}>
|
||||
<Text size="2" color="gray">
|
||||
BlitzKit
|
||||
</Text>
|
||||
<Code size="2" color="gray">
|
||||
{packageJson.version}
|
||||
</Code>
|
||||
<Text size="2" color="gray">
|
||||
WoT Blitz
|
||||
</Text>
|
||||
<Code size="2" color="gray">
|
||||
{awaitedGameDefinitions.version}
|
||||
</Code>
|
||||
<Text size="2" color="gray">
|
||||
CDN
|
||||
</Text>
|
||||
<Code size="2" color="gray">
|
||||
{process.env.NEXT_PUBLIC_ASSET_BRANCH}
|
||||
</Code>
|
||||
</Flex>
|
||||
</Flex>
|
||||
</Theme>
|
||||
);
|
||||
|
||||
@@ -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,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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}`;
|
||||
}
|
||||
@@ -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,
|
||||
);
|
||||
|
||||
@@ -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>,
|
||||
);
|
||||
@@ -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;
|
||||
|
||||
@@ -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)))
|
||||
);
|
||||
}
|
||||
@@ -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),
|
||||
});
|
||||
@@ -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',
|
||||
});
|
||||
|
||||
|
||||
@@ -0,0 +1,4 @@
|
||||
export function assertSecrete(secrete?: string) {
|
||||
if (secrete === undefined) throw new Error('Missing secret');
|
||||
return secrete;
|
||||
}
|
||||
@@ -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>;
|
||||
@@ -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),
|
||||
});
|
||||
@@ -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,
|
||||
});
|
||||
}
|
||||
|
||||
@@ -33,7 +33,7 @@ import { searchPlayersCommand } from '../../commands/searchPlayers';
|
||||
import { statsCommand } from '../../commands/stats';
|
||||
import { todayCommand } from '../../commands/today';
|
||||
import { RenderConfiguration } from '../../core/blitzkit/renderConfiguration';
|
||||
import { secrets } from '../../core/blitzkit/secrets';
|
||||
import { assertSecrete } from '../../core/blitzkit/secrete';
|
||||
import handleAutocomplete from './handlers/autocomplete';
|
||||
import handleButton from './handlers/button';
|
||||
import handleChatInputCommand from './handlers/chatInputCommand';
|
||||
@@ -115,14 +115,19 @@ export const commands = Promise.allSettled(COMMANDS_RAW).then((rawCommands) => {
|
||||
);
|
||||
});
|
||||
|
||||
const rest = new REST().setToken(secrets.DISCORD_TOKEN);
|
||||
const rest = new REST().setToken(assertSecrete(process.env.DISCORD_TOKEN));
|
||||
|
||||
commands.then((awaitedCommands) => {
|
||||
const body = Object.values(awaitedCommands).map((registry) =>
|
||||
registry.command.toJSON(),
|
||||
);
|
||||
|
||||
rest.put(Routes.applicationCommands(secrets.DISCORD_CLIENT_ID), { body });
|
||||
rest.put(
|
||||
Routes.applicationCommands(assertSecrete(process.env.DISCORD_CLIENT_ID)),
|
||||
{
|
||||
body,
|
||||
},
|
||||
);
|
||||
});
|
||||
|
||||
export default async function interactionCreate(
|
||||
|
||||
+3
-2
@@ -1,8 +1,9 @@
|
||||
import { registerProcesses } from '../core/blitzkit/processes';
|
||||
import { secrets } from '../core/blitzkit/secrets';
|
||||
import { assertSecrete } from '../core/blitzkit/secrete';
|
||||
import { client } from '../core/discord/client';
|
||||
|
||||
console.log(`🟡 Launching bot ${client.shard?.ids[0]}`);
|
||||
|
||||
registerProcesses();
|
||||
client.login(secrets.DISCORD_TOKEN);
|
||||
|
||||
client.login(assertSecrete(process.env.DISCORD_TOKEN));
|
||||
Reference in new issue
Block a user