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