mirror of
https://github.com/blitzkit/blitzkit.git
synced 2026-10-23 11:39:50 +02:00
fix: port to core 3
This commit is contained in:
1 parent
5e989a16bc
commit
de6a4d5675
29 files changed
+27
-20
No files matched your search
@@ -1,11 +0,0 @@
|
||||
import { asset } from '@blitzkit/core';
|
||||
|
||||
export interface DiscoveredIdsDefinitions {
|
||||
time: number;
|
||||
chunks: number;
|
||||
count: number;
|
||||
}
|
||||
|
||||
export const discoveredIdsDefinitions = fetch(asset('ids/manifest.json')).then(
|
||||
(response) => response.json() as Promise<DiscoveredIdsDefinitions>,
|
||||
);
|
||||
@@ -1,3 +0,0 @@
|
||||
export function emblemURL(emblemId: number) {
|
||||
return `https://wotblitz-gc.gcdn.co/icons/clanEmblems1x/clan-icon-v2-${emblemId}.png`;
|
||||
}
|
||||
@@ -1,9 +0,0 @@
|
||||
import { usersDatabase } from '@blitzkit/core';
|
||||
|
||||
export async function flagUserActivity(blitzId: number) {
|
||||
await usersDatabase.user.upsert({
|
||||
where: { blitz_id: blitzId },
|
||||
update: {},
|
||||
create: { blitz_id: blitzId },
|
||||
});
|
||||
}
|
||||
@@ -1,20 +0,0 @@
|
||||
import { Region } from '@blitzkit/core';
|
||||
|
||||
const TIME_ZONE_MAPPINGS: Record<Region, number> = {
|
||||
com: -5, // Central North American Time
|
||||
eu: +1, // Central European Time
|
||||
asia: +7, // Central Asia Standard Time
|
||||
};
|
||||
|
||||
export function getTimeDaysAgo(region: Region, daysAgo: number) {
|
||||
const now = new Date();
|
||||
if (daysAgo === 0) now.getTime() / 1000;
|
||||
|
||||
const time = new Date();
|
||||
|
||||
time.setUTCHours(-TIME_ZONE_MAPPINGS[region], 0, 0, 0);
|
||||
if (time > now) time.setUTCDate(time.getUTCDate() - 1);
|
||||
time.setUTCDate(time.getUTCDate() - daysAgo + 1);
|
||||
|
||||
return time.getTime() / 1000;
|
||||
}
|
||||
@@ -1,16 +0,0 @@
|
||||
import sharp from 'sharp';
|
||||
|
||||
const cache: Record<string, Buffer> = {};
|
||||
|
||||
export async function iconPng(url: string) {
|
||||
if (!url.endsWith('.webp')) return url;
|
||||
|
||||
if (!cache[url]) {
|
||||
const imageResponse = await fetch(url);
|
||||
const imageBufferWEBP = await imageResponse.arrayBuffer();
|
||||
const imageBufferPNG = await sharp(imageBufferWEBP).png().toBuffer();
|
||||
cache[url] = imageBufferPNG;
|
||||
}
|
||||
|
||||
return `data:image/png;base64,${cache[url].toString('base64')}`;
|
||||
}
|
||||
@@ -1,5 +0,0 @@
|
||||
export function isLocalhost() {
|
||||
return (
|
||||
typeof window !== 'undefined' && window.location.hostname === 'localhost'
|
||||
);
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
import { usersDatabase } from '@blitzkit/core';
|
||||
import { flagUserActivity } from './flagUserActivity';
|
||||
|
||||
export async function linkBlitzAndDiscord(discordId: bigint, blitzId: number) {
|
||||
await usersDatabase.discordUser.upsert({
|
||||
where: { discord_id: discordId },
|
||||
update: { blitz_id: blitzId },
|
||||
create: { discord_id: discordId, blitz_id: blitzId },
|
||||
});
|
||||
await flagUserActivity(blitzId);
|
||||
}
|
||||
@@ -1,12 +0,0 @@
|
||||
import { asset, fetchCdonLz4 } from '@blitzkit/core';
|
||||
|
||||
export interface MapDefinitions {
|
||||
[id: number]: {
|
||||
id: number;
|
||||
name: string;
|
||||
};
|
||||
}
|
||||
|
||||
export const mapDefinitions = fetchCdonLz4<MapDefinitions>(
|
||||
asset('definitions/maps.cdon.lz4'),
|
||||
);
|
||||
@@ -1,9 +0,0 @@
|
||||
import { assertSecret } from '@blitzkit/core';
|
||||
import { throttling } from '@octokit/plugin-throttling';
|
||||
import { Octokit } from '@octokit/rest';
|
||||
|
||||
Octokit.plugin(throttling);
|
||||
|
||||
export const octokit = new Octokit({
|
||||
auth: assertSecret(process.env.GH_TOKEN),
|
||||
});
|
||||
@@ -1,20 +0,0 @@
|
||||
import { BKNI_COLORS, BkniPercentile, getBkniPercentile } from '@blitzkit/core';
|
||||
|
||||
export function parseBkni(bkni: number) {
|
||||
const bkniFraction = (bkni + 1) / 2;
|
||||
const bkniMetric = Math.round(bkniFraction * 200);
|
||||
const bkniPercentile = getBkniPercentile(bkniMetric);
|
||||
const lastBkniPercentile = Math.max(0, bkniPercentile - 1) as BkniPercentile;
|
||||
const bkniColor = BKNI_COLORS[bkniPercentile];
|
||||
const lastBkniColor = BKNI_COLORS[lastBkniPercentile];
|
||||
|
||||
return {
|
||||
bkni,
|
||||
bkniFraction,
|
||||
bkniMetric,
|
||||
bkniPercentile,
|
||||
lastBkniPercentile,
|
||||
bkniColor,
|
||||
lastBkniColor,
|
||||
};
|
||||
}
|
||||
@@ -1,21 +0,0 @@
|
||||
export async function patientFetch(
|
||||
url: string,
|
||||
timeout = 1000,
|
||||
options?: Partial<{ cache: 'no-store' }>,
|
||||
) {
|
||||
let patientResponse: Response;
|
||||
|
||||
while (patientResponse! === undefined) {
|
||||
try {
|
||||
patientResponse = await fetch(url, options);
|
||||
} catch (error) {
|
||||
console.warn(
|
||||
`Failed to fetch ${url}; retrying in ${timeout}ms...`,
|
||||
error,
|
||||
);
|
||||
await new Promise((resolve) => setTimeout(resolve, timeout));
|
||||
}
|
||||
}
|
||||
|
||||
return patientResponse;
|
||||
}
|
||||
@@ -1,23 +0,0 @@
|
||||
export async function patientFetchJSON<Type extends object>(
|
||||
url: string,
|
||||
timeout = 1000,
|
||||
options?: Partial<{ cache: 'no-store' }>,
|
||||
) {
|
||||
let patientJSON: Type;
|
||||
|
||||
while (patientJSON! === undefined) {
|
||||
try {
|
||||
patientJSON = (await fetch(url, options).then((response) =>
|
||||
response.json(),
|
||||
)) as Type;
|
||||
} catch (error) {
|
||||
console.warn(
|
||||
`Failed to fetch ${url} as JSON; retrying in ${timeout}ms...`,
|
||||
error,
|
||||
);
|
||||
await new Promise((resolve) => setTimeout(resolve, timeout));
|
||||
}
|
||||
}
|
||||
|
||||
return patientJSON;
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
export interface RenderConfiguration {
|
||||
width: number;
|
||||
}
|
||||
|
||||
export class RenderConfiguration implements RenderConfiguration {
|
||||
width = 480;
|
||||
|
||||
constructor(configuration?: Partial<RenderConfiguration>) {
|
||||
Object.assign(this, configuration);
|
||||
}
|
||||
}
|
||||
@@ -1,6 +0,0 @@
|
||||
import { tankIcon } from '@blitzkit/core';
|
||||
import { iconPng } from './iconPng';
|
||||
|
||||
export function tankIconPng(id: number) {
|
||||
return iconPng(tankIcon(id));
|
||||
}
|
||||
@@ -1,9 +0,0 @@
|
||||
import { BlitzkitResponse } from '../../hooks/useTankVotes';
|
||||
|
||||
export function unwrapBlitzkitResponse<Data>(response: BlitzkitResponse<Data>) {
|
||||
if (response.status === 'error') {
|
||||
throw new Error(response.error, { cause: response.message });
|
||||
}
|
||||
|
||||
return response.data;
|
||||
}
|
||||
@@ -1,7 +0,0 @@
|
||||
import { context } from '@blitzkit/core/src/blitzkit/context';
|
||||
|
||||
export function withCORSProxy(url: string) {
|
||||
return context === 'website'
|
||||
? `https://corsproxy.io/?${encodeURIComponent(url)}`
|
||||
: url;
|
||||
}
|
||||
Reference in new issue
Block a user