mirror of
https://github.com/BTMuli/TeyvatGuide.git
synced 2025-12-14 09:38:13 +08:00
@@ -1,31 +1,61 @@
|
||||
/**
|
||||
* @file web request getAnnouncement.ts
|
||||
* @file web/request/getAnnouncement.ts
|
||||
* @description 获取游戏内公告
|
||||
* @author BTMuli <bt-muli@outlook.com>
|
||||
* @since Beta v0.3.2
|
||||
* @since Beta v0.4.3
|
||||
*/
|
||||
|
||||
// Tauri
|
||||
import { http } from "@tauri-apps/api";
|
||||
|
||||
const params = {
|
||||
game: "hk4e",
|
||||
game_biz: "hk4e_cn",
|
||||
lang: "zh-cn",
|
||||
bundle_id: "hk4e_cn",
|
||||
platform: "pc",
|
||||
region: "cn_gf01",
|
||||
level: "60",
|
||||
uid: "500299765",
|
||||
};
|
||||
export enum SERVER {
|
||||
CN_ISLAND = "cn_gf01",
|
||||
CN_TREE = "cn_qd01",
|
||||
OS_USA = "os_usa",
|
||||
OS_EURO = "os_euro",
|
||||
OS_ASIA = "os_asia",
|
||||
OS_CHT = "os_cht",
|
||||
}
|
||||
|
||||
/**
|
||||
* @description 获取游戏内公告参数
|
||||
* @since Beta v0.4.3
|
||||
* @param {SERVER} region 服务器
|
||||
* @param {string} lang 语言
|
||||
* @returns {TGApp.BBS.Announcement.Params}
|
||||
*/
|
||||
function getAnnoParams(region: SERVER, lang: string = "zh-cn"): TGApp.BBS.Announcement.Params {
|
||||
const params: TGApp.BBS.Announcement.Params = {
|
||||
game: "hk4e",
|
||||
game_biz: "hk4e_cn",
|
||||
lang,
|
||||
bundle_id: "hk4e_cn",
|
||||
platform: "pc",
|
||||
region,
|
||||
level: "55",
|
||||
uid: "100000000",
|
||||
};
|
||||
if (region === SERVER.CN_ISLAND || region === SERVER.CN_TREE) {
|
||||
return params;
|
||||
}
|
||||
params.game_biz = "hk4e_global";
|
||||
params.bundle_id = "hk4e_global";
|
||||
return params;
|
||||
}
|
||||
|
||||
/**
|
||||
* @description 获取游戏内公告列表
|
||||
* @since Beta v0.3.2
|
||||
* @since Beta v0.4.3
|
||||
* @param {string} region 服务器
|
||||
* @param {string} lang 语言
|
||||
* @returns {Promise<TGApp.BBS.Announcement.ListData>}
|
||||
*/
|
||||
export async function getAnnoList(): Promise<TGApp.BBS.Announcement.ListData> {
|
||||
const url = "https://hk4e-api.mihoyo.com/common/hk4e_cn/announcement/api/getAnnList";
|
||||
export async function getAnnoList(
|
||||
region: SERVER = SERVER.CN_ISLAND,
|
||||
lang: string = "zh-cn",
|
||||
): Promise<TGApp.BBS.Announcement.ListData> {
|
||||
const params: TGApp.BBS.Announcement.Params = getAnnoParams(region, lang);
|
||||
let url = "https://hk4e-api.mihoyo.com/common/hk4e_cn/announcement/api/getAnnList";
|
||||
if (region !== SERVER.CN_ISLAND && region !== SERVER.CN_TREE) {
|
||||
url = "https://hk4e-api-os.hoyoverse.com/common/hk4e_global/announcement/api/getAnnList";
|
||||
}
|
||||
return await http
|
||||
.fetch<TGApp.BBS.Announcement.ListResponse>(url, {
|
||||
method: "GET",
|
||||
@@ -36,12 +66,22 @@ export async function getAnnoList(): Promise<TGApp.BBS.Announcement.ListData> {
|
||||
|
||||
/**
|
||||
* @description 获取游戏内公告内容
|
||||
* @since Beta v0.3.2
|
||||
* @since Beta v0.4.3
|
||||
* @param {number} annId 公告 ID
|
||||
* @param {SERVER} region 服务器
|
||||
* @param {string} lang 语言
|
||||
* @returns {Promise<TGApp.BBS.Announcement.ContentItem>}
|
||||
*/
|
||||
export async function getAnnoContent(annId: number): Promise<TGApp.BBS.Announcement.ContentItem> {
|
||||
const url = "https://hk4e-api.mihoyo.com/common/hk4e_cn/announcement/api/getAnnContent";
|
||||
export async function getAnnoContent(
|
||||
annId: number,
|
||||
region: SERVER,
|
||||
lang: string = "zh-cn",
|
||||
): Promise<TGApp.BBS.Announcement.ContentItem> {
|
||||
const params: TGApp.BBS.Announcement.Params = getAnnoParams(region, lang);
|
||||
let url = "https://hk4e-api.mihoyo.com/common/hk4e_cn/announcement/api/getAnnContent";
|
||||
if (region !== SERVER.CN_ISLAND && region !== SERVER.CN_TREE) {
|
||||
url = "https://hk4e-api-os.hoyoverse.com/common/hk4e_global/announcement/api/getAnnContent";
|
||||
}
|
||||
const annoContents: TGApp.BBS.Announcement.ContentItem[] = await http
|
||||
.fetch<TGApp.BBS.Announcement.ContentResponse>(url, {
|
||||
method: "GET",
|
||||
|
||||
@@ -9,7 +9,7 @@ const defaultCover = "/source/UI/defaultCover.webp";
|
||||
|
||||
/**
|
||||
* @description 将获取到的数据转为渲染用的卡片
|
||||
* @since Beta v0.3.3
|
||||
* @since Beta v0.4.3
|
||||
* @param {TGApp.BBS.Announcement.ListData[]} data 公告数据
|
||||
* @returns {TGApp.App.Announcement.ListCard[]} 渲染用的卡片
|
||||
*/
|
||||
@@ -27,7 +27,7 @@ export function getAnnoCard(
|
||||
title: anno.title,
|
||||
subtitle: anno.subtitle,
|
||||
banner: anno.banner || defaultCover,
|
||||
typeLabel: anno.type_label,
|
||||
typeLabel: anno.type === 2 ? "游戏公告" : "活动公告",
|
||||
tagIcon: anno.tag_icon,
|
||||
tagLabel: anno.tag_label,
|
||||
timeStr: time,
|
||||
|
||||
Reference in New Issue
Block a user