node-karin 0.0.3 → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (109) hide show
  1. package/LICENSE +674 -674
  2. package/README.md +57 -57
  3. package/config/defSet/App.yaml +37 -37
  4. package/config/defSet/config.yaml +43 -43
  5. package/config/defSet/group.yaml +18 -18
  6. package/config/defSet/pm2.yaml +21 -21
  7. package/config/defSet/server.yaml +42 -42
  8. package/config/view/App.yaml +74 -74
  9. package/config/view/config.yaml +100 -100
  10. package/config/view/group.yaml +62 -62
  11. package/config/view/pm2.yaml +41 -41
  12. package/config/view/redis.yaml +25 -25
  13. package/config/view/server.yaml +93 -93
  14. package/lib/adapter/onebot/onebot11.d.ts +430 -430
  15. package/lib/adapter/onebot/onebot11.js +1265 -1302
  16. package/lib/core/dir.d.ts +1 -0
  17. package/lib/core/dir.js +4 -0
  18. package/lib/core/init.js +4 -4
  19. package/lib/core/karin.d.ts +72 -72
  20. package/lib/core/karin.js +51 -51
  21. package/lib/core/listener.d.ts +121 -121
  22. package/lib/core/listener.js +178 -178
  23. package/lib/core/plugin.app.d.ts +15 -15
  24. package/lib/core/plugin.app.js +18 -18
  25. package/lib/core/plugin.d.ts +182 -182
  26. package/lib/core/plugin.js +132 -132
  27. package/lib/core/plugin.loader.d.ts +149 -149
  28. package/lib/core/plugin.loader.js +451 -451
  29. package/lib/core/server.d.ts +26 -26
  30. package/lib/core/server.js +209 -209
  31. package/lib/db/level.d.ts +20 -20
  32. package/lib/db/level.js +36 -36
  33. package/lib/db/redis.d.ts +41 -41
  34. package/lib/db/redis.js +131 -131
  35. package/lib/db/redis_level.d.ts +113 -113
  36. package/lib/db/redis_level.js +274 -274
  37. package/lib/event/event.d.ts +138 -138
  38. package/lib/event/event.handler.d.ts +29 -29
  39. package/lib/event/event.handler.js +138 -138
  40. package/lib/event/event.js +120 -120
  41. package/lib/event/message.d.ts +102 -102
  42. package/lib/event/message.handler.d.ts +25 -25
  43. package/lib/event/message.handler.js +237 -237
  44. package/lib/event/message.js +69 -69
  45. package/lib/event/notice.d.ts +49 -49
  46. package/lib/event/notice.js +14 -14
  47. package/lib/event/request.d.ts +49 -49
  48. package/lib/event/request.js +14 -14
  49. package/lib/event/review.handler.d.ts +54 -54
  50. package/lib/event/review.handler.js +374 -374
  51. package/lib/index.d.ts +24 -23
  52. package/lib/index.js +40 -40
  53. package/lib/renderer/app.d.ts +53 -53
  54. package/lib/renderer/app.js +88 -88
  55. package/lib/renderer/base.d.ts +30 -30
  56. package/lib/renderer/base.js +68 -68
  57. package/lib/renderer/client.d.ts +30 -30
  58. package/lib/renderer/client.js +155 -155
  59. package/lib/renderer/http.d.ts +19 -19
  60. package/lib/renderer/http.js +50 -50
  61. package/lib/renderer/server.d.ts +42 -42
  62. package/lib/renderer/server.js +110 -110
  63. package/lib/renderer/wormhole.d.ts +1 -1
  64. package/lib/renderer/wormhole.js +154 -154
  65. package/lib/tools/init.d.ts +2 -0
  66. package/lib/tools/init.js +31 -0
  67. package/lib/types/adapter.d.ts +575 -575
  68. package/lib/types/adapter.js +1 -1
  69. package/lib/types/config.d.ts +327 -327
  70. package/lib/types/config.js +1 -1
  71. package/lib/types/element.d.ts +576 -576
  72. package/lib/types/element.js +1 -1
  73. package/lib/types/index.d.ts +8 -8
  74. package/lib/types/index.js +8 -8
  75. package/lib/types/logger.d.ts +109 -109
  76. package/lib/types/logger.js +1 -1
  77. package/lib/types/onebots11.d.ts +1371 -1371
  78. package/lib/types/onebots11.js +1 -1
  79. package/lib/types/plugin.d.ts +282 -282
  80. package/lib/types/plugin.js +1 -1
  81. package/lib/types/render.d.ts +111 -111
  82. package/lib/types/render.js +1 -1
  83. package/lib/types/reply.d.ts +40 -40
  84. package/lib/types/reply.js +1 -1
  85. package/lib/types/types.d.ts +898 -898
  86. package/lib/types/types.js +1 -1
  87. package/lib/utils/YamlEditor.d.ts +62 -62
  88. package/lib/utils/YamlEditor.js +197 -197
  89. package/lib/utils/button.d.ts +49 -49
  90. package/lib/utils/button.js +75 -75
  91. package/lib/utils/common.d.ts +123 -123
  92. package/lib/utils/common.js +396 -396
  93. package/lib/utils/config.d.ts +72 -72
  94. package/lib/utils/config.js +259 -254
  95. package/lib/utils/exec.d.ts +22 -22
  96. package/lib/utils/exec.js +36 -36
  97. package/lib/utils/ffmpeg.d.ts +12 -12
  98. package/lib/utils/ffmpeg.js +25 -25
  99. package/lib/utils/handler.d.ts +76 -76
  100. package/lib/utils/handler.js +98 -98
  101. package/lib/utils/logger.d.ts +3 -3
  102. package/lib/utils/logger.js +104 -104
  103. package/lib/utils/segment.d.ts +276 -276
  104. package/lib/utils/segment.js +420 -420
  105. package/lib/utils/update.d.ts +69 -69
  106. package/lib/utils/update.js +145 -145
  107. package/lib/utils/updateVersion.d.ts +33 -33
  108. package/lib/utils/updateVersion.js +140 -140
  109. package/package.json +95 -91
