@kne/fastify-puppeteer 1.1.5 → 1.1.6

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.
@@ -1,5 +1,5 @@
1
1
  const fp = require('fastify-plugin');
2
- const path = require('node:path');
2
+ const { decode } = require('plantuml-encoder');
3
3
  module.exports = fp(async (fastify, options) => {
4
4
  const { services } = fastify.puppeteer;
5
5
  fastify.post(
@@ -24,6 +24,25 @@ module.exports = fp(async (fastify, options) => {
24
24
  return reply.sendFile(filename, { root: options.root });
25
25
  }
26
26
  );
27
+ fastify.get(
28
+ `${options.prefix}/parseHtmlToPdf`,
29
+ {
30
+ description: '接口说明',
31
+ summary: 'html生成pdf文件流',
32
+ query: {
33
+ type: 'object',
34
+ required: ['content'],
35
+ properties: {
36
+ options: { type: 'object' },
37
+ content: { type: 'string' }
38
+ }
39
+ }
40
+ },
41
+ async (request, reply) => {
42
+ const filename = await services.parseHtmlToPdf({ html: decode(request.query.content), options: request.query.options });
43
+ return reply.sendFile(filename, { root: options.root });
44
+ }
45
+ );
27
46
 
28
47
  fastify.post(
29
48
  `${options.prefix}/parseHtmlToPdfBatch`,
@@ -56,6 +75,37 @@ module.exports = fp(async (fastify, options) => {
56
75
  }
57
76
  );
58
77
 
78
+ fastify.get(
79
+ `${options.prefix}/parseHtmlToPdfBatch`,
80
+ {
81
+ onRequest: options.authenticate,
82
+ schema: {
83
+ description: '接口说明',
84
+ summary: '批量将html生成pdf的zip文件流',
85
+ query: {
86
+ type: 'object',
87
+ required: ['contentList'],
88
+ properties: {
89
+ options: { type: 'object' },
90
+ contentList: {
91
+ type: 'array',
92
+ items: {
93
+ type: 'string'
94
+ }
95
+ }
96
+ }
97
+ }
98
+ }
99
+ },
100
+ async (request, reply) => {
101
+ const filename = await services.parseHtmlToPdfBatch({
102
+ htmlList: request.query.contentList.map(item => decode(item)),
103
+ options: request.query.options
104
+ });
105
+ return reply.sendFile(filename, { root: options.root });
106
+ }
107
+ );
108
+
59
109
  fastify.post(
60
110
  `${options.prefix}/parseHtmlToPhotoBatch`,
61
111
  {
@@ -87,6 +137,37 @@ module.exports = fp(async (fastify, options) => {
87
137
  }
88
138
  );
89
139
 
140
+ fastify.get(
141
+ `${options.prefix}/parseHtmlToPhotoBatch`,
142
+ {
143
+ onRequest: options.authenticate,
144
+ schema: {
145
+ description: '接口说明',
146
+ summary: '批量将html生成png的zip文件流',
147
+ query: {
148
+ type: 'object',
149
+ required: ['contentList'],
150
+ properties: {
151
+ options: { type: 'object' },
152
+ contentList: {
153
+ type: 'array',
154
+ items: {
155
+ type: 'string'
156
+ }
157
+ }
158
+ }
159
+ }
160
+ }
161
+ },
162
+ async (request, reply) => {
163
+ const filename = await services.parseHtmlToPhotoBatch({
164
+ htmlList: request.query.contentList.map(item => decode(item)),
165
+ options: request.query.options
166
+ });
167
+ return reply.sendFile(filename, { root: options.root });
168
+ }
169
+ );
170
+
90
171
  fastify.post(
91
172
  `${options.prefix}/parseHtmlToPhoto`,
92
173
  {
@@ -113,6 +194,32 @@ module.exports = fp(async (fastify, options) => {
113
194
  }
114
195
  );
115
196
 
197
+ fastify.get(
198
+ `${options.prefix}/parseHtmlToPhoto`,
199
+ {
200
+ onRequest: options.authenticate,
201
+ schema: {
202
+ description: '接口说明',
203
+ summary: 'html生成png文件流',
204
+ query: {
205
+ type: 'object',
206
+ required: ['content'],
207
+ properties: {
208
+ options: { type: 'object' },
209
+ content: { type: 'string' }
210
+ }
211
+ }
212
+ }
213
+ },
214
+ async (request, reply) => {
215
+ const filename = await services.parseHtmlToPhoto({
216
+ html: decode(request.query.content),
217
+ options: request.query.options
218
+ });
219
+ return reply.sendFile(filename, { root: options.root });
220
+ }
221
+ );
222
+
116
223
  fastify.post(
117
224
  `${options.prefix}/parseUrlToPdf`,
118
225
  {
@@ -136,14 +243,37 @@ module.exports = fp(async (fastify, options) => {
136
243
  }
137
244
  );
138
245
 
139
- fastify.post(
246
+ fastify.get(
247
+ `${options.prefix}/parseUrlToPdf`,
248
+ {
249
+ onRequest: options.authenticate,
250
+ schema: {
251
+ description: '接口说明',
252
+ summary: 'url生成pdf文件流',
253
+ query: {
254
+ type: 'object',
255
+ required: ['url'],
256
+ properties: {
257
+ options: { type: 'object' },
258
+ url: { type: 'string' }
259
+ }
260
+ }
261
+ }
262
+ },
263
+ async (request, reply) => {
264
+ const filename = await services.parseUrlToPdf({ url: request.query.url, options: request.query.options });
265
+ return reply.sendFile(filename, { root: options.root });
266
+ }
267
+ );
268
+
269
+ fastify.get(
140
270
  `${options.prefix}/parseUrlToPdfBatch`,
141
271
  {
142
272
  onRequest: options.authenticate,
143
273
  schema: {
144
274
  description: '接口说明',
145
275
  summary: 'url生成pdf文件流',
146
- body: {
276
+ query: {
147
277
  type: 'object',
148
278
  required: ['urlList'],
149
279
  properties: {
@@ -155,8 +285,8 @@ module.exports = fp(async (fastify, options) => {
155
285
  },
156
286
  async (request, reply) => {
157
287
  const filename = await services.parseUrlToPdfBatch({
158
- urlList: request.body.urlList,
159
- options: request.body.options
288
+ urlList: request.query.urlList,
289
+ options: request.query.options
160
290
  });
161
291
  return reply.sendFile(filename, { root: options.root });
162
292
  }
@@ -190,6 +320,34 @@ module.exports = fp(async (fastify, options) => {
190
320
  }
191
321
  );
192
322
 
323
+ fastify.get(
324
+ `${options.prefix}/parseUrlToPhoto`,
325
+ {
326
+ onRequest: options.authenticate,
327
+ schema: {
328
+ description: '接口说明',
329
+ summary: 'url生成png文件流',
330
+ query: {
331
+ type: 'object',
332
+ required: ['url'],
333
+ properties: {
334
+ options: { type: 'object' },
335
+ url: { type: 'string' },
336
+ selector: { type: 'string' }
337
+ }
338
+ }
339
+ }
340
+ },
341
+ async (request, reply) => {
342
+ const filename = await services.parseUrlToPhoto({
343
+ url: request.query.url,
344
+ selector: request.query.selector,
345
+ options: request.query.options
346
+ });
347
+ return reply.sendFile(filename, { root: options.root });
348
+ }
349
+ );
350
+
193
351
  fastify.post(
194
352
  `${options.prefix}/parseUrlToPhotoBatch`,
195
353
  {
@@ -217,4 +375,32 @@ module.exports = fp(async (fastify, options) => {
217
375
  return reply.sendFile(filename, { root: options.root });
218
376
  }
219
377
  );
378
+
379
+ fastify.get(
380
+ `${options.prefix}/parseUrlToPhotoBatch`,
381
+ {
382
+ onRequest: options.authenticate,
383
+ schema: {
384
+ description: '接口说明',
385
+ summary: 'url生成png文件流',
386
+ query: {
387
+ type: 'object',
388
+ required: ['urlList'],
389
+ properties: {
390
+ options: { type: 'object' },
391
+ urlList: { type: 'array', items: { type: 'string' } },
392
+ selector: { type: 'string' }
393
+ }
394
+ }
395
+ }
396
+ },
397
+ async (request, reply) => {
398
+ const filename = await services.parseUrlToPhotoBatch({
399
+ urlList: request.query.urlList,
400
+ selector: request.query.selector,
401
+ options: request.query.options
402
+ });
403
+ return reply.sendFile(filename, { root: options.root });
404
+ }
405
+ );
220
406
  });
package/libs/services.js CHANGED
@@ -2,7 +2,7 @@ const fp = require('fastify-plugin');
2
2
  const setup = require('./core/setup');
3
3
  const createCache = require('./core/file-cache');
4
4
  const compressing = require('compressing');
5
- const path = require('path');
5
+ const path = require('node:path');
6
6
  const createDeferred = require('@kne/create-deferred');
7
7
 
8
8
  module.exports = fp(async (fastify, options) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kne/fastify-puppeteer",
3
- "version": "1.1.5",
3
+ "version": "1.1.6",
4
4
  "description": "用于操作无头浏览器截图保存pdf等",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -49,6 +49,7 @@
49
49
  "lodash": "^4.17.21",
50
50
  "lru-cache": "^11.0.0",
51
51
  "object-hash": "^3.0.0",
52
+ "plantuml-encoder": "^1.4.0",
52
53
  "puppeteer": "^22.13.1",
53
54
  "puppeteer-core": "^22.13.1",
54
55
  "uuid": "^10.0.0"