MiaoApi面板服务逻辑更新

This commit is contained in:
Kokomi 2023-02-20 01:08:05 +08:00
parent b600d3799a
commit d02a675649
12 changed files with 101 additions and 30 deletions

View File

@ -1,3 +1,13 @@
# 2.3.1
* MiaoApi面板服务更新
* 使用新版接口获取面板,大幅提高响应速度
* 使用statsIds存储圣遗物数据能够更精确的计算角色属性
* 部分已知问题调整或优化
* 圣遗物、天赋更新策略及更新逻辑优化
* `#面板`、`#角色`等页面使用Q版头像
* 面板更新的提醒文案逻辑优化
# 2.3.0 # 2.3.0
* 重写底层面板、角色数据获取与保存逻辑 * 重写底层面板、角色数据获取与保存逻辑

View File

@ -96,7 +96,8 @@ const ProfileList = {
let profile = profiles[id] let profile = profiles[id]
let char = profile.char let char = profile.char
let tmp = char.getData('id,face,name,abbr,element,star') let tmp = char.getData('id,face,name,abbr,element,star')
tmp.face = char.getImgs(profile.costume).face let imgs = char.getImgs(profile.costume)
tmp.face = imgs.qFace || imgs.face
tmp.level = profile.level || 1 tmp.level = profile.level || 1
tmp.cons = profile.cons tmp.cons = profile.cons
tmp.isNew = 0 tmp.isNew = 0

View File

@ -9,7 +9,7 @@ export async function AbyssTeam (e) {
return true return true
} }
let player = Player.create(e) let player = Player.create(e)
await player.refreshMysDetail() await player.refreshMysDetail(2)
await player.refreshTalent() await player.refreshTalent()
let abyssData = await HutaoApi.getAbyssTeam() let abyssData = await HutaoApi.getAbyssTeam()
@ -23,8 +23,8 @@ export async function AbyssTeam (e) {
let data = {} let data = {}
let noAvatar = {} let noAvatar = {}
lodash.forEach(avatarData, (avatar) => { lodash.forEach(avatarData, (avatar) => {
let t = avatar.originalTalent let t = avatar.originalTalent || {}
avatarRet[avatar.id] = Math.min(avatar.level, avatar.weapon?.level || 1) * 100 + Math.max(t?.a, t?.e, t?.q) * 1000 avatarRet[avatar.id] = Math.min(avatar.level, (avatar.weapon?.level || 1)) * 100 + Math.max(t?.a || 1, t?.e || 1, t?.q || 1) * 1000
}) })
let getTeamCfg = (str) => { let getTeamCfg = (str) => {

View File

@ -7,7 +7,7 @@ export const miaoApi = {
listApi: ({ uid, diyCfg }) => { listApi: ({ uid, diyCfg }) => {
let qq = /\d{5,12}/.test(diyCfg.qq) ? diyCfg.qq : 'none' let qq = /\d{5,12}/.test(diyCfg.qq) ? diyCfg.qq : 'none'
let token = diyCfg.token let token = diyCfg.token
return `http://miaoapi.cn/profile/data?uid=${uid}&qq=${qq}&token=${token}` return `http://miaoapi.cn/profile/data?uid=${uid}&qq=${qq}&token=${token}&version=2`
} }
} }

View File

@ -1,6 +1,6 @@
/** /**
* 用户数据文件 * 用户数据文件
* 数据存储在/data/userData/${uid}.json * 数据存储在/data/UserData/${uid}.json
* 兼容处理面板户数及Mys数据 * 兼容处理面板户数及Mys数据
* *
*/ */
@ -12,7 +12,7 @@ import { AvatarData, ProfileRank, Character } from './index.js'
import MysAvatar from './player/MysAvatar.js' import MysAvatar from './player/MysAvatar.js'
import Profile from './player/Profile.js' import Profile from './player/Profile.js'
Data.createDir('/data/userData', 'root') Data.createDir('/data/UserData', 'root')
export default class Player extends Base { export default class Player extends Base {
constructor (uid) { constructor (uid) {

View File

@ -58,20 +58,30 @@ export default class ProfileReq extends Base {
async requestProfile (player, serv) { async requestProfile (player, serv) {
this.serv = serv this.serv = serv
let reqParam = await serv.getReqParam(this.uid) let uid = this.uid
let reqParam = await serv.getReqParam(uid)
let cdTime = await this.inCd() let cdTime = await this.inCd()
if (cdTime && !process.argv.includes('web-debug')) { if (cdTime && !process.argv.includes('web-debug')) {
return this.err(`请求过快,请${cdTime}秒后重试..`) return this.err(`请求过快,请${cdTime}秒后重试..`)
} }
await this.setCd(20) await this.setCd(20)
let self = this
// 若3秒后还未响应则返回提示
setTimeout(() => {
if (self._isReq) {
this.msg(`开始获取uid:${uid}的数据,可能会需要一定时间~`)
}
}, 3000)
// 发起请求 // 发起请求
logger.mark(`面板请求UID:${this.uid},面板服务:${serv.name}...`) logger.mark(`面板请求UID:${uid},面板服务:${serv.name}...`)
let data = {} let data = {}
try { try {
let params = reqParam.params || {} let params = reqParam.params || {}
params.timeout = params.timeout || 1000 * 20 params.timeout = params.timeout || 1000 * 20
self._isReq = true
let req = await fetch(reqParam.url, params) let req = await fetch(reqParam.url, params)
data = await req.text() data = await req.text()
self._isReq = false
if (data[0] === '<') { if (data[0] === '<') {
let titleRet = /<title>(.+)<\/title>/.exec(data) let titleRet = /<title>(.+)<\/title>/.exec(data)
if (titleRet && titleRet[1]) { if (titleRet && titleRet[1]) {
@ -84,6 +94,7 @@ export default class ProfileReq extends Base {
} }
} catch (e) { } catch (e) {
console.log('面板请求错误', e) console.log('面板请求错误', e)
self._isReq = false
data = {} data = {}
} }
data = await serv.response(data, this) data = await serv.response(data, this)

View File

@ -10,21 +10,40 @@ export default {
if (data.status !== 0) { if (data.status !== 0) {
return req.err(data.msg || 'error', 60) return req.err(data.msg || 'error', 60)
} }
data = data.data || {} if (data.version === 2) {
if (!data.showAvatarInfoList || data.showAvatarInfoList.length === 0) { data = data.data || {}
return req.err('empty', 5 * 60) if (!data.avatars || data.avatars.length === 0) {
return req.err('empty', 5 * 60)
}
data.version = 2
return data
} else {
data = data.data || {}
if (!data.showAvatarInfoList || data.showAvatarInfoList.length === 0) {
return req.err('empty', 5 * 60)
}
return data
} }
return data
}, },
updatePlayer (player, data) { updatePlayer (player, data) {
player.setBasicData(Data.getData(data, 'name:nickname,face:profilePicture.avatarId,card:nameCardID,level,word:worldLevel,sign:signature')) if (data.version === 2) {
lodash.forEach(data.showAvatarInfoList, (ds) => { player.setBasicData(data)
let ret = MiaoData.setAvatar(player, ds) lodash.forEach(data.avatars, (avatar) => {
if (ret) { let ret = MiaoData.setAvatarNew(player, avatar)
player._update.push(ret.id) if (ret) {
} player._update.push(ret.id)
}) }
})
} else {
player.setBasicData(Data.getData(data, 'name:nickname,face:profilePicture.avatarId,card:nameCardID,level,word:worldLevel,sign:signature'))
lodash.forEach(data.showAvatarInfoList, (ds) => {
let ret = MiaoData.setAvatar(player, ds)
if (ret) {
player._update.push(ret.id)
}
})
}
}, },
// 获取冷却时间 // 获取冷却时间

View File

@ -22,6 +22,17 @@ let MiaoData = {
return avatar return avatar
}, },
setAvatarNew (player, ds) {
let char = Character.get(ds.id)
let avatar = player.getAvatar(ds.id, true)
let talentRet = MiaoData.getTalentNew(char.id, ds.talent)
avatar.setAvatar({
...ds,
elem: talentRet.elem
}, 'miao')
return avatar
},
getWeapon (weapon) { getWeapon (weapon) {
return { return {
name: weapon.name, name: weapon.name,
@ -31,6 +42,31 @@ let MiaoData = {
} }
}, },
getTalentNew (charid, data = {}) {
let char = Character.get(charid)
let { talentId = {}, talentElem = {}, talentKey = {} } = char.meta
let elem = ''
let idx = 0
let ret = {}
lodash.forEach(data, (level, id) => {
let key
if (talentId[id]) {
let tid = talentId[id]
key = talentKey[tid]
elem = elem || talentElem[tid]
ret[key] = level
} else {
key = ['a', 'e', 'q'][idx]
ret[key] = level
}
idx++
})
return {
talent: ret,
elem
}
},
getTalent (charid, data = {}) { getTalent (charid, data = {}) {
let char = Character.get(charid) let char = Character.get(charid)
let { talentId = {}, talentElem = {}, talentKey = {} } = char.meta let { talentId = {}, talentElem = {}, talentKey = {} } = char.meta

View File

@ -107,10 +107,9 @@ body,
width: 100%; width: 100%;
} }
.cont-footer span { .cont-footer span {
width: 35%; width: 50%;
} }
.cont-footer .serv { .cont-footer .serv {
width: 65%;
text-align: right; text-align: right;
} }
.cont-footer .new-tip:before { .cont-footer .new-tip:before {

View File

@ -55,14 +55,10 @@
{{if hasNew}} {{if hasNew}}
<span class="new-tip">本次更新角色</span> <span class="new-tip">本次更新角色</span>
{{else}} {{else}}
<span></span> <span>{{if updateTime.profile }} 更新时间:{{updateTime.profile }} {{/if}}</span>
{{/if}} {{/if}}
<span class="serv"> <span class="serv">
当前更新服务:{{servName}} 当前更新服务:{{servName}}
{{if updateTime.profile }}
<span>,更新时间:{{updateTime.profile }}</span>
{{/if}}
</span> </span>
</div> </div>
</div> </div>

View File

@ -128,11 +128,10 @@ body, .container {
width: 100%; width: 100%;
span { span {
width: 35%; width: 50%;
} }
.serv { .serv {
width: 65%;
text-align: right; text-align: right;
} }

View File

@ -44,7 +44,7 @@
<div class="card-list"> <div class="card-list">
{{each teamData.teamArr id}} {{each teamData.teamArr id}}
<div <div
class="card star{{avatars[id].star == 4 ? 4:5}} {{avatars[id].level*1 === 0 ? 'no-character':'has-character'}}"> class="card star{{avatars[id].star == 4 ? 4:5}} {{ avatars[id].level*1 === 0 ? 'no-character':'has-character'}}">
<img class="role" src="{{_res_path}}{{avatars[id].face}}"/> <img class="role" src="{{_res_path}}{{avatars[id].face}}"/>
<span class="cons cons-{{avatars[id].cons}} for-has">{{avatars[id].cons}}</span> <span class="cons cons-{{avatars[id].cons}} for-has">{{avatars[id].cons}}</span>
<span class="lvl for-has">Lv.{{avatars[id].level}}</span> <span class="lvl for-has">Lv.{{avatars[id].level}}</span>