@@ -1,30 +1,30 @@
1
- import WebSocket from 'ws';
2
- import RenderBase from './base.js';
3
- import { KarinRenderType } from '../types/render.js';
4
- export default class RenderClient extends RenderBase {
5
- url: string;
6
- type: string;
7
- id: string;
8
- index: number;
9
- retry: number;
10
- reg: RegExp;
11
- ws: WebSocket;
12
- constructor(url: string);
13
- /**
14
- * 初始化
15
- */
16
- start(): Promise<void>;
17
- /**
18
- * 心跳
19
- */
20
- heartbeat(): Promise<void>;
21
- /**
22
- * 接受消息
23
- */
24
- message(str: string): Promise<void>;
25
- /**
26
- * 渲染标准方法
27
- * @param options 渲染参数
28
- */
29
- render(options: KarinRenderType): Promise<string | string[]>;
30
- }
1
+ import WebSocket from 'ws';
2
+ import RenderBase from './base.js';
3
+ import { KarinRenderType } from '../types/render.js';
4
+ export default class RenderClient extends RenderBase {
5
+ url: string;
6
+ type: string;
7
+ id: string;
8
+ index: number;
9
+ retry: number;
10
+ reg: RegExp;
11
+ ws: WebSocket;
12
+ constructor(url: string);
13
+ /**
14
+ * 初始化
15
+ */
16
+ start(): Promise<void>;
17
+ /**
18
+ * 心跳
19
+ */
20
+ heartbeat(): Promise<void>;
21
+ /**
22
+ * 接受消息
23
+ */
24
+ message(str: string): Promise<void>;
25
+ /**
26
+ * 渲染标准方法
27
+ * @param options 渲染参数
28
+ */
29
+ render(options: KarinRenderType): Promise<string | string[]>;
30
+ }
@@ -1,159 +1,159 @@
1
- import fs from 'fs'
2
- import WebSocket from 'ws'
3
- import Renderer from './app.js'
4
- import RenderBase from './base.js'
5
- import { randomUUID } from 'crypto'
6
- import common from '../utils/common.js'
7
- import logger from '../utils/logger.js'
8
- import listener from '../core/listener.js'
9
- export default class RenderClient extends RenderBase {
10
- url
11
- type
12
- id
13
- index
14
- retry
15
- reg
16
- ws
17
- constructor (url) {
18
- super()
19
- this.url = url
20
- this.type = 'image'
21
- this.id = 'puppeteer'
22
- this.index = 0
23
- this.retry = 0
24
- this.reg = new RegExp(`(${process.cwd().replace(/\\/g, '\\\\')}|${process.cwd().replace(/\\/g, '/')})`, 'g')
25
- /** 连接ws */
26
- this.ws = new WebSocket(this.url)
1
+ import fs from 'fs'
2
+ import WebSocket from 'ws'
3
+ import Renderer from './app.js'
4
+ import RenderBase from './base.js'
5
+ import { randomUUID } from 'crypto'
6
+ import common from '../utils/common.js'
7
+ import logger from '../utils/logger.js'
8
+ import listener from '../core/listener.js'
9
+ export default class RenderClient extends RenderBase {
10
+ url
11
+ type
12
+ id
13
+ index
14
+ retry
15
+ reg
16
+ ws
17
+ constructor (url) {
18
+ super()
19
+ this.url = url
20
+ this.type = 'image'
21
+ this.id = 'puppeteer'
22
+ this.index = 0
23
+ this.retry = 0
24
+ this.reg = new RegExp(`(${process.cwd().replace(/\\/g, '\\\\')}|${process.cwd().replace(/\\/g, '/')})`, 'g')
25
+ /** 连接ws */
26
+ this.ws = new WebSocket(this.url)
27
27
  }
28
-
29
- /**
30
- * 初始化
31
- */
32
- async start () {
33
- /** 建立连接 */
34
- this.ws.on('open', () => {
35
- logger.mark(`[渲染器:${this.id}][WebSocket] 建立连接:${logger.green(this.url)}`)
36
- /** 注册渲染器 */
37
- try {
38
- this.index = Renderer.app({ id: this.id, type: this.type, render: this.render.bind(this) })
39
- this.retry = 0
40
- } catch (error) {
41
- logger.error(`[渲染器:${this.id}] 注册渲染器失败:`, error)
42
- /** 断开连接 */
43
- this.ws.close()
44
- }
45
- /** 心跳 */
46
- this.heartbeat()
47
- /** 监听消息 */
48
- this.ws.on('message', data => this.message(data.toString()))
49
- })
50
- /** 监听断开 */
51
- this.ws.once('close', async () => {
52
- this.retry++
53
- /** 停止监听 */
54
- this.ws.removeAllListeners()
55
- /** 卸载渲染器 */
56
- this.index && Renderer.unapp(this.index) && (this.index = 0)
57
- logger.warn(`[渲染器:${this.id}][重连次数:${this.retry}] 连接断开,5秒后将尝试重连:${this.url}`)
58
- await common.sleep(5000)
59
- await this.start()
60
- })
61
- /** 监听错误 */
62
- this.ws.on('error', async (e) => {
63
- logger.debug(e)
64
- await common.sleep(5000)
65
- this.ws.close()
66
- })
28
+
29
+ /**
30
+ * 初始化
31
+ */
32
+ async start () {
33
+ /** 建立连接 */
34
+ this.ws.on('open', () => {
35
+ logger.mark(`[渲染器:${this.id}][WebSocket] 建立连接:${logger.green(this.url)}`)
36
+ /** 注册渲染器 */
37
+ try {
38
+ this.index = Renderer.app({ id: this.id, type: this.type, render: this.render.bind(this) })
39
+ this.retry = 0
40
+ } catch (error) {
41
+ logger.error(`[渲染器:${this.id}] 注册渲染器失败:`, error)
42
+ /** 断开连接 */
43
+ this.ws.close()
44
+ }
45
+ /** 心跳 */
46
+ this.heartbeat()
47
+ /** 监听消息 */
48
+ this.ws.on('message', data => this.message(data.toString()))
49
+ })
50
+ /** 监听断开 */
51
+ this.ws.once('close', async () => {
52
+ this.retry++
53
+ /** 停止监听 */
54
+ this.ws.removeAllListeners()
55
+ /** 卸载渲染器 */
56
+ this.index && Renderer.unapp(this.index) && (this.index = 0)
57
+ logger.warn(`[渲染器:${this.id}][重连次数:${this.retry}] 连接断开,5秒后将尝试重连:${this.url}`)
58
+ await common.sleep(5000)
59
+ await this.start()
60
+ })
61
+ /** 监听错误 */
62
+ this.ws.on('error', async (e) => {
63
+ logger.debug(e)
64
+ await common.sleep(5000)
65
+ this.ws.close()
66
+ })
67
67
  }
68
-
69
- /**
70
- * 心跳
71
- */
72
- async heartbeat () {
73
- /** 无限循环 错误则停止 */
74
- while (true) {
75
- try {
76
- this.ws.send(JSON.stringify({ action: 'heartbeat' }))
77
- logger.debug(`[渲染器:${this.id}] 心跳:${this.url}`)
78
- } catch (e) {
79
- logger.debug(`[渲染器:${this.id}] 心跳失败:`, e)
80
- this.ws.close()
81
- break
82
- }
83
- await common.sleep(5000)
84
- }
68
+
69
+ /**
70
+ * 心跳
71
+ */
72
+ async heartbeat () {
73
+ /** 无限循环 错误则停止 */
74
+ while (true) {
75
+ try {
76
+ this.ws.send(JSON.stringify({ action: 'heartbeat' }))
77
+ logger.debug(`[渲染器:${this.id}] 心跳:${this.url}`)
78
+ } catch (e) {
79
+ logger.debug(`[渲染器:${this.id}] 心跳失败:`, e)
80
+ this.ws.close()
81
+ break
82
+ }
83
+ await common.sleep(5000)
84
+ }
85
85
  }
86
-
87
- /**
88
- * 接受消息
89
- */
90
- async message (str) {
91
- const data = JSON.parse(str)
92
- switch (data.action) {
93
- /** 静态文件 */
94
- case 'static': {
95
- const filePath = decodeURIComponent(data.params.file)
96
- logger.debug(`[渲染器:${this.id}][正向WS] 访问静态文件:${filePath}`)
97
- const file = fs.readFileSync('.' + filePath)
98
- const params = {
99
- echo: data.echo,
100
- action: 'static',
101
- status: 'ok',
102
- data: { file },
103
- }
104
- return this.ws.send(JSON.stringify(params))
105
- }
106
- /** 渲染结果 */
107
- case 'renderRes': {
108
- listener.emit(data.echo, data)
109
- break
110
- }
111
- /** 未知数据 */
112
- default: {
113
- logger.warn(`[渲染器:${this.id}] 收到未知数据:`, data)
114
- }
115
- }
86
+
87
+ /**
88
+ * 接受消息
89
+ */
90
+ async message (str) {
91
+ const data = JSON.parse(str)
92
+ switch (data.action) {
93
+ /** 静态文件 */
94
+ case 'static': {
95
+ const filePath = decodeURIComponent(data.params.file)
96
+ logger.debug(`[渲染器:${this.id}][正向WS] 访问静态文件:${filePath}`)
97
+ const file = fs.readFileSync('.' + filePath)
98
+ const params = {
99
+ echo: data.echo,
100
+ action: 'static',
101
+ status: 'ok',
102
+ data: { file },
103
+ }
104
+ return this.ws.send(JSON.stringify(params))
105
+ }
106
+ /** 渲染结果 */
107
+ case 'renderRes': {
108
+ listener.emit(data.echo, data)
109
+ break
110
+ }
111
+ /** 未知数据 */
112
+ default: {
113
+ logger.warn(`[渲染器:${this.id}] 收到未知数据:`, data)
114
+ }
115
+ }
116
116
  }
117
-
118
- /**
119
- * 渲染标准方法
120
- * @param options 渲染参数
121
- */
122
- async render (options) {
123
- /** 渲染模板 */
124
- let file = options.file
125
- let action = 'renderHtml'
126
- if (options.file.includes('http') || options.vue) {
127
- action = 'render'
128
- } else {
129
- file = this.dealTpl(options)
130
- /** 判断是本地karin-puppeteer还是远程 */
131
- if (!/127\.0\.0\.1|localhost/.test(this.url)) {
132
- file = fs.readFileSync(file, 'utf-8').replace(this.reg, '')
133
- } else {
134
- action = 'render'
135
- file = 'file://' + file
136
- }
137
- }
138
- if (!file) {
139
- logger.error(`[渲染器:${this.id}:${this.index}] 渲染文件不存在:${options.file}`)
140
- return ''
141
- }
142
- /** 编码 */
143
- file = encodeURIComponent(file)
144
- const data = options
145
- const echo = randomUUID()
146
- /** 移除掉模板参数 */
147
- if (data.data) { delete data.data }
148
- data.file = file
149
- const req = JSON.stringify({ echo, action, data })
150
- logger.debug(`[渲染器:${this.id}:${this.index}][正向WS] 请求:${this.url} \nhtml: ${options.file} \ndata: ${JSON.stringify(data)}`)
151
- this.ws.send(req)
152
- return new Promise((resolve, reject) => {
153
- listener.once(echo, (data) => {
154
- if (data.ok) { return resolve(data.data) }
155
- reject(new Error(JSON.stringify(data)))
156
- })
157
- })
158
- }
159
- }
117
+
118
+ /**
119
+ * 渲染标准方法
120
+ * @param options 渲染参数
121
+ */
122
+ async render (options) {
123
+ /** 渲染模板 */
124
+ let file = options.file
125
+ let action = 'renderHtml'
126
+ if (options.file.includes('http') || options.vue) {
127
+ action = 'render'
128
+ } else {
129
+ file = this.dealTpl(options)
130
+ /** 判断是本地karin-puppeteer还是远程 */
131
+ if (!/127\.0\.0\.1|localhost/.test(this.url)) {
132
+ file = fs.readFileSync(file, 'utf-8').replace(this.reg, '')
133
+ } else {
134
+ action = 'render'
135
+ file = 'file://' + file
136
+ }
137
+ }
138
+ if (!file) {
139
+ logger.error(`[渲染器:${this.id}:${this.index}] 渲染文件不存在:${options.file}`)
140
+ return ''
141
+ }
142
+ /** 编码 */
143
+ file = encodeURIComponent(file)
144
+ const data = options
145
+ const echo = randomUUID()
146
+ /** 移除掉模板参数 */
147
+ if (data.data) { delete data.data }
148
+ data.file = file
149
+ const req = JSON.stringify({ echo, action, data })
150
+ logger.debug(`[渲染器:${this.id}:${this.index}][正向WS] 请求:${this.url} \nhtml: ${options.file} \ndata: ${JSON.stringify(data)}`)
151
+ this.ws.send(req)
152
+ return new Promise((resolve, reject) => {
153
+ listener.once(echo, (data) => {
154
+ if (data.ok) { return resolve(data.data) }
155
+ reject(new Error(JSON.stringify(data)))
156
+ })
157
+ })
158
+ }
159
+ }
@@ -1,19 +1,19 @@
1
- import RenderBase from './base.js';
2
- import { KarinRenderType } from '../types/render.js';
3
- export default class HttpRenderer extends RenderBase {
4
- id: string;
5
- host: string;
6
- url: string;
7
- token: string;
8
- /**
9
- * 构造函数
10
- * @param host - 静态服务器地址
11
- * @param url - 渲染接口
12
- * @param token - token
13
- */
14
- constructor(host: string, url: string, token: string);
15
- /**
16
- * 渲染
17
- */
18
- render(options: KarinRenderType): Promise<string | Array<string>>;
19
- }
1
+ import RenderBase from './base.js';
2
+ import { KarinRenderType } from '../types/render.js';
3
+ export default class HttpRenderer extends RenderBase {
4
+ id: string;
5
+ host: string;
6
+ url: string;
7
+ token: string;
8
+ /**
9
+ * 构造函数
10
+ * @param host - 静态服务器地址
11
+ * @param url - 渲染接口
12
+ * @param token - token
13
+ */
14
+ constructor(host: string, url: string, token: string);
15
+ /**
16
+ * 渲染
17
+ */
18
+ render(options: KarinRenderType): Promise<string | Array<string>>;
19
+ }
@@ -1,51 +1,51 @@
1
- import axios from 'axios'
2
- import RenderBase from './base.js'
3
- import logger from '../utils/logger.js'
4
- export default class HttpRenderer extends RenderBase {
5
- id
6
- host
7
- url
8
- token
9
- /**
10
- * 构造函数
11
- * @param host - 静态服务器地址
12
- * @param url - 渲染接口
13
- * @param token - token
14
- */
15
- constructor (host, url, token) {
16
- super()
17
- this.id = 'puppeteer'
18
- this.host = host
19
- this.url = url
20
- this.token = token
1
+ import axios from 'axios'
2
+ import RenderBase from './base.js'
3
+ import logger from '../utils/logger.js'
4
+ export default class HttpRenderer extends RenderBase {
5
+ id
6
+ host
7
+ url
8
+ token
9
+ /**
10
+ * 构造函数
11
+ * @param host - 静态服务器地址
12
+ * @param url - 渲染接口
13
+ * @param token - token
14
+ */
15
+ constructor (host, url, token) {
16
+ super()
17
+ this.id = 'puppeteer'
18
+ this.host = host
19
+ this.url = url
20
+ this.token = token
21
21
  }
22
-
23
- /**
24
- * 渲染
25
- */
26
- async render (options) {
27
- const name = options.name || 'render'
28
- let file = options.file
29
- /** 非http渲染模板并转为http静态资源 */
30
- if (!options.file.includes('http') && !options.vue) {
31
- const isLocalhost = this.host.includes('127.0.0.1') || this.host.includes('localhost')
32
- file = this.dealTpl(options, isLocalhost)
33
- if (!file) {
34
- logger.error(`[渲染器:${this.id}] 模板文件不存在:${name}`)
35
- return ''
36
- }
37
- options.file = isLocalhost ? 'file://' + file : `${this.host}/api/renderHtml?html=${file}`
38
- }
39
- delete options.data
40
- const data = options
41
- const headers = {
42
- Authorization: this.token,
43
- }
44
- logger.debug(`[渲染器:${this.id}][POST] \n请求:${this.url} \nhtml: ${options.file} \ndata: ${JSON.stringify(data)}`)
45
- const res = await axios({ method: 'post', url: this.url, headers, data })
46
- if (res.status === 200 && res.data.ok) {
47
- return res.data.data
48
- }
49
- throw new Error(`渲染失败:${JSON.stringify(res.data)}`)
50
- }
51
- }
22
+
23
+ /**
24
+ * 渲染
25
+ */
26
+ async render (options) {
27
+ const name = options.name || 'render'
28
+ let file = options.file
29
+ /** 非http渲染模板并转为http静态资源 */
30
+ if (!options.file.includes('http') && !options.vue) {
31
+ const isLocalhost = this.host.includes('127.0.0.1') || this.host.includes('localhost')
32
+ file = this.dealTpl(options, isLocalhost)
33
+ if (!file) {
34
+ logger.error(`[渲染器:${this.id}] 模板文件不存在:${name}`)
35
+ return ''
36
+ }
37
+ options.file = isLocalhost ? 'file://' + file : `${this.host}/api/renderHtml?html=${file}`
38
+ }
39
+ delete options.data
40
+ const data = options
41
+ const headers = {
42
+ Authorization: this.token,
43
+ }
44
+ logger.debug(`[渲染器:${this.id}][POST] \n请求:${this.url} \nhtml: ${options.file} \ndata: ${JSON.stringify(data)}`)
45
+ const res = await axios({ method: 'post', url: this.url, headers, data })
46
+ if (res.status === 200 && res.data.ok) {
47
+ return res.data.data
48
+ }
49
+ throw new Error(`渲染失败:${JSON.stringify(res.data)}`)
50
+ }
51
+ }
@@ -1,42 +1,42 @@
1
- /// <reference types="node" />
2
- import RenderBase from './base.js';
3
- import WebSocket from 'ws';
4
- import { IncomingMessage } from 'http';
5
- import { KarinRenderType } from '../types/render.js';
6
- declare class Puppeteer extends RenderBase {
7
- socket: WebSocket;
8
- id: any;
9
- type: any;
10
- host: any;
11
- url: string;
12
- index: number;
13
- constructor();
14
- server(socket: WebSocket, request: IncomingMessage): Promise<void>;
15
- /**
16
- * 渲染模板
17
- * @param {object} options 渲染参数
18
- * @param {string} options.file http地址或本地文件路径
19
- * @param {string} [options.name] 模板名称
20
- * @param {string} [options.fileID] art-template后的文件名
21
- * @param {object} [options.data] 传递给模板的数据 template.render(data)
22
- * @param {'png'|'jpeg'|'webp'} [options.type] 截图类型 默认'webp'
23
- * @param {number} [options.quality] 截图质量 默认90 1-100
24
- * @param {boolean} options.omitBackground 是否隐藏背景 默认false
25
- * @param {object} [options.setViewport] 设置视窗大小和设备像素比 默认1920*1080、1
26
- * @param {number} [options.setViewport.width] 视窗宽度
27
- * @param {number} [options.setViewport.height] 视窗高度
28
- * @param {string} [options.setViewport.deviceScaleFactor] 设备像素比
29
- * @param {number|boolean} [options.multiPage] 分页截图 传递数字则视为视窗高度 返回数组
30
- * @param {object} [options.pageGotoParams] 页面goto时的参数
31
- * @param {number} [options.pageGotoParams.timeout] 页面加载超时时间
32
- * @param {'load'|'domcontentloaded'|'networkidle0'|'networkidle2'} [options.pageGotoParams.waitUntil] 页面加载状态
33
- * @returns {Promise<string|string[]>} 返回图片base64或数组
34
- */
35
- render(options: KarinRenderType): Promise<string | string[]>;
36
- }
37
- declare const _default: {
38
- type: string;
39
- path: string;
40
- adapter: typeof Puppeteer;
41
- };
42
- export default _default;
1
+ /// <reference types="node" />
2
+ import RenderBase from './base.js';
3
+ import WebSocket from 'ws';
4
+ import { IncomingMessage } from 'http';
5
+ import { KarinRenderType } from '../types/render.js';
6
+ declare class Puppeteer extends RenderBase {
7
+ socket: WebSocket;
8
+ id: any;
9
+ type: any;
10
+ host: any;
11
+ url: string;
12
+ index: number;
13
+ constructor();
14
+ server(socket: WebSocket, request: IncomingMessage): Promise<void>;
15
+ /**
16
+ * 渲染模板
17
+ * @param {object} options 渲染参数
18
+ * @param {string} options.file http地址或本地文件路径
19
+ * @param {string} [options.name] 模板名称
20
+ * @param {string} [options.fileID] art-template后的文件名
21
+ * @param {object} [options.data] 传递给模板的数据 template.render(data)
22
+ * @param {'png'|'jpeg'|'webp'} [options.type] 截图类型 默认'webp'
23
+ * @param {number} [options.quality] 截图质量 默认90 1-100
24
+ * @param {boolean} options.omitBackground 是否隐藏背景 默认false
25
+ * @param {object} [options.setViewport] 设置视窗大小和设备像素比 默认1920*1080、1
26
+ * @param {number} [options.setViewport.width] 视窗宽度
27
+ * @param {number} [options.setViewport.height] 视窗高度
28
+ * @param {string} [options.setViewport.deviceScaleFactor] 设备像素比
29
+ * @param {number|boolean} [options.multiPage] 分页截图 传递数字则视为视窗高度 返回数组
30
+ * @param {object} [options.pageGotoParams] 页面goto时的参数
31
+ * @param {number} [options.pageGotoParams.timeout] 页面加载超时时间
32
+ * @param {'load'|'domcontentloaded'|'networkidle0'|'networkidle2'} [options.pageGotoParams.waitUntil] 页面加载状态
33
+ * @returns {Promise<string|string[]>} 返回图片base64或数组
34
+ */
35
+ render(options: KarinRenderType): Promise<string | string[]>;
36
+ }
37
+ declare const _default: {
38
+ type: string;
39
+ path: string;
40
+ adapter: typeof Puppeteer;
41
+ };
42
+ export default _default;