miao-plugin/models/ProfileServ.js
Kokomi 5fe63f4896 * 为#喵喵设置增加更多配置项
* 允许禁用面板替换功能
    * 允许禁用非实装角色资料,关闭可禁用非实装角色资料及面板替换
    * 可选择面板服务,可选喵喵Api优先(需具备Token)或Enka优先
* 更新迪希雅、米卡的最新天赋与命座数据
* 全量使用通过属性计算得到的面板数据,移除相关配置项
2023-02-07 02:08:12 +08:00

97 lines
2.2 KiB
JavaScript

import lodash from 'lodash'
import Base from './Base.js'
import { Data, Cfg } from '../components/index.js'
let { sysCfg, diyCfg } = await Data.importCfg('profile')
export default class ProfileServ extends Base {
constructor (cfg) {
super()
this._name = cfg.name
this.cfgKey = cfg.cfgKey || cfg.id
this.diyCfg = diyCfg[this.cfgKey] || {}
this.sysCfg = sysCfg[this.cfgKey] || {}
this._cfg = cfg
}
get name () {
let url = this.getCfg('url')
return this._name || url.replace('https://', '').replace('/', '').trim()
}
// 获取当前面板服务配置
getCfg (key, def = '') {
if (!lodash.isUndefined(this.diyCfg[key])) {
return this.diyCfg[key]
}
if (!lodash.isUndefined(this.sysCfg[key])) {
return this.sysCfg[key]
}
return def
}
// 请求当前面板服务
async getReqParam (uid) {
let url = this.getCfg('url')
let profileApi = this.getCfg('listApi')
let cfg = this._cfg
let api = profileApi({
url,
uid: uid,
diyCfg: this.diyCfg
})
let param = {}
// 获取请求参数
if (cfg.request) {
param = await cfg.request.call(this, api)
}
return {
url: param.api || api,
params: param.params || {}
}
}
async response (data, req) {
// 处理返回
let cfg = this._cfg
if (cfg.response) {
return await cfg.response.call(this, data, req)
}
}
execFn (fn, args = [], def = false) {
let { _cfg } = this
if (_cfg[fn]) {
return _cfg[fn].apply(this, args)
}
return def
}
getCdTime (data) {
const requestInterval = diyCfg.requestInterval || sysCfg.requestInterval || 5
let cdTime = requestInterval * 60
return Math.max(cdTime, this.execFn('cdTime', [data], 60))
}
getUserData (data) {
return this.execFn('userData', [data], {})
}
getProfileData (data) {
return this.execFn('profileData', [data], {})
}
}
ProfileServ.getServ = function ({ uid, serv }) {
let { Miao, Enka } = serv
let token = diyCfg?.miaoApi?.token
let qq = diyCfg?.miaoApi?.qq
if (qq && token && token.length === 32 && !/^test/.test(token) && Cfg.get('profileServ') === 1) {
return Miao
}
return Enka
}