mirror of
https://github.com/Moe-Sakura/Wrangler-API.git
synced 2026-05-12 01:15:30 +08:00
优化 KunGalgameBuDingItem 接口,支持多语言名称解析
This commit is contained in:
@@ -6,7 +6,7 @@ const BASE_URL = "https://www.moyu.moe/patch/";
|
|||||||
|
|
||||||
interface KunGalgameBuDingItem {
|
interface KunGalgameBuDingItem {
|
||||||
id: number;
|
id: number;
|
||||||
name: string;
|
name?: Record<string, string | undefined> | string;
|
||||||
}
|
}
|
||||||
|
|
||||||
interface KunGalgameBuDingResponse {
|
interface KunGalgameBuDingResponse {
|
||||||
@@ -45,10 +45,23 @@ async function searchKunGalgameBuDing(game: string): Promise<PlatformSearchResul
|
|||||||
|
|
||||||
const data = await response.json() as KunGalgameBuDingResponse;
|
const data = await response.json() as KunGalgameBuDingResponse;
|
||||||
|
|
||||||
const items: SearchResultItem[] = data.galgames.map(item => ({
|
const items: SearchResultItem[] = data.galgames.map(item => {
|
||||||
name: item.name,
|
const nameByLocale = typeof item.name === "object" && item.name !== null
|
||||||
url: `${BASE_URL}${item.id}/introduction`,
|
? item.name
|
||||||
}));
|
: undefined;
|
||||||
|
const localizedName = nameByLocale
|
||||||
|
? (nameByLocale["zh-cn"]
|
||||||
|
|| nameByLocale["ja-jp"]
|
||||||
|
|| nameByLocale["en-us"])
|
||||||
|
: undefined;
|
||||||
|
const name = (localizedName && localizedName.trim())
|
||||||
|
|| (typeof item.name === "string" ? item.name : "");
|
||||||
|
|
||||||
|
return {
|
||||||
|
name,
|
||||||
|
url: `${BASE_URL}${item.id}/introduction`,
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
searchResult.items = items;
|
searchResult.items = items;
|
||||||
searchResult.count = items.length;
|
searchResult.count = items.length;
|
||||||
|
|||||||
Reference in New Issue
Block a user