2022-10-21 14:48:19 +00:00
|
|
|
import { Data } from '../../components/index.js'
|
2022-09-20 11:50:27 +00:00
|
|
|
|
2022-10-21 14:48:19 +00:00
|
|
|
let YzMysInfo = false
|
2022-09-20 12:16:19 +00:00
|
|
|
let MysUser = false
|
2022-09-20 11:50:27 +00:00
|
|
|
|
|
|
|
async function init () {
|
|
|
|
let mys = await Data.importModule('plugins/genshin/model/mys/mysInfo.js', 'root')
|
|
|
|
if (mys && mys.default) {
|
2022-10-21 14:48:19 +00:00
|
|
|
YzMysInfo = mys.default
|
2022-09-20 12:16:19 +00:00
|
|
|
} else {
|
|
|
|
let module = await Data.importModule('lib/components/models/MysUser.js', 'root')
|
|
|
|
if (module && module.default) {
|
|
|
|
MysUser = module.default
|
|
|
|
}
|
2022-09-20 11:50:27 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
await init()
|
|
|
|
|
2022-10-21 14:48:19 +00:00
|
|
|
if (!YzMysInfo) {
|
2022-09-20 11:50:27 +00:00
|
|
|
// v2 MysInfo
|
2022-10-21 14:48:19 +00:00
|
|
|
YzMysInfo = class {
|
2022-09-20 11:50:27 +00:00
|
|
|
constructor (e, uid, cookieUser) {
|
|
|
|
if (e) {
|
|
|
|
this.e = e
|
|
|
|
this.userId = String(e.user_id)
|
|
|
|
}
|
|
|
|
this.uid = uid
|
|
|
|
this.ckInfo = {
|
|
|
|
ck: cookieUser.cookie,
|
|
|
|
uid: cookieUser.uid
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-10-25 20:11:01 +00:00
|
|
|
static async init (e, api) {
|
|
|
|
let MysApi = await e.getMysApi({
|
|
|
|
auth: 'all',
|
|
|
|
targetType: 'all',
|
|
|
|
cookieType: api === 'detail' ? 'self:' : 'all'
|
|
|
|
}) // V2兼容
|
2022-09-20 12:16:19 +00:00
|
|
|
let { selfUser, targetUser, cookieUser } = MysApi
|
2022-10-21 14:48:19 +00:00
|
|
|
let mys = new YzMysInfo(e, targetUser.uid || selfUser.uid, cookieUser)
|
2022-09-20 11:50:27 +00:00
|
|
|
mys._MysApi = MysApi
|
|
|
|
return mys
|
|
|
|
}
|
|
|
|
|
|
|
|
// 检查当前UID是否有CK绑定
|
|
|
|
static async checkUidBing (uid) {
|
2022-09-20 12:16:19 +00:00
|
|
|
let user = await MysUser.get(uid)
|
|
|
|
return user.cookie
|
2022-09-20 11:50:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static async getUid (e) {
|
2022-09-20 12:16:19 +00:00
|
|
|
let user = await e.checkAuth({
|
|
|
|
auth: 'all'
|
|
|
|
})
|
2022-09-27 04:21:46 +00:00
|
|
|
if (!user || !user.getMysUser) {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
let mysUser = await user.getMysUser()
|
|
|
|
return mysUser ? mysUser.uid : false
|
2022-09-20 11:50:27 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-10-21 14:48:19 +00:00
|
|
|
export default YzMysInfo
|