🌱 新v版角色列表&详情请求 #121

This commit is contained in:
目棃
2024-08-15 17:53:13 +08:00
parent 8c94710c24
commit a2e9bae018
7 changed files with 486 additions and 227 deletions

403
src/types/Game/Avatar.d.ts vendored Normal file
View File

@@ -0,0 +1,403 @@
/**
* @file types/Game/Avatar.d.ts
* @description 游戏角色详情相关类型定义文件
* @since Beta v0.5.3
*/
/**
* @description 游戏角色详情相关类型定义命名空间
* @since Beta v0.5.3
* @namespace TGApp.Game.Avatar
* @memberof TGApp.Game
*/
declare namespace TGApp.Game.Avatar {
/**
* @description 角色列表数据返回类型
* @interface ListResponse
* @since Beta v0.5.3
* @extends TGApp.BBS.Response.BaseWithData
* @property {Avatar[]} data.list - 角色列表
* @return ListResponse
*/
interface ListResponse extends TGApp.BBS.Response.BaseWithData {
data: {
list: Avatar[];
};
}
/**
* @description 角色详情数据返回类型
* @interface DetailResponse
* @since Beta v0.5.3
* @extends TGApp.BBS.Response.BaseWithData
* @property {AvatarDetail} data - 角色详情
* @return DetailResponse
*/
interface DetailResponse extends TGApp.BBS.Response.BaseWithData {
data: AvatarDetail;
}
/**
* @description 角色列表数据类型
* @interface Avatar
* @since Beta v0.5.3
* @property {number} actived_constellation_num - 角色已激活命座数量
* @property {string} element - 角色元素
* @property {number} fetter - 角色好感等级
* @property {string} icon - 角色头像
* @property {number} id - 角色 ID
* @property {string} image - 角色全身像
* @property {boolean} is_chosen - 是否选中作为展示
* @property {number} level - 角色等级
* @property {string} name - 角色名称
* @property {number} rarity - 角色稀有度
* @property {string} side_icon - 角色侧边头像
* @property {Weapon} weapon - 角色武器
* @property {number} weapon_type - 角色武器类型 // todo: 需要查明枚举类型
* @return Avatar
*/
interface Avatar {
actived_constellation_num: number;
element: string;
fetter: number;
icon: string;
id: number;
image: string;
is_chosen: boolean;
level: number;
name: string;
rarity: number;
side_icon: string;
weapon: Weapon;
weapon_type: number;
}
/**
* @description 角色武器数据类型
* @interface Weapon
* @since Beta v0.5.3
* @property {number} affix_level - 武器精炼等级
* @property {string} icon - 武器图标
* @property {number} id - 武器 ID
* @property {number} level - 武器等级
* @property {number} rarity - 武器稀有度
* @property {number} type - 武器类型,与上面的 weapon_type 一致 // todo: 需要查明枚举类型
* @return Weapon
*/
interface Weapon {
affix_level: number;
icon: string;
id: number;
level: number;
rarity: number;
type: number;
}
/**
* @description 角色详情数据类型
* @interface AvatarDetail
* @since Beta v0.5.3
* @property {DetailList[]} list - 角色详情列表
* @property {PropMap[]} property_map - 角色属性映射
* @property {PropRecommend} relic_property_options - 圣遗物属性选项
* @property {Record<string, string>} relic_wiki - 圣遗物属性对应的百科
* @property {Record<string, string>} weapon_wiki - 武器属性对应的百科
* @property {Record<string, string>} avatar_wiki - 角色属性对应的百科
* @return AvatarDetail
*/
interface AvatarDetail {
list: DetailList[];
property_map: PropMap[];
relic_property_options: PropRecommend;
relic_wiki: Record<string, string>;
weapon_wiki: Record<string, string>;
avatar_wiki: Record<string, string>;
}
/**
* @description 角色详情列表数据类型
* @interface DetailList
* @since Beta v0.5.3
* @property {Avatar} base - 角色基础信息
* @property {WeaponDetail} weapon - 角色武器信息
* @property {Relic[]} relics - 角色圣遗物信息
* @property {Constellation[]} constellations - 角色命座信息
* @property {Costume[]} costumes - 角色时装信息
* @property {WeaponProp[]} selected_properties - 角色选中属性
* @property {WeaponProp[]} base_properties - 角色基础属性
* @property {WeaponProp[]} extra_properties - 角色额外属性
* @property {WeaponProp[]} element_properties - 角色元素属性
* @property {Skill[]} skills - 角色技能信息
* @property {RelicRecommendProp[]} recommend_relic_properties - 推荐圣遗物属性
* @return DetailList
*/
interface DetailList {
base: Avatar;
weapon: WeaponDetail;
relics: Relic[];
constellations: Constellation[];
costumes: Costume[];
selected_properties: WeaponProp[];
base_properties: WeaponProp[];
extra_properties: WeaponProp[];
element_properties: WeaponProp[];
skills: Skill[];
recommend_relic_properties: RelicRecommendProp[];
}
/**
* @description 角色详情武器数据类型
* @interface WeaponDetail
* @since Beta v0.5.3
* @property {number} id - 武器 ID
* @property {string} name - 武器名称
* @property {string} icon - 武器图标
* @property {number} type - 武器类型
* @property {number} rarity - 武器稀有度
* @property {number} level - 武器等级
* @property {number} promote_level - 武器突破等级
* @property {string} type_name - 武器类型名称
* @property {string} desc - 武器描述
* @property {number} affix_level - 武器精炼等级
* @property {WeaponProp} main_property - 武器主属性
* @property {WeaponProp} sub_property - 武器副属性
* @return WeaponDetail
*/
interface WeaponDetail {
id: number;
name: string;
icon: string;
type: number;
rarity: number;
level: number;
promote_level: number;
type_name: string;
desc: string;
affix_level: number;
main_property: WeaponProp;
sub_property: WeaponProp;
}
/**
* @description 角色详情武器属性数据类型
* @interface WeaponProp
* @since Beta v0.5.3
* @property {number} property_type - 属性类型
* @property {string} base - 基础属性
* @property {string} add - 附加属性
* @property {string} final - 最终属性
* @return WeaponProp
*/
interface WeaponProp {
property_type: number;
base: string;
add: string;
final: string;
}
/**
* @description 角色详情圣遗物数据类型
* @interface Relic
* @since Beta v0.5.3
* @property {number} id - 圣遗物 ID
* @property {string} name - 圣遗物名称
* @property {string} icon - 圣遗物图标
* @property {number} pos - 圣遗物位置
* @property {number} rarity - 圣遗物稀有度
* @property {number} level - 圣遗物等级
* @property {RelicSet} set - 圣遗物套装
* @property {string} pos_name - 圣遗物位置名称
* @property {RelicProp} main_property - 圣遗物主属性
* @property {RelicProp[]} sub_properties - 圣遗物副属性
* @return Relic
*/
interface Relic {
id: number;
name: string;
icon: string;
pos: number;
rarity: number;
level: number;
set: RelicSet;
pos_name: string;
main_property: RelicProp;
sub_properties: RelicProp[];
}
/**
* @description 圣遗物套装数据类型
* @interface RelicSet
* @since Beta v0.5.3
* @property {number} id - 圣遗物套装 ID
* @property {string} name - 圣遗物套装名称
* @property {RelicSetAffix[]} affixes - 圣遗物套装效果
* @return RelicSet
*/
interface RelicSet {
id: number;
name: string;
affixes: RelicSetAffix[];
}
/**
* @description 圣遗物套装效果数据类型
* @interface RelicSetAffix
* @since Beta v0.5.3
* @property {number} activation_number - 圣遗物套装激活数量
* @property {string} effect - 圣遗物套装效果
* @return RelicSetAffix
*/
interface RelicSetAffix {
activation_number: number;
effect: string;
}
/**
* @description 圣遗物属性数据类型
* @interface RelicProp
* @since Beta v0.5.3
* @property {number} property_type - 属性类型
* @property {string} value - 属性值
* @property {number} times - 强化次数
* @return RelicProp
*/
interface RelicProp {
property_type: number;
value: string;
times: number;
}
/**
* @description 角色详情命座数据类型
* @interface Constellation
* @since Beta v0.5.3
* @property {number} id - 命座 ID
* @property {string} name - 命座名称
* @property {string} icon - 命座图标
* @property {string} effect - 命座效果
* @property {boolean} is_actived - 命座是否激活
* @property {number} pos - 命座位置
* @return Constellation
*/
interface Constellation {
id: number;
name: string;
icon: string;
effect: string;
is_actived: boolean;
pos: number;
}
/**
* @description 角色详情时装数据类型
* @interface Costume
* @since Beta v0.5.3
* @property {number} id - 时装 ID
* @property {string} name - 时装名称
* @property {string} icon - 时装图标
* @return Costume
*/
interface Costume {
id: number;
name: string;
icon: string;
}
/**
* @description 角色详情技能数据类型
* @interface Skill
* @since Beta v0.5.3
* @property {number} skill_id - 技能 ID
* @property {number} skill_type - 技能类型
* @property {number} level - 技能等级
* @property {string} desc - 技能描述
* @property {SkillAffix[]} skill_affix_list - 技能效果
* @property {string} icon - 技能图标
* @property {boolean} is_unlock - 技能是否解锁
* @property {string} name - 技能名称
* @return Skill
*/
interface Skill {
skill_id: number;
skill_type: number;
level: number;
desc: string;
skill_affix_list: SkillAffix[];
icon: string;
is_unlock: boolean;
name: string;
}
/**
* @description 技能效果数据类型
* @interface SkillAffix
* @since Beta v0.5.3
* @property {string} name - 效果名称
* @property {string} value - 效果值
* @return SkillAffix
*/
interface SkillAffix {
name: string;
value: string;
}
/**
* @description 推荐圣遗物属性数据类型
* @interface RelicRecommendProp
* @since Beta v0.5.3
* @property {PropRecommend} recommend_properties - 推荐属性
* @property {PropRecommend|null} custom_properties - 自定义属性
* @property {boolean} has_set_recommend_prop - 是否有套装推荐属性
* @return RelicRecommendProp
*/
interface RelicRecommendProp {
recommend_properties: PropRecommend;
custom_properties: PropRecommend | null;
has_set_recommend_prop: boolean;
}
/**
* @description 推荐属性数据类型
* @interface PropRecommend
* @since Beta v0.5.3
* @property {number[]} sand_main_property_list - 推荐主属性列表
* @property {number[]} goblet_main_property_list - 推荐主属性列表
* @property {number[]} circlet_main_property_list - 推荐主属性列表
* @property {number[]} sub_property_list - 推荐副属性列表
* @return PropRecommend
*/
interface PropRecommend {
sand_main_property_list: number[];
goblet_main_property_list: number[];
circlet_main_property_list: number[];
sub_property_list: number[];
}
/**
* @description 角色属性映射数据类型
* @interface PropMap
* @since Beta v0.5.3
* @type {[key:string]:DetailPropMapItem} - 属性映射
* @return PropMap
*/
interface PropMap {
[key: string]: PropMapItem;
}
/**
* @description 角色属性映射项数据类型
* @interface PropMapItem
* @since Beta v0.5.3
* @property {number} property_type - 属性类型与key一致
* @property {string} name - 属性名称
* @property {string} icon - 属性图标
* @property {string} filter_name - 属性过滤名称
* @return PropMapItem
*/
interface PropMapItem {
property_type: number;
name: string;
icon: string;
filter_name: string;
}
}

