mirror of
https://github.com/blitzkit/blitzkit.git
synced 2026-10-23 19:49:50 +02:00
fix: port to core 1
This commit is contained in:
1 parent
fd2e2f9c7b
commit
5e989a16bc
24 files changed
+24
-14
No files matched your search
@@ -1,5 +0,0 @@
|
||||
import { ShellDefinition, ShellType } from '@blitzkit/core';
|
||||
|
||||
export function canSplash(type: ShellDefinition['type']): type is ShellType.HE {
|
||||
return type === ShellType.HE;
|
||||
}
|
||||
@@ -1,6 +0,0 @@
|
||||
import { getRatingInfo } from '@blitzkit/core';
|
||||
|
||||
export async function isOnGoingRatingSeason() {
|
||||
const ratingInfo = await getRatingInfo('com');
|
||||
return ratingInfo.detail === undefined;
|
||||
}
|
||||
@@ -1,30 +0,0 @@
|
||||
import { Region, assertSecret, idToRegion } from '@blitzkit/core';
|
||||
|
||||
export async function isValidBlitzId(id: number, token?: string) {
|
||||
let region: Region;
|
||||
|
||||
try {
|
||||
region = idToRegion(id);
|
||||
} catch (error) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const json = await fetch(
|
||||
`https://api.wotblitz.${region}/wotb/account/info/?account_id=${id}&application_id=${assertSecret(
|
||||
process.env.NEXT_PUBLIC_WARGAMING_APPLICATION_ID,
|
||||
)}${
|
||||
token === undefined ? '' : `&access_token=${token}`
|
||||
}&fields=account_id%2C-account_id`,
|
||||
).then(
|
||||
(response) =>
|
||||
response.json() as Promise<
|
||||
| {
|
||||
status: 'ok';
|
||||
data: Record<number, {} | null>;
|
||||
}
|
||||
| { status: 'error' }
|
||||
>,
|
||||
);
|
||||
|
||||
return json.status === 'ok' && json.data[id] !== null;
|
||||
}
|
||||
@@ -1,3 +0,0 @@
|
||||
export function normalizeExtra(extra?: string[]) {
|
||||
return extra ? `&extra=${extra.join(',')}` : '';
|
||||
}
|
||||
@@ -1,3 +0,0 @@
|
||||
export function normalizeIds(ids: number | number[]): string {
|
||||
return typeof ids === 'number' ? ids.toString() : ids.join(',');
|
||||
}
|
||||
@@ -1,5 +0,0 @@
|
||||
import { Region, RegionSubdomain } from '@blitzkit/core';
|
||||
|
||||
export function regionToRegionSubdomain(regionDomain: Region): RegionSubdomain {
|
||||
return regionDomain === 'com' ? 'na' : regionDomain;
|
||||
}
|
||||
@@ -1,40 +0,0 @@
|
||||
import { Region } from '@blitzkit/core';
|
||||
import { context } from '../blitzkit/context';
|
||||
import { regionToRegionSubdomain } from './regionToRegionSubdomain';
|
||||
|
||||
type CurrentRatingPlayerSearch = Record<
|
||||
number,
|
||||
{
|
||||
spa_id: number;
|
||||
nickname: string;
|
||||
clan_tag: string;
|
||||
} & (
|
||||
| {
|
||||
skip: true;
|
||||
}
|
||||
| {
|
||||
skip: false;
|
||||
mmr: number;
|
||||
season_number: number;
|
||||
calibrationBattlesLeft: number;
|
||||
number: number;
|
||||
updated_at: string;
|
||||
neighbors: [];
|
||||
}
|
||||
)
|
||||
>;
|
||||
|
||||
export async function searchCurrentRatingPlayers(region: Region, name: string) {
|
||||
const encodedSearch = encodeURIComponent(name);
|
||||
const response = await fetch(
|
||||
context === 'website'
|
||||
? `/api/${region}/rating/current/search/${encodedSearch}`
|
||||
: `https://${regionToRegionSubdomain(
|
||||
region,
|
||||
)}.wotblitz.com/en/api/rating-leaderboards/search/?prefix=${encodedSearch}`,
|
||||
{ cache: 'no-store' },
|
||||
);
|
||||
const accountList = (await response.json()) as CurrentRatingPlayerSearch;
|
||||
|
||||
return accountList;
|
||||
}
|
||||
@@ -1,5 +0,0 @@
|
||||
import { NATION_IDS } from "@blitzkit/core";
|
||||
|
||||
export function toUniqueId(nation: string, id: number) {
|
||||
return (id << 8) + (NATION_IDS[nation] << 4) + 1;
|
||||
}
|
||||
@@ -1,64 +0,0 @@
|
||||
import { crc32 } from 'crc';
|
||||
import { compressBlock } from 'lz4js';
|
||||
|
||||
/**
|
||||
* Thanks Maddoxkkm! Modernized heavily.
|
||||
*
|
||||
* https://github.com/Maddoxkkm/dvpl_converter/
|
||||
*/
|
||||
export function writeDVPL(buffer: Buffer) {
|
||||
const source = new Uint8Array(buffer);
|
||||
const destination = new Uint8Array(buffer.length);
|
||||
const compressedBlockSize = compressBlock(
|
||||
source,
|
||||
destination,
|
||||
0,
|
||||
source.length,
|
||||
0,
|
||||
);
|
||||
let output = Buffer.from(destination);
|
||||
|
||||
if (compressedBlockSize === 0 || compressedBlockSize >= buffer.length) {
|
||||
const footerBuffer = toDVPLFooter(
|
||||
buffer.length,
|
||||
buffer.length,
|
||||
crc32(buffer),
|
||||
0,
|
||||
);
|
||||
|
||||
return Buffer.concat(
|
||||
[new Uint8Array(buffer), new Uint8Array(footerBuffer)],
|
||||
buffer.length + 20,
|
||||
);
|
||||
} else {
|
||||
output = output.subarray(0, compressedBlockSize);
|
||||
const footerBuffer = toDVPLFooter(
|
||||
buffer.length,
|
||||
compressedBlockSize,
|
||||
crc32(output),
|
||||
2,
|
||||
);
|
||||
|
||||
return Buffer.concat(
|
||||
[new Uint8Array(output), new Uint8Array(footerBuffer)],
|
||||
compressedBlockSize + 20,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
function toDVPLFooter(
|
||||
inputSize: number,
|
||||
compressedSize: number,
|
||||
crc32: number,
|
||||
type: number,
|
||||
) {
|
||||
const result = Buffer.alloc(20);
|
||||
|
||||
result.writeUInt32LE(inputSize, 0);
|
||||
result.writeUInt32LE(compressedSize, 4);
|
||||
result.writeUInt32LE(crc32, 8);
|
||||
result.writeUInt32LE(type, 12);
|
||||
result.write('DVPL', 16, 4, 'utf8');
|
||||
|
||||
return result;
|
||||
}
|
||||
Reference in new issue
Block a user