mirror of
https://github.com/blitzkit/blitzkit.git
synced 2026-10-23 11:39:50 +02:00
glossary
This commit is contained in:
1 parent
851a1108d2
commit
bc2b9f1267
10 files changed
+174
-15
No files matched your search
@@ -4,8 +4,8 @@ import type { BlitzGlossary } from "../types";
|
||||
export async function fetchGlossary(locale: string) {
|
||||
const response = await fetch(
|
||||
`${assertSecret(
|
||||
import.meta.env.WOTB_GLOSSARY_DOMAIN
|
||||
)}/${locale}${assertSecret(import.meta.env.WOTB_GLOSSARY_PATH)}`
|
||||
import.meta.env.WOTB_GLOSSARY_DOMAIN,
|
||||
)}/${locale}${assertSecret(import.meta.env.WOTB_GLOSSARY_PATH)}`,
|
||||
);
|
||||
return (await response.json()) as BlitzGlossary;
|
||||
}
|
||||
@@ -2,6 +2,7 @@ import {
|
||||
CamouflageDefinitions,
|
||||
ConsumableDefinitions,
|
||||
EquipmentDefinitions,
|
||||
Gallery,
|
||||
GameDefinitions,
|
||||
MapDefinitions,
|
||||
ModelDefinitions,
|
||||
@@ -20,4 +21,5 @@ export abstract class BlitzKitAPI {
|
||||
abstract camouflageDefinitions(): Promise<CamouflageDefinitions>;
|
||||
abstract tankDefinitions(): Promise<TankDefinitions>;
|
||||
abstract gameDefinitions(): Promise<GameDefinitions>;
|
||||
abstract galleryDefinitions(): Promise<Gallery>;
|
||||
}
|
||||
@@ -3,6 +3,7 @@ import {
|
||||
CamouflageDefinitions,
|
||||
ConsumableDefinitions,
|
||||
EquipmentDefinitions,
|
||||
Gallery,
|
||||
GameDefinitions,
|
||||
ModelDefinitions,
|
||||
ProvisionDefinitions,
|
||||
@@ -43,4 +44,8 @@ export class ClientBlitzKitAPI extends BlitzKitAPI {
|
||||
equipmentDefinitions() {
|
||||
return fetchPB("/api/definitions/equipment.pb", EquipmentDefinitions);
|
||||
}
|
||||
|
||||
galleryDefinitions() {
|
||||
return fetchPB("/api/definitions/gallery.pb", Gallery);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,67 @@
|
||||
import { Avatar, fetchGlossary, Gallery } from "@blitzkit/core";
|
||||
import { ServerBlitzKitAPI9 } from "@blitzkit/core/src/blitzkit/api/server/9_gameDefinitions";
|
||||
import locales from "@blitzkit/i18n/locales.json";
|
||||
import { extname } from "path";
|
||||
import { Cache } from "./0_base";
|
||||
|
||||
export abstract class ServerBlitzKitAPI10 extends ServerBlitzKitAPI9 {
|
||||
@Cache()
|
||||
async galleryDefinitions() {
|
||||
const avatars: Record<string, { avatar: Avatar; url: string }> = {};
|
||||
|
||||
await Promise.all(
|
||||
locales.supported.map(async (supported) => {
|
||||
const glossary = await fetchGlossary(
|
||||
supported.blitz ?? supported.locale,
|
||||
);
|
||||
|
||||
console.log(
|
||||
`Found ${Object.keys(glossary).length} things for ${supported.locale}`,
|
||||
);
|
||||
|
||||
for (const key in glossary) {
|
||||
const glossaryEntry = glossary[key];
|
||||
|
||||
if (
|
||||
!key.startsWith("avatar") ||
|
||||
key.endsWith("_part") ||
|
||||
glossaryEntry.image_url === null
|
||||
) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (key in avatars) {
|
||||
avatars[key].avatar.name!.locales[supported.locale] =
|
||||
glossaryEntry.title;
|
||||
} else {
|
||||
const extension = extname(glossaryEntry.image_url);
|
||||
|
||||
avatars[key] = {
|
||||
url: glossaryEntry.image_url,
|
||||
avatar: {
|
||||
id: key,
|
||||
name: { locales: { [supported.locale]: glossaryEntry.title } },
|
||||
extension,
|
||||
},
|
||||
};
|
||||
}
|
||||
}
|
||||
}),
|
||||
);
|
||||
|
||||
const gallery: Gallery = { avatars: [] };
|
||||
|
||||
await Promise.all(
|
||||
Object.entries(avatars).map(async ([key, { url, avatar }]) => {
|
||||
if (!(locales.default in avatars[key].avatar.name!.locales)) {
|
||||
console.warn(`Avatar ${key} has no ${locales.default} name`);
|
||||
return;
|
||||
}
|
||||
|
||||
gallery.avatars.push(avatar);
|
||||
}),
|
||||
);
|
||||
|
||||
return gallery;
|
||||
}
|
||||
}
|
||||
@@ -1,3 +1,3 @@
|
||||
import { ServerBlitzKitAPI9 } from "./9_gameDefinitions";
|
||||
import { ServerBlitzKitAPI10 } from "@blitzkit/core/src/blitzkit/api/server/10_galleryDefinitions";
|
||||
|
||||
export class ServerBlitzKitAPI extends ServerBlitzKitAPI9 {}
|
||||
export class ServerBlitzKitAPI extends ServerBlitzKitAPI10 {}
|
||||
Reference in new issue
Block a user