mirror of
https://github.com/blitzkit/blitzkit.git
synced 2026-10-23 03:29:51 +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,5 +1,5 @@
|
||||
import { assertSecret, EventManager, Region } from '@blitzkit/core';
|
||||
import { patientFetch } from '../../../website/src/core/blitzkit/patientFetch';
|
||||
import { patientFetch } from '../blitzkit/patientFetch';
|
||||
|
||||
const RETRY_ERRORS = ['REQUEST_LIMIT_EXCEEDED', 'SOURCE_NOT_AVAILABLE'];
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { RatingInfo, Region } from '@blitzkit/core';
|
||||
import { patientFetch } from '../../../website/src/core/blitzkit/patientFetch';
|
||||
import { context } from '../blitzkit/context';
|
||||
import { patientFetch } from '../blitzkit/patientFetch';
|
||||
import { regionToRegionSubdomain } from './regionToRegionSubdomain';
|
||||
|
||||
const cache: Partial<Record<Region, RatingInfo>> = {};
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { LeagueTop, RatingPlayer, Region } from '@blitzkit/core';
|
||||
import { patientFetch } from '../../../website/src/core/blitzkit/patientFetch';
|
||||
import { context } from '../blitzkit/context';
|
||||
import { patientFetch } from '../blitzkit/patientFetch';
|
||||
import { regionToRegionSubdomain } from './regionToRegionSubdomain';
|
||||
|
||||
export async function getRatingLeague(
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { RatingNeighbors, Region } from '@blitzkit/core';
|
||||
import { patientFetch } from '../../../website/src/core/blitzkit/patientFetch';
|
||||
import { withCORSProxy } from '../../../website/src/core/blitzkit/withCORSProxy';
|
||||
import { patientFetch } from '../blitzkit/patientFetch';
|
||||
import { withCORSProxy } from '../blitzkit/withCORSProxy';
|
||||
import { regionToRegionSubdomain } from './regionToRegionSubdomain';
|
||||
|
||||
export async function getRatingNeighbors(
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
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>,
|
||||
);
|
||||
@@ -0,0 +1,3 @@
|
||||
export function emblemURL(emblemId: number) {
|
||||
return `https://wotblitz-gc.gcdn.co/icons/clanEmblems1x/clan-icon-v2-${emblemId}.png`;
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
import { usersDatabase } from '@blitzkit/core';
|
||||
|
||||
export async function flagUserActivity(blitzId: number) {
|
||||
await usersDatabase.user.upsert({
|
||||
where: { blitz_id: blitzId },
|
||||
update: {},
|
||||
create: { blitz_id: blitzId },
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
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;
|
||||
}
|
||||
@@ -9,18 +9,28 @@ export * from './consumableDefinitions';
|
||||
export * from './context';
|
||||
export * from './createDefaultSkills';
|
||||
export * from './degressiveStat';
|
||||
export * from './discoveredIdDefinitions';
|
||||
export * from './emblemURL';
|
||||
export * from './equipmentDefinitions';
|
||||
export * from './eventManager';
|
||||
export * from './fetchCdonLz4';
|
||||
export * from './filterTank';
|
||||
export * from './flagUserActivity';
|
||||
export * from './gameDefinitions';
|
||||
export * from './getArchivedLatestSeasonNumber';
|
||||
export * from './getArchivedRatingInfo';
|
||||
export * from './getArchivedRatingLeaderboard';
|
||||
export * from './getArchivedRatingMidnightLeaderboard';
|
||||
export * from './getTimeDaysAgo';
|
||||
export * from './isExplosive';
|
||||
export * from './linkBlitzAndDiscord';
|
||||
export * from './mapDefinitions';
|
||||
export * from './modelDefinitions';
|
||||
export * from './normalizeBoundingBox';
|
||||
export * from './octokit';
|
||||
export * from './parseBkni';
|
||||
export * from './patientFetch';
|
||||
export * from './patientFetchJSON';
|
||||
export * from './progressiveStat';
|
||||
export * from './provisionDefinitions';
|
||||
export * from './resolveDpm';
|
||||
@@ -36,5 +46,7 @@ export * from './tankIcon';
|
||||
export * from './tankNames';
|
||||
export * from './unionBoundingBox';
|
||||
export * from './uniqueGuns';
|
||||
export * from './unwrapBlitzkitResponse';
|
||||
export * from './votes';
|
||||
export * from './withCORSProxy';
|
||||
export * from './youtubers';
|
||||
@@ -0,0 +1,11 @@
|
||||
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);
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
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'),
|
||||
);
|
||||
@@ -0,0 +1,9 @@
|
||||
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),
|
||||
});
|
||||
@@ -0,0 +1,20 @@
|
||||
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,
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
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;
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
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;
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
import { BlitzkitResponse } from '../../../website/src/hooks/useTankVotes';
|
||||
|
||||
export function unwrapBlitzkitResponse<Data>(response: BlitzkitResponse<Data>) {
|
||||
if (response.status === 'error') {
|
||||
throw new Error(response.error, { cause: response.message });
|
||||
}
|
||||
|
||||
return response.data;
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
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