From 9e9073971e3f4318ee3602a2406a1b19173cbb89 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=F0=9F=8C=8C?= Date: Thu, 1 Jun 2023 15:02:01 +0800 Subject: [PATCH] =?UTF-8?q?=E5=90=8C=E6=AD=A5=20Miao-Yunzai=20=E6=9B=B4?= =?UTF-8?q?=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/plugins/runtime.js | 48 ++++++++++++++++++++++++++++++++++++------ lib/tools/web.js | 8 +++---- package.json | 4 ++-- 3 files changed, 46 insertions(+), 14 deletions(-) diff --git a/lib/plugins/runtime.js b/lib/plugins/runtime.js index 1dbf7b8..83d379a 100644 --- a/lib/plugins/runtime.js +++ b/lib/plugins/runtime.js @@ -67,9 +67,47 @@ export default class Runtime { } static async init (e) { - e.runtime = new Runtime(e) - e.user = await MysInfo.getNoteUser(e) - return e.runtime + await MysInfo.initCache() + let runtime = new Runtime(e) + e.runtime = runtime + e.game = e.isSr ? 'sr' : 'gs' + await runtime.initUser() + return runtime + } + + async initUser () { + let e = this.e + let user = await NoteUser.create(e) + if (user) { + e.user = new Proxy(user, { + get (self, key, receiver) { + let game = e.isSr ? 'sr' : 'gs' + 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) + } + if (['getUid', 'getUidList', 'getMysUser', 'getCkUidList', 'getUidMapList', 'getGameDs'].includes(key)) { + return (_game, arg2) => { + return self[key](_game || game, arg2) + } + } + if (['getUidData', 'hasUid', 'addRegUid', 'delRegUid', 'setMainUid'].includes(key)) { + return (uid, _game = '') => { + return self[key](uid, _game || game) + } + } + return self[key] + } + }) + } } /** @@ -89,10 +127,6 @@ export default class Runtime { return await MysInfo.getUid(this.e) } - async getSelfUid () { - return await MysInfo.getSelfUid(this.e) - } - /** * 获取MysApi实例 * diff --git a/lib/tools/web.js b/lib/tools/web.js index aedb808..32ff156 100644 --- a/lib/tools/web.js +++ b/lib/tools/web.js @@ -46,7 +46,8 @@ app.get('/', function (req, res) { }) app.get('/:page', function (req, res) { - let [plugin, app, page] = req.params.page.split('_') + let [plugin, app, ...page] = req.params.page.split('_') + page = page.join('_') if (plugin == 'favicon.ico') { return res.send('') } @@ -60,12 +61,9 @@ app.get('/:page', function (req, res) { data.pluResPath = data._res_path } let htmlPath = '' - if (data._plugin === 'genshin') { - htmlPath = 'html/' - } let tplPath = `${app}/${htmlPath}${page}/${page}.html` if (data._plugin) { - tplPath = `../plugins/${data._plugin}/resources/${htmlPath}/${app}/${page}.html` + tplPath = `../plugins/${data._plugin}/resources/${htmlPath}/${app}/${page.split('_').join('/')}.html` } else if (data._no_type_path) { tplPath = `${app}/${page}.html` } diff --git a/package.json b/package.json index 50a3eb4..617f0f0 100644 --- a/package.json +++ b/package.json @@ -30,8 +30,8 @@ "node-schedule": "^2.1.1", "node-xlsx": "^0.23.0", "pm2": "^5.3.0", - "puppeteer": "^20.4.0", - "redis": "^4.6.6", + "puppeteer": "^20.5.0", + "redis": "^4.6.7", "sequelize": "^6.31.1", "sqlite3": "^5.1.6", "ws": "^8.13.0",