diff --git a/CHANGELOG.md b/CHANGELOG.md index 1f2545c4..a03a3e70 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,10 @@ +# 2.3.2 + +* 面板服务增加国内专属面板服务 MiniGG-API + * 由小灰灰大佬**@MiniGrayGay**与Enka官方合作部署 + * 国内节点,免费开放,请求速度会比Enka更快 +* `#喵喵设置`中可区分国服、B服、外服分别设置面板服务器,具体参见喵喵设置 + # 2.3.1 * MiaoApi面板服务更新 diff --git a/config/profile_default.js b/config/profile_default.js index 8ea5681f..5eceb34b 100644 --- a/config/profile_default.js +++ b/config/profile_default.js @@ -15,7 +15,7 @@ * 目前使用Miao-Plugin的默认UA请求国服UID时 * 会默认重定向 https://enka.network/ 到 https://profile.microgg.cn/ * 如果没有外服uid查询请求,可直接在配置文件改为 https://profile.microgg.cn/ -* +* * 感谢@MiniGrayGay 大佬提供的服务(Github: https://github.com/MiniGrayGay) * * 使用代理(科学上网)可以配置proxyAgent diff --git a/config/system/cfg_system.js b/config/system/cfg_system.js index b272f7cb..c409cf39 100644 --- a/config/system/cfg_system.js +++ b/config/system/cfg_system.js @@ -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,否则Enka),2:Enka服务优先' + 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: '使用自定义面板插图', diff --git a/config/system/profile_system.js b/config/system/profile_system.js index e0c8beca..05a94a5a 100644 --- a/config/system/profile_system.js +++ b/config/system/profile_system.js @@ -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}/` } diff --git a/models/AvatarData.js b/models/AvatarData.js index f468a270..3cdbb7c3 100644 --- a/models/AvatarData.js +++ b/models/AvatarData.js @@ -62,6 +62,7 @@ export default class AvatarData extends Base { return { enka: 'Enka.Network', miao: '喵喵Api', + mgg: 'MiniGG-API', mys: '米游社' }[this._source] || this._source } diff --git a/models/player/EnkaApi.js b/models/player/EnkaApi.js index 30089001..d5c61181 100644 --- a/models/player/EnkaApi.js +++ b/models/player/EnkaApi.js @@ -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 diff --git a/models/player/EnkaData.js b/models/player/EnkaData.js index 46cbc086..849306dd 100644 --- a/models/player/EnkaData.js +++ b/models/player/EnkaData.js @@ -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 }, diff --git a/models/player/MggApi.js b/models/player/MggApi.js new file mode 100644 index 00000000..410a4069 --- /dev/null +++ b/models/player/MggApi.js @@ -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 + } +} diff --git a/models/player/MiaoApi.js b/models/player/MiaoApi.js index 905c0882..de03f2ff 100644 --- a/models/player/MiaoApi.js +++ b/models/player/MiaoApi.js @@ -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) diff --git a/models/player/Profile.js b/models/player/Profile.js index 73de0f54..506da25f 100644 --- a/models/player/Profile.js +++ b/models/player/Profile.js @@ -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) - } - return Profile.Miao + // 判断国服、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喵,2Enka,3Mgg + let servCfg = Cfg.get('profileServer', '0').toString() || '0' + servCfg = servCfg[servIdx] || servCfg[0] || '0' + + if ((servCfg === '0' || servCfg === '1') && hasToken) { + return Profile.serv('miao') } - if (!Profile.Enka) { - Profile.Enka = new ProfileServ(enkaCfg) + if (servCfg === '2') { + return Profile.serv('enka') + } else if (servCfg === '3') { + return Profile.serv('mgg') } - 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 } // 检查武器及天赋 diff --git a/resources/character/character-card.html b/resources/character/character-card.html index 7f2b59d3..8fbf1ccd 100644 --- a/resources/character/character-card.html +++ b/resources/character/character-card.html @@ -78,7 +78,7 @@