View File

@@ -1,198 +0,0 @@
/**
* @file types Plugins Enka.d.ts
* @description Enka 获取到的数据类型定义文件
* @todo 待使用
* @author BTMuli<bt-muli@outlook.com>
* @since Alpha v0.2.0
*/
declare namespace TGApp.Plugins.Enka {}
// /**
// * @description ENKA 数据
// * @since Alpha v0.1.3
// * @interface Data
// * @property {PlayerInfo} playerInfo 玩家信息
// * @property {AvatarInfo[]} avatarInfoList 角色信息列表
// * @property {number} ttl 缓存时间
// * @property {string} uid 用户 UID
// * @return Data
// */
// export interface Data {
// playerInfo: PlayerInfo
// avatarInfoList: AvatarInfo[]
// ttl: number
// uid: string
// }
//
// /**
// * @description 玩家信息
// * @since Alpha v0.1.3
// * @interface PlayerInfo
// * @property {string} nickname 昵称
// * @property {number} level 等级
// * @property {string} signature 个性签名
// * @property {number} worldLevel 世界等级
// * @property {number} nameCardId 名片 ID
// * @property {number} finishAchievementNum 完成成就数量
// * @property {number} towerFloorIndex 深渊层数
// * @property {number} towerLevelIndex 深渊间数
// * @property {BriefAvatarInfo[]} showAvatarInfoList 显示角色信息列表
// * @property {number[]} showNameCardIdList 显示名片 ID 列表
// * @property {BriefAvatarInfo} profilePicture 角色头像
// * @return PlayerInfo
// */
// export interface PlayerInfo {
// nickname: string
// level: number
// signature: string
// worldLevel: number
// nameCardId: number
// finishAchievementNum: number
// towerFloorIndex: number
// towerLevelIndex: number
// showAvatarInfoList: BriefAvatarInfo[]
// showNameCardIdList: number[]
// profilePicture: BriefAvatarInfo
// }
//
// /**
// * @description 简要角色信息
// * @since Alpha v0.1.3
// * @interface BriefAvatarInfo
// * @property {number} avatarId 角色 ID
// * @property {number} level 角色等级
// * @property {number} costumeId 角色服装 ID
// * @return BriefAvatarInfo
// */
// export interface BriefAvatarInfo {
// avatarId: number
// level?: number
// costumeId?: number
// }
//
// /**
// * @description 角色信息
// * @since Alpha v0.1.3
// * @interface AvatarInfo
// * @property {number} avatarId 角色 ID
// * @property {Record<number, AvatarProp>} propMap 角色属性
// * @property {number[]} talentIdList 角色天赋 ID 列表
// * @property {Record<number, number>} fightPropMap 角色战斗属性
// * @property {number} skillDepotId 角色技能库 ID
// * @property {number[]} inherentProudSkillList 角色固有技能列表
// * @property {Record<number, number>} skillLevelMap 角色技能等级
// * @property {Equip[]} equipList 角色装备列表
// * @property {number} fetterInfo.expLevel 角色羁绊等级
// * @return AvatarInfo
// */
// export interface AvatarInfo {
// avatarId: number
// propMap: Record<number, AvatarProp>
// talentIdList: number[]
// fightPropMap: Record<number, number>
// skillDepotId: number
// inherentProudSkillList: number[]
// skillLevelMap: Record<number, number>
// equipList: Equip[]
// fetterInfo: {
// expLevel: number
// }
// }
//
// /**
// * @description 角色属性
// * @since Alpha v0.1.3
// * @interface AvatarProp
// * @property {number} type 角色属性类型
// * @property {string} ival 角色属性值
// * @property {string} val 角色属性值
// * @return AvatarProp
// */
// export interface AvatarProp {
// type: number
// ival: string
// val?: string
// }
//
// /**
// * @description 角色装备
// * @since Alpha v0.1.3
// * @interface Equip
// * @property {number} itemId 装备 ID
// * @property {Reliquary} reliquary 装备圣遗物
// * @property {EquipFlat} flat 装备属性
//
// * @return Equip
// */
// export interface Equip {
// itemId: number
// reliquary: Reliquary
// flat: EquipFlat
// }
//
// /**
// * @description 圣遗物
// * @since Alpha v0.1.3
// * @interface Reliquary
// * @property {number} level 圣遗物等级
// * @property {number} mainPropId 圣遗物主属性 ID
// * @property {number[]} appendPropIdList 圣遗物附加属性 ID 列表
// * @return Reliquary
// */
// export interface Reliquary {
// level: number
// mainPropId: number
// appendPropIdList: number[]
// }
//
// /**
// * @description 装备属性
// * @since Alpha v0.1.3
// * @interface EquipFlat
// * @property {string} nameTextMapHash 装备名称
// * @property {string} setNameTextMapHash 装备套装名称
// * @property {number} rankLevel 装备等级
// * @property {ReliquaryMainStat} reliquaryMainStat 圣遗物主属性
// * @property {ReliquaryAppendStat[]} reliquarySubStats 圣遗物附加属性
// * @property {string} itemType 装备类型
// * @property {string} icon 装备图标
// * @property {string} equipType 装备类型
// * @return EquipFlat
// */
// export interface EquipFlat {
// nameTextMapHash: string
// setNameTextMapHash: string
// rankLevel: number
// reliquaryMainStat: ReliquaryMainStat
// reliquarySubStats: ReliquaryAppendStat[]
// itemType: string
// icon: string
// equipType: string
// }
//
// /**
// * @description 圣遗物主属性
// * @since Alpha v0.1.3
// * @interface ReliquaryMainStat
// * @property {string} mainPropId 圣遗物主属性 ID
// * @property {number} statValue 圣遗物主属性值
// * @return ReliquaryMainStat
// */
// export interface ReliquaryMainStat {
// mainPropId: string
// statValue: number
// }
//
// /**
// * @description 圣遗物附加属性
// * @since Alpha v0.1.3
// * @interface ReliquaryAppendStat
// * @property {string} appendPropId 圣遗物附加属性 ID
// * @property {number} statValue 圣遗物附加属性值
// * @return ReliquaryAppendStat
// */
// export interface ReliquaryAppendStat {
// appendPropId: string
// statValue: number
// }

