2024-06-09 01:31:31 +08:00
|
|
|
|
import common from '../lib/common/common.js'
|
|
|
|
|
import cfg from '../lib/config/config.js'
|
|
|
|
|
import Handler from '../lib/plugins/handler.js'
|
|
|
|
|
|
|
|
|
|
import {
|
|
|
|
|
gsCfg,
|
|
|
|
|
mysApi as MysApi,
|
|
|
|
|
mysInfo as MysInfo,
|
|
|
|
|
NoteUser,
|
|
|
|
|
MysUser
|
|
|
|
|
} from '../mys/index.js'
|
2024-06-09 01:00:07 +08:00
|
|
|
|
|
|
|
|
|
/**
|
2024-06-09 01:31:31 +08:00
|
|
|
|
* ********************
|
2024-06-09 01:00:07 +08:00
|
|
|
|
* 对e进行重构的危险代码
|
2024-06-09 01:31:31 +08:00
|
|
|
|
* ********************
|
|
|
|
|
* tudo
|
|
|
|
|
* 写法混乱,需要重构
|
2024-06-09 01:00:07 +08:00
|
|
|
|
*/
|
|
|
|
|
export default class Runtime {
|
|
|
|
|
e = null
|
|
|
|
|
_mysInfo = null
|
|
|
|
|
handler = null
|
|
|
|
|
|
2024-06-09 11:40:24 +08:00
|
|
|
|
/**
|
|
|
|
|
*
|
|
|
|
|
* @param e
|
|
|
|
|
*/
|
2024-06-09 01:00:07 +08:00
|
|
|
|
constructor(e) {
|
|
|
|
|
this.e = e
|
|
|
|
|
this._mysInfo = {}
|
|
|
|
|
this.handler = {
|
|
|
|
|
has: Handler.has,
|
|
|
|
|
call: Handler.call,
|
|
|
|
|
callAll: Handler.callAll
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-06-09 11:40:24 +08:00
|
|
|
|
/**
|
|
|
|
|
*
|
|
|
|
|
*/
|
2024-06-09 01:00:25 +08:00
|
|
|
|
get uid() {
|
2024-06-09 01:00:07 +08:00
|
|
|
|
return this.user?.uid
|
|
|
|
|
}
|
|
|
|
|
|
2024-06-09 11:40:24 +08:00
|
|
|
|
/**
|
|
|
|
|
*
|
|
|
|
|
*/
|
2024-06-09 01:00:25 +08:00
|
|
|
|
get hasCk() {
|
2024-06-09 01:00:07 +08:00
|
|
|
|
return this.user?.hasCk
|
|
|
|
|
}
|
|
|
|
|
|
2024-06-09 11:40:24 +08:00
|
|
|
|
/**
|
|
|
|
|
*
|
|
|
|
|
*/
|
2024-06-09 01:00:25 +08:00
|
|
|
|
get user() {
|
2024-06-09 01:00:07 +08:00
|
|
|
|
return this.e.user
|
|
|
|
|
}
|
|
|
|
|
|
2024-06-09 11:40:24 +08:00
|
|
|
|
/**
|
|
|
|
|
*
|
|
|
|
|
*/
|
2024-06-09 01:00:25 +08:00
|
|
|
|
get cfg() {
|
2024-06-09 01:00:07 +08:00
|
|
|
|
return cfg
|
|
|
|
|
}
|
|
|
|
|
|
2024-06-09 11:40:24 +08:00
|
|
|
|
/**
|
|
|
|
|
*
|
|
|
|
|
*/
|
2024-06-09 01:00:25 +08:00
|
|
|
|
get gsCfg() {
|
2024-06-09 01:00:07 +08:00
|
|
|
|
return gsCfg
|
|
|
|
|
}
|
|
|
|
|
|
2024-06-09 11:40:24 +08:00
|
|
|
|
/**
|
|
|
|
|
*
|
|
|
|
|
*/
|
2024-06-09 01:00:25 +08:00
|
|
|
|
get common() {
|
2024-06-09 01:00:07 +08:00
|
|
|
|
return common
|
|
|
|
|
}
|
|
|
|
|
|
2024-06-09 01:31:31 +08:00
|
|
|
|
/**
|
|
|
|
|
* @deprecated 不符合架构设计,已废弃
|
|
|
|
|
*/
|
2024-06-09 01:00:25 +08:00
|
|
|
|
get puppeteer() {
|
2024-06-09 01:31:31 +08:00
|
|
|
|
return null
|
2024-06-09 01:00:07 +08:00
|
|
|
|
}
|
|
|
|
|
|
2024-06-09 11:40:24 +08:00
|
|
|
|
/**
|
|
|
|
|
*
|
|
|
|
|
*/
|
2024-06-09 01:00:25 +08:00
|
|
|
|
get MysInfo() {
|
2024-06-09 01:00:07 +08:00
|
|
|
|
return MysInfo
|
|
|
|
|
}
|
|
|
|
|
|
2024-06-09 11:40:24 +08:00
|
|
|
|
/**
|
|
|
|
|
*
|
|
|
|
|
*/
|
2024-06-09 01:00:25 +08:00
|
|
|
|
get NoteUser() {
|
2024-06-09 01:00:07 +08:00
|
|
|
|
return NoteUser
|
|
|
|
|
}
|
|
|
|
|
|
2024-06-09 11:40:24 +08:00
|
|
|
|
/**
|
|
|
|
|
*
|
|
|
|
|
*/
|
2024-06-09 01:00:25 +08:00
|
|
|
|
get MysUser() {
|
2024-06-09 01:00:07 +08:00
|
|
|
|
return MysUser
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2024-06-09 01:00:25 +08:00
|
|
|
|
*
|
|
|
|
|
* @param e
|
|
|
|
|
* @returns
|
2024-06-09 01:00:07 +08:00
|
|
|
|
*/
|
2024-06-09 01:00:25 +08:00
|
|
|
|
static async init(e) {
|
2024-06-09 01:00:07 +08:00
|
|
|
|
await MysInfo.initCache()
|
|
|
|
|
let runtime = new Runtime(e)
|
|
|
|
|
e.runtime = runtime
|
|
|
|
|
await runtime.initUser()
|
|
|
|
|
return runtime
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2024-06-09 01:31:31 +08:00
|
|
|
|
* 初始化
|
2024-06-09 01:00:07 +08:00
|
|
|
|
*/
|
2024-06-09 01:00:25 +08:00
|
|
|
|
async initUser() {
|
2024-06-09 01:00:07 +08:00
|
|
|
|
let e = this.e
|
|
|
|
|
let user = await NoteUser.create(e)
|
|
|
|
|
if (user) {
|
2024-06-09 01:31:31 +08:00
|
|
|
|
// 对象代理
|
2024-06-09 01:00:07 +08:00
|
|
|
|
e.user = new Proxy(user, {
|
2024-06-09 01:00:25 +08:00
|
|
|
|
get(self, key, receiver) {
|
2024-06-09 01:00:07 +08:00
|
|
|
|
let game = e.game
|
|
|
|
|
let fnMap = {
|
|
|
|
|
uid: 'getUid',
|
|
|
|
|
uidList: 'getUidList',
|
|
|
|
|
mysUser: 'getMysUser',
|
|
|
|
|
ckUidList: 'getCkUidList'
|
|
|
|
|
}
|
|
|
|
|
if (fnMap[key]) {
|
|
|
|
|
return self[fnMap[key]](game)
|
|
|
|
|
}
|
|
|
|
|
if (key === 'uidData') {
|
|
|
|
|
return self.getUidData('', game)
|
|
|
|
|
}
|
2024-06-09 01:31:31 +08:00
|
|
|
|
// 不能将类型“symbol”分配给类型“string”。
|
2024-06-09 01:00:25 +08:00
|
|
|
|
if (
|
|
|
|
|
[
|
|
|
|
|
'getUid',
|
|
|
|
|
'getUidList',
|
|
|
|
|
'getMysUser',
|
|
|
|
|
'getCkUidList',
|
|
|
|
|
'getUidMapList',
|
|
|
|
|
'getGameDs'
|
2024-06-09 01:31:31 +08:00
|
|
|
|
].includes(key as string)
|
2024-06-09 01:00:25 +08:00
|
|
|
|
) {
|
2024-06-09 01:00:07 +08:00
|
|
|
|
return (_game, arg2) => {
|
|
|
|
|
return self[key](_game || game, arg2)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// 不能将类型“symbol”分配给类型“string”。
|
2024-06-09 01:00:25 +08:00
|
|
|
|
if (
|
|
|
|
|
[
|
|
|
|
|
'getUidData',
|
|
|
|
|
'hasUid',
|
|
|
|
|
'addRegUid',
|
|
|
|
|
'delRegUid',
|
|
|
|
|
'setMainUid'
|
2024-06-09 01:31:31 +08:00
|
|
|
|
].includes(key as string)
|
2024-06-09 01:00:25 +08:00
|
|
|
|
) {
|
2024-06-09 01:00:07 +08:00
|
|
|
|
return (uid, _game = '') => {
|
|
|
|
|
return self[key](uid, _game || game)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return self[key]
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 获取MysInfo实例
|
|
|
|
|
*
|
|
|
|
|
* @param targetType all: 所有用户均可, cookie:查询用户必须具备Cookie
|
|
|
|
|
* @returns {Promise<boolean|MysInfo>}
|
|
|
|
|
*/
|
2024-06-09 01:00:25 +08:00
|
|
|
|
async getMysInfo(targetType = 'all') {
|
2024-06-09 01:00:07 +08:00
|
|
|
|
if (!this._mysInfo[targetType]) {
|
2024-06-09 01:00:25 +08:00
|
|
|
|
this._mysInfo[targetType] = await MysInfo.init(
|
|
|
|
|
this.e,
|
|
|
|
|
targetType === 'cookie' ? 'detail' : 'roleIndex'
|
|
|
|
|
)
|
2024-06-09 01:00:07 +08:00
|
|
|
|
}
|
|
|
|
|
return this._mysInfo[targetType]
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2024-06-09 01:00:25 +08:00
|
|
|
|
*
|
|
|
|
|
* @returns
|
2024-06-09 01:00:07 +08:00
|
|
|
|
*/
|
2024-06-09 01:00:25 +08:00
|
|
|
|
async getUid() {
|
2024-06-09 01:00:07 +08:00
|
|
|
|
return await MysInfo.getUid(this.e)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 获取MysApi实例
|
|
|
|
|
*
|
|
|
|
|
* @param targetType all: 所有用户均可, cookie:查询用户必须具备Cookie
|
|
|
|
|
* @param option MysApi option
|
|
|
|
|
* @param isSr 是否为星穹铁道
|
|
|
|
|
* @returns {Promise<boolean|MysApi>}
|
|
|
|
|
*/
|
2024-06-09 01:00:25 +08:00
|
|
|
|
async getMysApi(targetType = 'all', option = {}, isSr = false) {
|
2024-06-09 01:00:07 +08:00
|
|
|
|
let mys = await this.getMysInfo(targetType)
|
|
|
|
|
if (mys.uid && mys?.ckInfo?.ck) {
|
|
|
|
|
return new MysApi(mys.uid, mys.ckInfo.ck, option, isSr)
|
|
|
|
|
}
|
|
|
|
|
return false
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 生成MysApi实例
|
|
|
|
|
* @param uid
|
|
|
|
|
* @param ck
|
|
|
|
|
* @param option
|
|
|
|
|
* @param isSr 是否为星穹铁道
|
|
|
|
|
* @returns {Promise<MysApi>}
|
|
|
|
|
*/
|
2024-06-09 01:00:25 +08:00
|
|
|
|
async createMysApi(uid, ck, option, isSr = false) {
|
2024-06-09 01:00:07 +08:00
|
|
|
|
return new MysApi(uid, ck, option, isSr)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2024-06-09 01:31:31 +08:00
|
|
|
|
* @deprecated 不符合架构设计,已废弃
|
2024-06-09 01:00:07 +08:00
|
|
|
|
*/
|
2024-06-09 01:00:25 +08:00
|
|
|
|
async render(plugin, path, data = {}, cfg = {}) {
|
2024-06-09 01:31:31 +08:00
|
|
|
|
return false
|
2024-06-09 01:00:07 +08:00
|
|
|
|
}
|
2024-06-09 01:00:25 +08:00
|
|
|
|
}
|