将html、material、strategy等可丢数据移至temp目录,便于后期清理

This commit is contained in:
Kokomi 2023-03-05 07:41:36 +08:00
parent f00c709147
commit 2185f65962
9 changed files with 113 additions and 31 deletions

1
.gitignore vendored
View File

@ -142,3 +142,4 @@ redis
yunzai
/.idea/
/data/
/temp/

View File

@ -9,7 +9,7 @@
* 使用icqq登录防止oicq可能出现的低版本问题如只需要此特性可使用[Yunzai-V3](https://gitee.com/yoimiya-kokomi/Yunzai-Bot) )
* 基础功能会保持与Yunzai同步迭代更新如只需原版Yunzai无需切换
## Miao-Yunzai后续计划
## Miao-Yunzai后续计划no
先刨坑,但也许会咕咕咕

View File

@ -23,12 +23,6 @@ export default class Runtime {
this._mysInfo = {}
}
static async init (e) {
e.runtime = new Runtime(e)
e.user = await MysInfo.getNoteUser(e)
return e.runtime
}
get uid () {
return this.user?.uid
}
@ -61,6 +55,12 @@ export default class Runtime {
return MysInfo
}
static async init (e) {
e.runtime = new Runtime(e)
e.user = await MysInfo.getNoteUser(e)
return e.runtime
}
/**
* 获取MysInfo实例
*
@ -128,7 +128,7 @@ export default class Runtime {
path = paths.join('/')
// 创建目录
const mkdir = (check) => {
let currDir = `${process.cwd()}/data`
let currDir = `${process.cwd()}/temp`
for (let p of check.split('/')) {
currDir = `${currDir}/${p}`
if (!fs.existsSync(currDir)) {
@ -157,7 +157,8 @@ export default class Runtime {
data = cfg.beforeRender({ data }) || data
}
// 保存模板数据
if (process.argv.includes('web-debug')) {
console.log(process.argv)
if (process.argv.includes('dev')) {
// debug下保存当前页面的渲染数据方便模板编写与调试
// 由于只用于调试开发者只关注自己当时开发的文件即可暂不考虑app及plugin的命名冲突
let saveDir = mkdir(`ViewData/${plugin}`)

View File

@ -37,7 +37,8 @@ class Puppeteer {
this.html = {}
this.watcher = {}
this.createDir('./data/html')
this.createDir('./temp')
this.createDir('./temp/html')
}
async initPupp () {
@ -166,11 +167,11 @@ class Puppeteer {
/** 模板 */
dealTpl (name, data) {
let { tplFile, saveId = name } = data
let savePath = `./data/html/${name}/${saveId}.html`
let savePath = `./temp/html/${name}/${saveId}.html`
/** 读取html模板 */
if (!this.html[tplFile]) {
this.createDir(`./data/html/${name}`)
this.createDir(`./temp/html/${name}`)
try {
this.html[tplFile] = fs.readFileSync(tplFile, 'utf8')

76
lib/tools/web.js Normal file
View File

@ -0,0 +1,76 @@
import express from 'express'
import template from 'express-art-template'
import fs from 'fs'
import lodash from 'lodash'
/*
* npm run app web-debug开启Bot后
* 可另外通过 npm run web 开启浏览器调试
* 访问 http://localhost:8000/ 即可看到对应页面
* 页面内的资源需使用 {{_res_path}}来作为resources目录的根目录
* 可编辑模板与页面查看效果
* todo: 预览页面的热更
*
* */
let app = express()
let _path = process.cwd()
app.engine('html', template)
app.set('views', _path + '/resources/')
app.set('view engine', 'art')
app.use(express.static(_path + '/resources'))
app.use('/plugins', express.static('plugins'))
app.get('/', function (req, res) {
let pluginList = fs.readdirSync(_path + '/temp/ViewData/') || []
let html = [
'在npm run web-dev模式下触发截图消息后可在下方选择页面进行调试',
'如果页面内资源路径不正确请使用{{_res_path}}作为根路径,对应之前的../../../../',
'可直接修改模板html或css刷新查看效果'
]
let li = {}
for (let pIdx in pluginList) {
const plugin = pluginList[pIdx]
let fileList = fs.readdirSync(_path + `/temp/ViewData/${plugin}/`) || []
for (let idx in fileList) {
let ret = /(.+)\.json$/.exec(fileList[idx])
if (ret && ret[1]) {
let text = [plugin, ...ret[1].split('_')]
li[text.join('')] = (`<li style="font-size:18px; line-height:30px;"><a href="/${plugin}_${ret[1]}">${text.join(' / ')}</a></li>`)
}
}
}
res.send(html.join('</br>') + '<ul>' + lodash.values(li).join('') + '</ul>')
})
app.get('/:page', function (req, res) {
let [plugin, app, page] = req.params.page.split('_')
if (plugin == 'favicon.ico') {
return res.send('')
}
let data = JSON.parse(fs.readFileSync(_path + `/temp/ViewData/${plugin}/${app}_${page}.json`, 'utf8'))
data = data || {}
data._res_path = ''
data._sys_res_path = data._res_path
if (data._plugin) {
data._res_path = `/plugins/${data._plugin}/resources/`
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`
} else if (data._no_type_path) {
tplPath = `${app}/${page}.html`
}
res.render(tplPath, data)
})
app.listen(8000)
console.log('页面服务已启动,触发消息图片后访问 http://localhost:8000/ 调试页面')

View File

@ -6,9 +6,11 @@
"type": "module",
"scripts": {
"app": "node app.js",
"web-debug": "node app.js --web-debug",
"dev": "node app.js dev",
"web": "node ./lib/tools/web.js",
"test": "node ./lib/tools/test.js",
"login": "node app.js login",
"dev": "node app.js dev",
"start": "pm2 start ./config/pm2/pm2.json",
"stop": "pm2 stop ./config/pm2/pm2.json",
"restart": "pm2 restart ./config/pm2/pm2.json",

View File

@ -21,8 +21,8 @@ export class material extends plugin {
]
})
this.path = './data/material_友人A'
this.pathOther = './data/material_other'
this.path = './temp/material/友人A'
this.pathOther = './temp/material/other'
this.url = 'https://bbs-api.mihoyo.com/post/wapi/getPostFullInCollection?&gids=2&order_type=2&collection_id='
this.collection_id = [428421, 1164644, 1362644]
@ -34,11 +34,10 @@ export class material extends plugin {
/** 初始化创建配置文件 */
async init () {
if (!fs.existsSync(this.path)) {
fs.mkdirSync(this.path)
}
if (!fs.existsSync(this.pathOther)) {
fs.mkdirSync(this.pathOther)
for (let dir of ['./temp', './temp/material', this.path, this.pathOther]) {
if (!fs.existsSync(dir)) {
fs.mkdirSync(dir)
}
}
}

View File

@ -41,7 +41,7 @@ export class strategy extends plugin {
this.set = gsCfg.getConfig('mys', 'set')
this.path = './data/strategy'
this.path = './temp/strategy'
this.url = 'https://bbs-api.mihoyo.com/post/wapi/getPostFullInCollection?&gids=2&order_type=2&collection_id='
this.collection_id = [

View File

@ -63,6 +63,12 @@ importers:
express: 4.18.1
express-art-template: 1.0.1_art-template@4.13.2
plugins/miao-plugin:
specifiers:
image-size: ^1.0.2
dependencies:
image-size: registry.npmmirror.com/image-size/1.0.2
packages:
/@eslint/eslintrc/1.3.0:
@ -441,7 +447,7 @@ packages:
resolution: {integrity: sha512-1W07cM9gS6DcLperZfFSj+bWLtaPGSOHWhPiGzXmvVJbRLdG82sH/Kn8EtW1VqWVA54AKf2h5k5BbnIbwF3h6w==}
dependencies:
buffer: 5.7.1
inherits: 2.0.4
inherits: registry.npmmirror.com/inherits/2.0.4
readable-stream: 3.6.0
dev: false
@ -1533,7 +1539,7 @@ packages:
dependencies:
fs.realpath: 1.0.0
inflight: 1.0.6
inherits: 2.0.4
inherits: registry.npmmirror.com/inherits/2.0.4
minimatch: 3.1.2
once: 1.4.0
path-is-absolute: 1.0.1
@ -1601,7 +1607,7 @@ packages:
engines: {node: '>= 0.8'}
dependencies:
depd: 2.0.0
inherits: 2.0.4
inherits: registry.npmmirror.com/inherits/2.0.4
setprototypeof: 1.2.0
statuses: 2.0.1
toidentifier: 1.0.1
@ -1661,9 +1667,6 @@ packages:
once: 1.4.0
wrappy: 1.0.2
/inherits/2.0.4:
resolution: {integrity: sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ==}
/ini/1.3.8:
resolution: {integrity: sha512-JV/yugV2uzW5iMRSiZAyDtQd+nxtUnjeLt0acNdw98kKLrvuRVyB80tsREOE7yvGVgalhZ6RNXCmEHkUKBKxew==}
dev: false
@ -2622,7 +2625,7 @@ packages:
resolution: {integrity: sha512-+MeVjFf4L44XUkhM1eYbD8fyEsxcV81pqMSR5gblfcLCHfZvbrqy4/qYHE+/R5HoBUT11WV5O08Cr1n3YXkWVQ==}
dependencies:
core-util-is: 1.0.3
inherits: 2.0.4
inherits: registry.npmmirror.com/inherits/2.0.4
isarray: 0.0.1
string_decoder: 0.10.31
dev: false
@ -2631,7 +2634,7 @@ packages:
resolution: {integrity: sha512-BViHy7LKeTz4oNnkcLJ+lVSL6vpiFeX6/d3oSH8zCW7UxP2onchk+vTGB143xuFjHS3deTgkKoXXymXqymiIdA==}
engines: {node: '>= 6'}
dependencies:
inherits: 2.0.4
inherits: registry.npmmirror.com/inherits/2.0.4
string_decoder: 1.3.0
util-deprecate: 1.0.2
dev: false
@ -3000,7 +3003,7 @@ packages:
bl: 4.1.0
end-of-stream: 1.4.4
fs-constants: 1.0.0
inherits: 2.0.4
inherits: registry.npmmirror.com/inherits/2.0.4
readable-stream: 3.6.0
dev: false
@ -3604,7 +3607,6 @@ packages:
resolution: {integrity: sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ==, registry: https://registry.npm.taobao.org/, tarball: https://registry.npmmirror.com/inherits/-/inherits-2.0.4.tgz}
name: inherits
version: 2.0.4
dev: false
registry.npmmirror.com/jsonfile/6.1.0:
resolution: {integrity: sha512-5dgndWOriYSm5cnYaJNhalLNDKOqFwyDB/rr1E9ZsGciGvKPs8R2xYGCacuf3z6K1YKDz182fd+fY3cn3pMqXQ==, registry: https://registry.npm.taobao.org/, tarball: https://registry.npmmirror.com/jsonfile/-/jsonfile-6.1.0.tgz}