View File

@@ -1,8 +1,7 @@
/**
* @file web api TGApi.ts
* @file web/api/TGApi.ts
* @description 应用用到的 API
* @author BTMuli <bt-muli@outlook.com>
* @since Beta v0.3.2
* @since Beta v0.5.3
*/
import { BBSUserInfoApi } from "./BBS.js";
@@ -19,6 +18,8 @@ import {
TakumiCookieBindingRolesApi,
TakumiCalculateSyncAvatarListApi,
TakumiCalculateSyncAvatarDetailApi,
TakumiRecordCharacterListApi,
TakumiRecordCharacterDetailApi,
} from "./Takumi.js";
// 应用 API
@@ -35,6 +36,8 @@ const TGApi = {
getUserInfo: BBSUserInfoApi, // 获取用户信息
getAccounts: TakumiCookieBindingRolesApi, // 获取绑定角色
getCharacter: TakumiRecordCharactersApi, // 获取角色信息
getAvatarList: TakumiRecordCharacterListApi, // 获取角色列表
getAvatarDetail: TakumiRecordCharacterDetailApi, // 获取角色详情
},
bySToken: {
getAccounts: TakumiSTokenBindingRolesApi, // 获取绑定角色

View File

@@ -1,8 +1,7 @@
/**
* @file web api Takumi.ts
* @file web/api/Takumi.ts
* @description 定义 Takumi API
* @author BTMuli <bt-muli@outlook.com>
* @since Alpha v0.2.2
* @since Beta v0.5.3
*/
const TakumiApi = "https://api-takumi.mihoyo.com/"; // 基础 API
@@ -17,6 +16,8 @@ export const TakumiRecordDailyNotesApi = `${TakumiRecordApi}game_record/app/gens
export const TakumiRecordCardApi = `${TakumiRecordApi}game_record/app/card/wapi/getGameRecordCard`; // 游戏记录卡片 API
export const TakumiRecordIndexApi = `${TakumiRecordGenshinApi}index`; // 原神游戏记录索引 API
export const TakumiRecordCharactersApi = `${TakumiRecordGenshinApi}character`; // 原神游戏记录角色 API
export const TakumiRecordCharacterListApi = `${TakumiRecordCharactersApi}/list`; // 原神游戏记录角色列表 API
export const TakumiRecordCharacterDetailApi = `${TakumiRecordCharactersApi}/detail`; // 原神游戏记录角色详情 API
export const TakumiRecordAbyssApi = `${TakumiRecordGenshinApi}spiralAbyss`; // 原神游戏记录深境螺旋 API
export const TakumiSTokenBindingRolesApi = `${TakumiBindingApi}getUserGameRolesBySToken`; // 获取绑定角色 API-根据 stoken
export const TakumiCookieBindingRolesApi = `${TakumiBindingApi}getUserGameRolesByCookie`; // 获取绑定角色 API-根据 Cookie

View File

@@ -1,16 +1,16 @@
/**
* @file web/request/TGRequest.ts
* @description 应用用到的请求函数
* @since Beta v0.5.0
* @since Beta v0.5.3
*/
import { genAuthkey, genAuthkey2 } from "./genAuthkey.js";
import { getAbyss } from "./getAbyss.js";
import { getActionTicketBySToken } from "./getActionTicket.js";
import { getAnnoContent, getAnnoList } from "./getAnno.js";
import { getAvatarList, getAvatarDetail } from "./getAvatarDetail.js";
import { getCookieTokenByGameToken, getCookieTokenBySToken } from "./getCookieToken.js";
import { getDeviceFp } from "./getDeviceFp.js";
// import * from "./getEnkaData.ts";
import { getGachaLog } from "./getGachaLog.js";
import { getGameAccountsByCookie, getGameAccountsBySToken } from "./getGameAccounts.js";
import { getGameRecord } from "./getGameRecord.js";
@@ -41,6 +41,8 @@ const TGRequest = {
getAbyss,
getAccounts: getGameAccountsByCookie,
getUserInfo: getUserInfoByCookie,
getAvatarList,
getAvatarDetail,
},
byLToken: {
verify: verifyLToken,

View File

@@ -0,0 +1,69 @@
/**
* @file web/request/getAvatarDetail.ts
* @description 获取角色详情相关请求函数
* @since Beta v0.5.3
*/
import { app } from "@tauri-apps/api";
import TGHttp from "../../utils/TGHttp.js";
import TGApi from "../api/TGApi.js";
import TGUtils from "../utils/TGUtils.js";
/**
* @description 获取角色列表
* @since Beta v0.5.3
* @param {Record<string, string>} cookie Cookie
* @param {string} uid 用户 uid
* @return {Promise<TGApp.Game.Avatar.Avatar[]|TGApp.BBS.Response.Base>}
*/
export async function getAvatarList(
cookie: Record<string, string>,
uid: string,
): Promise<TGApp.Game.Avatar.Avatar[] | TGApp.BBS.Response.Base> {
const url = TGApi.GameData.byCookie.getAvatarList;
const data = { uid, region: TGUtils.Tools.getServerByUid(uid) };
const version = await app.getVersion();
const header = {
"User-Agent": `TeyvatGuide/${version}`,
Referer: "https://webstatic.mihoyo.com/",
Cookie: TGUtils.Tools.transCookie(cookie),
};
const resp = await TGHttp<TGApp.Game.Avatar.ListResponse | TGApp.BBS.Response.Base>(url, {
method: "POST",
body: JSON.stringify(data),
headers: header,
});
if (resp.retcode !== 0) return <TGApp.BBS.Response.Base>resp;
return resp.data.list;
}
/**
* @description 获取角色详情
* @since Beta v0.5.3
* @param {Record<string, string>} cookie Cookie
* @param {string} uid 用户 uid
* @param {number} avatarId 角色 id
* @return {Promise<TGApp.Game.Avatar.AvatarDetail|TGApp.BBS.Response.Base>}
*/
export async function getAvatarDetail(
cookie: Record<string, string>,
uid: string,
avatarId: number,
): Promise<TGApp.Game.Avatar.AvatarDetail | TGApp.BBS.Response.Base> {
const url = TGApi.GameData.byCookie.getAvatarDetail;
const params = { uid, region: TGUtils.Tools.getServerByUid(uid), avatar_id: avatarId };
const version = await app.getVersion();
const header = {
"User-Agent": `TeyvatGuide/${version}`,
Referer: "https://webstatic.mihoyo.com/",
Cookie: TGUtils.Tools.transCookie(cookie),
};
const resp = await TGHttp<TGApp.Game.Avatar.DetailResponse | TGApp.BBS.Response.Base>(url, {
method: "GET",
query: params,
headers: header,
});
if (resp.retcode !== 0) return <TGApp.BBS.Response.Base>resp;
return resp.data;
}

View File

@@ -1,21 +0,0 @@
// /**
// * @file web request getEnkaData.ts
// * @description 获取 ENKA 数据
// * @author BTMuli<bt-muli@outlook.com>
// * @since Alpha v0.1.3
// */
//
// // Tauri
// import { http } from "@tauri-apps/api";
// // Tauri.App
// import TGApi from "../api/TGApi";
//
// /**
// * @description 获取 ENKA 数据
// * @since Alpha v0.1.3
// * @param {number} uid 用户 UID
// * @returns {Promise<TGApp.Plugins.Enka>}
// */
// export async function getEnkaData (uid: number): Promise<BTMuli.App.Enka.Data> {
// return await http.fetch<BTMuli.App.Enka.Data>(`${TGApi.GameEnka}${uid}`).then((res) => res.data);
// }