2022-08-18 10:13:42 +00:00
|
|
|
import lodash from 'lodash'
|
2023-10-19 09:48:52 +00:00
|
|
|
import Base from '../Base.js'
|
|
|
|
import { Data } from '#miao'
|
2022-08-18 10:13:42 +00:00
|
|
|
|
|
|
|
let { sysCfg, diyCfg } = await Data.importCfg('profile')
|
|
|
|
|
|
|
|
export default class ProfileServ extends Base {
|
2023-10-19 09:48:52 +00:00
|
|
|
|
2022-08-18 10:13:42 +00:00
|
|
|
constructor (cfg) {
|
|
|
|
super()
|
|
|
|
this._name = cfg.name
|
|
|
|
this.cfgKey = cfg.cfgKey || cfg.id
|
2022-08-19 01:50:17 +00:00
|
|
|
this.diyCfg = diyCfg[this.cfgKey] || {}
|
|
|
|
this.sysCfg = sysCfg[this.cfgKey] || {}
|
2022-08-18 10:13:42 +00:00
|
|
|
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
|
|
|
|
}
|
|
|
|
|
|
|
|
// 请求当前面板服务
|
2023-05-19 18:50:39 +00:00
|
|
|
async getReqParam (uid, game = 'gs') {
|
2022-08-18 10:13:42 +00:00
|
|
|
let url = this.getCfg('url')
|
|
|
|
let profileApi = this.getCfg('listApi')
|
|
|
|
let cfg = this._cfg
|
2023-10-23 03:11:08 +00:00
|
|
|
|
2022-08-18 10:13:42 +00:00
|
|
|
let api = profileApi({
|
|
|
|
url,
|
|
|
|
uid: uid,
|
2023-05-19 18:50:39 +00:00
|
|
|
diyCfg: this.diyCfg,
|
|
|
|
game
|
2022-08-18 10:13:42 +00:00
|
|
|
})
|
|
|
|
let param = {}
|
|
|
|
|
|
|
|
// 获取请求参数
|
|
|
|
if (cfg.request) {
|
|
|
|
param = await cfg.request.call(this, api)
|
|
|
|
}
|
|
|
|
|
|
|
|
return {
|
|
|
|
url: param.api || api,
|
2022-09-14 19:31:10 +00:00
|
|
|
params: param.params || {}
|
2022-08-18 10:13:42 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-05-19 18:50:39 +00:00
|
|
|
async response (data, req, game = 'gs') {
|
2022-08-18 10:13:42 +00:00
|
|
|
// 处理返回
|
|
|
|
let cfg = this._cfg
|
|
|
|
if (cfg.response) {
|
2023-05-19 18:50:39 +00:00
|
|
|
return await cfg.response.call(this, data, req, game)
|
2022-08-18 10:13:42 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-08-20 23:40:32 +00:00
|
|
|
execFn (fn, args = [], def = false) {
|
|
|
|
let { _cfg } = this
|
|
|
|
if (_cfg[fn]) {
|
|
|
|
return _cfg[fn].apply(this, args)
|
|
|
|
}
|
|
|
|
return def
|
|
|
|
}
|
|
|
|
|
2022-08-18 10:13:42 +00:00
|
|
|
getCdTime (data) {
|
|
|
|
const requestInterval = diyCfg.requestInterval || sysCfg.requestInterval || 5
|
|
|
|
let cdTime = requestInterval * 60
|
2022-08-20 23:40:32 +00:00
|
|
|
return Math.max(cdTime, this.execFn('cdTime', [data], 60))
|
|
|
|
}
|
|
|
|
|
2023-02-08 20:55:54 +00:00
|
|
|
updatePlayer (player, data) {
|
|
|
|
return this.execFn('updatePlayer', [player, data], {})
|
2022-08-18 10:13:42 +00:00
|
|
|
}
|
|
|
|
}
|