1
- import Config from '../components/Config.js'
2
1
import common from '../../../lib/common/common.js'
3
2
import puppeteer from './puppeteer.js'
4
-
5
-
3
+ import { Data , Version , Plugin_Name , Display_Plugin_Name , Config } from '../components/index.js'
4
+ import { _path , pluginResources , imgPath , tempPath } from './path.js'
5
+ import fCompute from './fCompute.js'
6
+ import fs from 'node:fs'
6
7
class picmodle {
7
8
8
9
constructor ( ) {
@@ -14,17 +15,22 @@ class picmodle {
14
15
this . rendering = [ ]
15
16
/**
16
17
* puppeteer队列
17
- * @param { [ puppeteer] } puppeteer
18
+ * @type { puppeteer[] }
18
19
*/
19
20
this . puppeteer = [ ]
20
21
this . tot = 0
21
22
}
22
23
23
24
async init ( ) {
25
+ /** 清理临时文件 */
26
+ fs . rmSync ( tempPath , { force : true , recursive : true } )
27
+ /** 初始化puppeteer实例 */
24
28
let num = Config . getUserCfg ( 'config' , 'renderNum' )
25
29
for ( let i = 0 ; i < num ; i ++ ) {
26
- this . puppeteer . push ( new puppeteer ( i ) )
27
- this . puppeteer [ i ] . init ( i )
30
+ this . puppeteer . push ( new puppeteer ( {
31
+ puppeteerTimeout : Config . getUserCfg ( 'config' , 'timeout' )
32
+ } , i ) )
33
+ this . puppeteer [ i ] . browserInit ( i )
28
34
this . queue . push ( i )
29
35
}
30
36
}
@@ -170,8 +176,42 @@ class picmodle {
170
176
puppeteerNum = this . queue . shift ( )
171
177
this . torender . shift ( )
172
178
try {
179
+
180
+ let [ app , tpl ] = path . split ( '/' )
181
+ let layoutPath = pluginResources . replace ( / \\ / g, '/' ) + `/html/common/layout/`
182
+ let resPath = pluginResources . replace ( / \\ / g, '/' ) + `/`
183
+
184
+
185
+ Data . createDir ( `data/html/${ Plugin_Name } /${ app } /${ tpl } ` , 'root' )
186
+ let data = {
187
+ ...params ,
188
+ waitUntil : [ 'networkidle0' , 'load' ] ,
189
+ saveId : ( params . saveId || params . save_id || tpl ) + `${ this . id } ` ,
190
+ tplFile : `./plugins/${ Plugin_Name } /resources/html/${ app } /${ tpl } .art` ,
191
+ pluResPath : resPath ,
192
+ _res_path : resPath ,
193
+ _imgPath : imgPath + '/' ,
194
+ _layout_path : layoutPath ,
195
+ defaultLayout : layoutPath + 'default.art' ,
196
+ elemLayout : layoutPath + 'elem.art' ,
197
+ pageGotoParams : {
198
+ waitUntil : [ 'networkidle2' , 'load' ] ,
199
+ timeout : Config . getUserCfg ( 'config' , 'timeout' ) ,
200
+ } ,
201
+ sys : {
202
+ scale : `style=transform:scale(${ cfg . scale || 1 } )` ,
203
+ copyright : `Created By Yunzai-Bot<span class="version">${ Version . yunzai } </span> & phi-Plugin<span class="version">${ Version . ver } </span>`
204
+ } ,
205
+ Version : { ...Version } ,
206
+ _plugin : Display_Plugin_Name ,
207
+ Math,
208
+ fCompute,
209
+ }
210
+
211
+ /**返回图片信息 */
173
212
this . rendering . push ( id )
174
- ans = await this . puppeteer [ puppeteerNum ] . render ( path , params , cfg )
213
+ ans = segment . image ( await this . puppeteer [ puppeteerNum ] . screenshot ( `${ Plugin_Name } /${ app } /${ tpl } ` , data ) )
214
+
175
215
} catch ( err ) {
176
216
logger . error ( `[Phi-Plugin][渲染失败]` , id )
177
217
logger . error ( err )
0 commit comments