2022-08-18 10:13:42 +00:00
|
|
|
|
import Cfg from './Cfg.js'
|
2022-08-24 01:07:06 +00:00
|
|
|
|
import { Data, Version } from './index.js'
|
|
|
|
|
import { puppeteer } from '../adapter/index.js'
|
2022-08-31 18:26:36 +00:00
|
|
|
|
import fs from 'fs'
|
2022-08-24 01:07:06 +00:00
|
|
|
|
|
|
|
|
|
const plugin = 'miao-plugin'
|
|
|
|
|
const _path = process.cwd()
|
2022-05-22 13:10:10 +00:00
|
|
|
|
|
|
|
|
|
export const render = async function (path, params, cfg) {
|
2022-08-24 01:07:06 +00:00
|
|
|
|
let [app, tpl] = path.split('/')
|
|
|
|
|
let { e } = cfg
|
2022-07-23 20:32:10 +00:00
|
|
|
|
let layoutPath = process.cwd() + '/plugins/miao-plugin/resources/common/layout/'
|
2022-08-24 01:07:06 +00:00
|
|
|
|
let resPath = `../../../../../plugins/${plugin}/resources/`
|
|
|
|
|
Data.createDir(_path + '/data/', `html/${plugin}/${app}/${tpl}`)
|
|
|
|
|
let data = {
|
2022-05-22 13:10:10 +00:00
|
|
|
|
...params,
|
2022-08-24 01:07:06 +00:00
|
|
|
|
_plugin: plugin,
|
|
|
|
|
saveId: params.saveId || params.save_id || tpl,
|
|
|
|
|
tplFile: `./plugins/${plugin}/resources/${app}/${tpl}.html`,
|
|
|
|
|
pluResPath: resPath,
|
|
|
|
|
_res_path: resPath,
|
2022-07-23 20:32:10 +00:00
|
|
|
|
_layout_path: layoutPath,
|
2022-08-02 19:12:07 +00:00
|
|
|
|
_tpl_path: process.cwd() + '/plugins/miao-plugin/resources/common/tpl/',
|
2022-07-23 20:32:10 +00:00
|
|
|
|
defaultLayout: layoutPath + 'default.html',
|
|
|
|
|
elemLayout: layoutPath + 'elem.html',
|
2022-05-22 13:10:10 +00:00
|
|
|
|
sys: {
|
|
|
|
|
scale: Cfg.scale(cfg.scale || 1),
|
2022-08-18 10:13:42 +00:00
|
|
|
|
copyright: `Created By Yunzai-Bot<span class="version">${Version.yunzai}</span> & Miao-Plugin<span class="version">${Version.version}</span>`
|
2022-05-22 13:10:10 +00:00
|
|
|
|
}
|
2022-08-24 01:07:06 +00:00
|
|
|
|
}
|
2022-08-31 18:26:36 +00:00
|
|
|
|
if (global.debugView === 'web-debug') {
|
|
|
|
|
// debug下保存当前页面的渲染数据,方便模板编写与调试
|
|
|
|
|
// 由于只用于调试,开发者只关注自己当时开发的文件即可,暂不考虑app及plugin的命名冲突
|
|
|
|
|
let saveDir = _path + '/data/ViewData/'
|
|
|
|
|
if (!fs.existsSync(saveDir)) {
|
|
|
|
|
fs.mkdirSync(saveDir)
|
|
|
|
|
}
|
|
|
|
|
let file = saveDir + tpl + '.json'
|
|
|
|
|
data._app = app
|
|
|
|
|
fs.writeFileSync(file, JSON.stringify(data))
|
|
|
|
|
}
|
2022-08-24 01:07:06 +00:00
|
|
|
|
let base64 = await puppeteer.screenshot(`miao-plugin/${app}/${tpl}`, data)
|
2022-07-30 21:06:00 +00:00
|
|
|
|
let ret = true
|
2022-05-22 13:10:10 +00:00
|
|
|
|
if (base64) {
|
2022-08-24 01:07:06 +00:00
|
|
|
|
ret = await e.reply(base64)
|
2022-05-22 13:10:10 +00:00
|
|
|
|
}
|
2022-07-30 21:06:00 +00:00
|
|
|
|
return cfg.retMsgId ? ret : true
|
2022-05-22 13:10:10 +00:00
|
|
|
|
}
|
|
|
|
|
|
2022-07-23 20:32:10 +00:00
|
|
|
|
export const todoV3 = function (e) {
|
2022-08-18 10:13:42 +00:00
|
|
|
|
if (Version.isV3) {
|
2022-07-23 20:32:10 +00:00
|
|
|
|
e.reply('本功能暂时不支持V3版Yunzai...')
|
|
|
|
|
return true
|
|
|
|
|
}
|
|
|
|
|
return false
|
|
|
|
|
}
|
2022-05-22 13:10:10 +00:00
|
|
|
|
|
2022-08-01 21:15:37 +00:00
|
|
|
|
function sleep (ms) {
|
|
|
|
|
return new Promise((resolve) => setTimeout(resolve, ms))
|
|
|
|
|
}
|
|
|
|
|
|
2022-05-22 13:10:10 +00:00
|
|
|
|
export default {
|
|
|
|
|
render,
|
|
|
|
|
cfg: Cfg.get,
|
2022-07-23 20:32:10 +00:00
|
|
|
|
isDisable: Cfg.isDisable,
|
2022-08-01 21:15:37 +00:00
|
|
|
|
todoV3,
|
|
|
|
|
sleep
|
2022-07-23 20:32:10 +00:00
|
|
|
|
}
|