Files
blitzkit/packages/website-ue/src/api/client.ts
T

149 lines
3.0 KiB
TypeScript
Raw Normal View History

2025-12-26 14:59:09 -06:00
import { fetchPB } from "@blitzkit/core";
2026-01-13 20:15:55 -06:00
import type { Strings } from "@blitzkit/i18n";
2026-05-15 22:46:36 -05:00
import { Avatars } from "@protos/avatars";
2026-05-20 13:09:19 -05:00
import { Consumables } from "@protos/consumables";
2026-05-17 12:56:23 -05:00
import { Equipment } from "@protos/equipment";
2026-05-15 22:46:36 -05:00
import { PopularTanks } from "@protos/popular_tanks";
2026-05-20 13:48:20 -05:00
import { Sets } from "@protos/sets";
2026-05-15 22:46:36 -05:00
import { TankList } from "@protos/tank_list";
2026-05-19 14:03:07 -05:00
import { TankUpgradePresets } from "@protos/tank_upgrade_presets";
2026-05-15 22:46:36 -05:00
import { Tanks } from "@protos/tanks";
2026-05-20 13:09:19 -05:00
import { TierPrices } from "@protos/tier_prices";
2026-05-15 22:46:36 -05:00
import { Tiers } from "@protos/tiers";
2026-03-23 18:06:26 -05:00
import { AbstractAPI, Cache } from "./abstract";
2026-05-17 12:56:23 -05:00
function rejected() {
return Promise.reject("Not implemented on client");
}
2025-11-28 13:51:17 -06:00
2025-11-30 22:12:46 -06:00
export class ClientAPI extends AbstractAPI {
2026-05-15 10:54:36 -05:00
get metadata(): never {
throw new Error("MetadataAccessor is inaccessible on the client");
}
2026-05-18 16:32:46 -05:00
@UnimplementedOnClient
mediaPrefix(): never {
throw rejected();
}
2026-04-26 19:44:27 -05:00
@Cache()
2026-03-23 18:06:26 -05:00
tankList() {
2026-04-26 19:44:27 -05:00
return fetchPB("/api/tanks/list.pb", TankList);
2025-11-30 22:12:46 -06:00
}
2026-01-13 13:30:09 -06:00
2026-03-23 18:06:26 -05:00
@Cache()
2026-04-27 14:39:47 -05:00
async tank(id: string) {
const tanks = await this.tanks();
return tanks.tanks[id];
2026-01-13 13:30:09 -06:00
}
2026-04-27 14:39:47 -05:00
@Cache()
2026-03-23 18:06:26 -05:00
tanks() {
2026-04-27 14:39:47 -05:00
return fetchPB("/api/tanks/all.pb", Tanks);
2026-01-13 13:30:09 -06:00
}
2026-01-13 20:15:55 -06:00
2026-03-23 18:06:26 -05:00
@Cache()
popularTanks() {
2026-03-15 22:37:46 -05:00
return fetchPB("/api/tanks/popular.pb", PopularTanks);
}
2026-05-15 10:54:36 -05:00
@Cache()
2026-05-19 14:03:07 -05:00
tankUpgradePresets() {
return fetchPB(`/api/tanks/upgrades.pb`, TankUpgradePresets);
2026-05-15 10:54:36 -05:00
}
2026-04-27 19:34:06 -05:00
@Cache()
tiers() {
return fetchPB("/api/tiers.pb", Tiers);
}
2026-05-17 12:56:23 -05:00
@Cache()
equipment() {
return fetchPB("/api/equipment.pb", Equipment);
}
2026-05-20 13:09:19 -05:00
@Cache()
consumables() {
return fetchPB("/api/consumables.pb", Consumables);
}
@Cache()
tierPrices() {
return fetchPB("/api/tier-prices.pb", TierPrices);
}
2026-05-20 13:48:20 -05:00
@Cache()
sets() {
return fetchPB("/api/sets.pb", Sets);
}
2026-03-23 18:06:26 -05:00
@Cache()
async strings(locale: string) {
const response = await fetch(`/api/strings/${locale}.json`);
const json = (await response.json()) as Strings;
return json;
}
@UnimplementedOnClient
gameStrings() {
2026-05-17 12:56:23 -05:00
return rejected();
2026-03-23 18:06:26 -05:00
}
@Cache()
protected async _groupedGameStrings(locale: string, group: string) {
const response = await fetch(`/api/game-strings/${locale}/${group}.json`);
const json = (await response.json()) as Record<string, string>;
return json;
}
@UnimplementedOnClient
gameStringGroups() {
2026-05-17 12:56:23 -05:00
return rejected();
2026-03-23 18:06:26 -05:00
}
@UnimplementedOnClient
avatar() {
2026-05-17 12:56:23 -05:00
return rejected();
2026-03-23 18:06:26 -05:00
}
avatars() {
return fetchPB("/api/avatars/all.pb", Avatars);
}
@UnimplementedOnClient
avatarList() {
2026-05-17 12:56:23 -05:00
return rejected();
2026-03-23 18:06:26 -05:00
}
@UnimplementedOnClient
background() {
2026-05-17 12:56:23 -05:00
return rejected();
2026-03-23 18:06:26 -05:00
}
@UnimplementedOnClient
backgrounds() {
2026-05-17 12:56:23 -05:00
return rejected();
}
@UnimplementedOnClient
currencyIcon() {
return rejected();
2026-03-15 22:37:46 -05:00
}
2026-05-18 17:08:12 -05:00
@UnimplementedOnClient
stuffIcon() {
return rejected();
}
2025-11-30 22:12:46 -06:00
}
2026-03-23 18:06:26 -05:00
function UnimplementedOnClient(
_target: unknown,
propertyKey: string,
descriptor: PropertyDescriptor,
) {
descriptor.value = function () {
throw new Error(`${propertyKey} is not implemented on the client`);
};
}