面板服务增加MiniGG-API,#喵喵设置中可区分国服、B服、外服分别设置面板服务器

This commit is contained in:
Kokomi 2023-02-24 03:23:57 +08:00
parent 276dba9b7e
commit 25a7103321
11 changed files with 109 additions and 34 deletions

View File

@ -1,3 +1,10 @@
# 2.3.2
* 面板服务增加国内专属面板服务 MiniGG-API
* 由小灰灰大佬**@MiniGrayGay**与Enka官方合作部署
* 国内节点免费开放请求速度会比Enka更快
* `#喵喵设置`中可区分国服、B服、外服分别设置面板服务器具体参见喵喵设置
# 2.3.1
* MiaoApi面板服务更新

View File

@ -68,13 +68,13 @@ export const cfgSchema = {
input: (n) => Math.min(30, Math.max(5, (n * 1 || 15))),
desc: '可选值5~30建议15。设置高排名人数会提高图片的长度图片较大可能会影响渲染与发送速度'
},
profileServ: {
profileServer: {
title: '面板服务',
key: '面板服务',
type: 'num',
def: 1,
input: (n) => n * 1 === 1 ? 1 : 2,
desc: '面板服务优先选择1自动具备有效Token时优先喵喵Api否则Enka2Enka服务优先'
def: 0,
input: (n) => /[0-3]{1,3}/.test(n) ? n : 0,
desc: '面板服务选择0:自动1:喵Api(需具备Token) 2:Enka-API 3:MiniGG-Api。如设置三位数字则为分服务器设置按顺序分别为 国服/B服/外服例如112代表国服B服Miao,国外Enka'
},
costumeSplash: {
title: '使用自定义面板插图',

View File

@ -4,16 +4,25 @@
* */
export const miaoApi = {
listApi: ({ uid, diyCfg }) => {
listApi: ({ url, uid, diyCfg }) => {
let qq = /\d{5,12}/.test(diyCfg.qq) ? diyCfg.qq : 'none'
let token = diyCfg.token
return `http://miaoapi.cn/profile/data?uid=${uid}&qq=${qq}&token=${token}&version=2`
url = url || 'http://miaoapi.cn/'
return `${url}profile/data?uid=${uid}&qq=${qq}&token=${token}&version=2`
}
}
export const enkaApi = {
url: 'https://enka.network/',
userAgent: 'Miao-Plugin/3.0',
userAgent: 'Miao-Plugin/3.1',
listApi: ({ url, uid, diyCfg }) => {
return `${url}api/uid/${uid}/`
}
}
export const mggApi = {
url: 'https://profile.microgg.cn/',
userAgent: 'Miao-Plugin/3.1',
listApi: ({ url, uid, diyCfg }) => {
return `${url}api/uid/${uid}/`
}

View File

@ -62,6 +62,7 @@ export default class AvatarData extends Base {
return {
enka: 'Enka.Network',
miao: '喵喵Api',
mgg: 'MiniGG-API',
mys: '米游社'
}[this._source] || this._source
}

View File

@ -1,7 +1,6 @@
import lodash from 'lodash'
import { Data } from '../../components/index.js'
import EnkaData from './EnkaData.js'
import MiaoData from './MiaoData.js'
let HttpsProxyAgent = ''
@ -53,17 +52,6 @@ export default {
})
},
profileData (data) {
let ret = {}
lodash.forEach(data.avatarInfoList, (ds) => {
let profile = EnkaData.getProfile(ds)
if (profile && profile.id) {
ret[profile.id] = profile
}
})
return ret
},
// 获取冷却时间
cdTime (data) {
return data.ttl || 60

View File

@ -3,7 +3,7 @@ import { attrMap, idsMap, artisIdxMap } from './ProfileMeta.js'
import { Character, ArtifactSet } from '../index.js'
let EnkaData = {
setAvatar (player, data) {
setAvatar (player, data, dataSource = 'enka') {
let char = Character.get(data.avatarId)
if (!char) {
return
@ -20,7 +20,7 @@ let EnkaData = {
weapon: EnkaData.getWeapon(data.equipList),
talent: talentRet.talent,
artis: EnkaData.getArtifact(data.equipList)
}, 'enka')
}, dataSource)
return avatar
},

46
models/player/MggApi.js Normal file
View File

@ -0,0 +1,46 @@
import lodash from 'lodash'
import { Data } from '../../components/index.js'
import EnkaData from './EnkaData.js'
export default {
id: 'mgg',
name: 'MiniGG-Api',
cfgKey: 'mggApi',
// 处理请求参数
async request (api) {
let params = {
headers: { 'User-Agent': this.getCfg('userAgent') }
}
return { api, params }
},
// 处理服务返回
async response (data, req) {
if (!data.playerInfo) {
if (data.error) {
console.log(`Enka ReqErr: ${data.error}`)
}
return req.err('error', 60)
}
let details = data.avatarInfoList
if (!details || details.length === 0 || !details[0].propMap) {
return req.err('empty', 5 * 60)
}
return data
},
updatePlayer (player, data) {
player.setBasicData(Data.getData(data, 'name:nickname,face:profilePicture.avatarID,card:nameCardID,level,word:worldLevel,sign:signature'))
lodash.forEach(data.avatarInfoList, (ds) => {
let ret = EnkaData.setAvatar(player, ds, 'mgg')
if (ret) {
player._update.push(ret.id)
}
})
},
// 获取冷却时间
cdTime (data) {
return data.ttl || 60
}
}

View File

@ -6,6 +6,10 @@ export default {
key: 'miao',
name: '喵喵Api',
cfgKey: 'miaoApi',
async request (api) {
api = this.getCfg('api') || api
return { api }
},
async response (data, req) {
if (data.status !== 0) {
return req.err(data.msg || 'error', 60)

View File

@ -2,12 +2,25 @@ import { ProfileReq, ProfileServ } from '../index.js'
import { Cfg, Data } from '../../components/index.js'
import MysAvatar from './MysAvatar.js'
import enkaCfg from './EnkaApi.js'
import MiaoApi from './MiaoApi.js'
import enkaApi from './EnkaApi.js'
import miaoApi from './MiaoApi.js'
import mggApi from './MggApi.js'
let { diyCfg } = await Data.importCfg('profile')
const Profile = {
servs: {},
serv (key) {
if (!Profile.servs[key]) {
Profile.servs[key] = new ProfileServ({
miao: miaoApi,
mgg: mggApi,
enka: enkaApi
}[key])
}
return Profile.servs[key]
},
/**
* 根据UID分配请求服务器
* @param uid
@ -16,17 +29,24 @@ const Profile = {
getServ (uid) {
let token = diyCfg?.miaoApi?.token
let qq = diyCfg?.miaoApi?.qq
let hasToken = !!(qq && token && token.length === 32 && !/^test/.test(token))
if (qq && token && token.length === 32 && !/^test/.test(token) && Cfg.get('profileServ') === 1) {
if (!Profile.Miao) {
Profile.Miao = new ProfileServ(MiaoApi)
// 判断国服、B服、外服获取在配置中的idx
let servIdx = { 1: 0, 2: 0, 3: 0, 4: 0, 5: 1, 6: 2, 7: 2, 8: 2, 9: 2 }[uid[0]]
// 获取对应服务选择的配置数字0自动1喵2Enka3Mgg
let servCfg = Cfg.get('profileServer', '0').toString() || '0'
servCfg = servCfg[servIdx] || servCfg[0] || '0'
if ((servCfg === '0' || servCfg === '1') && hasToken) {
return Profile.serv('miao')
}
return Profile.Miao
if (servCfg === '2') {
return Profile.serv('enka')
} else if (servCfg === '3') {
return Profile.serv('mgg')
}
if (!Profile.Enka) {
Profile.Enka = new ProfileServ(enkaCfg)
}
return Profile.Enka
return Profile.serv(servIdx === 2 ? 'enka' : 'mgg')
},
/**
@ -64,7 +84,7 @@ const Profile = {
isProfile (avatar) {
// 检查数据源
if (!avatar._source || !['enka', 'change', 'miao'].includes(avatar._source)) {
if (!avatar._source || !['enka', 'change', 'miao', 'mgg'].includes(avatar._source)) {
return false
}
// 检查武器及天赋

View File

@ -78,7 +78,7 @@
</div>
<div class="copyright data-source">
数据源:{{ {miao:'喵喵API', 'enka':'Enka.Network', mys:'米游社'}[data.source]||data.source }} {{data.updateTime}}
数据源:{{ {miao:'喵喵API', 'enka':'Enka.Network', 'mgg':'MiniGG-API', mys:'米游社'}[data.source]||data.source }} {{data.updateTime}}
</div>
{{else}}
{{if custom}}