@things-factory/integration-headless 7.0.40 → 7.0.41
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.
- package/dist-server/engine/connector/headless-connector.d.ts +1 -0
- package/dist-server/engine/connector/headless-connector.js +3 -0
- package/dist-server/engine/connector/headless-connector.js.map +1 -1
- package/dist-server/engine/task/headless-pdf-capture-board.js +1 -1
- package/dist-server/engine/task/headless-pdf-capture-board.js.map +1 -1
- package/dist-server/engine/task/headless-pdf-save.js +34 -19
- package/dist-server/engine/task/headless-pdf-save.js.map +1 -1
- package/dist-server/tsconfig.tsbuildinfo +1 -1
- package/helps/integration/connector/headless-connector.ja.md +71 -0
- package/helps/integration/connector/headless-connector.ko.md +72 -0
- package/helps/integration/connector/headless-connector.md +71 -0
- package/helps/integration/connector/headless-connector.ms.md +73 -0
- package/helps/integration/connector/headless-connector.zh.md +71 -0
- package/helps/integration/task/headless-pdf-capture-board.ja.md +51 -0
- package/helps/integration/task/headless-pdf-capture-board.ko.md +51 -0
- package/helps/integration/task/headless-pdf-capture-board.md +51 -0
- package/helps/integration/task/headless-pdf-capture-board.ms.md +53 -0
- package/helps/integration/task/headless-pdf-capture-board.zh.md +51 -0
- package/helps/integration/task/headless-pdf-capture.ja.md +45 -0
- package/helps/integration/task/headless-pdf-capture.ko.md +45 -0
- package/helps/integration/task/headless-pdf-capture.md +45 -0
- package/helps/integration/task/headless-pdf-capture.ms.md +47 -0
- package/helps/integration/task/headless-pdf-capture.zh.md +45 -0
- package/helps/integration/task/headless-pdf-open.ja.md +55 -0
- package/helps/integration/task/headless-pdf-open.ko.md +55 -0
- package/helps/integration/task/headless-pdf-open.md +55 -0
- package/helps/integration/task/headless-pdf-open.ms.md +57 -0
- package/helps/integration/task/headless-pdf-open.zh.md +55 -0
- package/helps/integration/task/headless-pdf-save.ja.md +23 -0
- package/helps/integration/task/headless-pdf-save.ko.md +25 -0
- package/helps/integration/task/headless-pdf-save.md +23 -0
- package/helps/integration/task/headless-pdf-save.ms.md +23 -0
- package/helps/integration/task/headless-pdf-save.zh.md +23 -0
- package/package.json +5 -4
- package/server/engine/connector/headless-connector.ts +4 -0
- package/server/engine/task/headless-pdf-capture-board.ts +1 -1
- package/server/engine/task/headless-pdf-save.ts +41 -18
- package/translations/en.json +1 -0
- package/translations/ko.json +1 -0
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
### 无头PDF保存任务 (Headless PDF Save Task)
|
|
2
|
+
|
|
3
|
+
**无头PDF保存任务**是将先前生成的PDF文档保存为文件的任务。此任务将PDF文档保存为附件,并返回保存文件的元数据。
|
|
4
|
+
|
|
5
|
+
#### 主要功能
|
|
6
|
+
|
|
7
|
+
- **保存PDF文档**: 保存由`headless-pdf-open`、`headless-pdf-capture`和`headless-pdf-capture-board`任务生成的PDF文档。文档将以指定的文件名保存,并返回文件的路径和元数据。
|
|
8
|
+
- **添加最后一页**: 如果在`headless-pdf-open`任务中指定了最后一页,则在保存之前将最后一页添加到PDF文档中。
|
|
9
|
+
- **保存为附件**: 将生成的PDF文档保存为附件,并将文件元数据记录到数据库中。保存的文件将作为`Attachment`记录进行管理。
|
|
10
|
+
|
|
11
|
+
#### 返回数据
|
|
12
|
+
|
|
13
|
+
- **id**: 保存的附件的唯一ID。
|
|
14
|
+
- **name**: 附件的名称。
|
|
15
|
+
- **path**: 附件的路径。
|
|
16
|
+
- **mimetype**: 文件的MIME类型(例如:`application/pdf`)。
|
|
17
|
+
- **refBy**: 引用信息(此任务中为`pdf-published`)。
|
|
18
|
+
- **fullpath**: 文件的完整路径。
|
|
19
|
+
|
|
20
|
+
#### 使用注意事项
|
|
21
|
+
|
|
22
|
+
- **必须先执行`headless-pdf-open`和`headless-pdf-capture`任务**: `headless-pdf-save`任务必须在执行了`headless-pdf-open`和必要的`headless-pdf-capture`任务后运行,否则会因为没有PDF文档可保存而导致错误。
|
|
23
|
+
- **文件名设置**: PDF文档的文件名默认设置为`document-<时间戳>.pdf`,如有需要,可以在`headless-pdf-open`中设置自定义文件名。
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@things-factory/integration-headless",
|
|
3
|
-
"version": "7.0.
|
|
3
|
+
"version": "7.0.41",
|
|
4
4
|
"main": "dist-server/index.js",
|
|
5
5
|
"things-factory": true,
|
|
6
6
|
"author": "heartyoh <heartyoh@hatiolab.com>",
|
|
@@ -22,11 +22,12 @@
|
|
|
22
22
|
"clean": "npm run clean:server"
|
|
23
23
|
},
|
|
24
24
|
"dependencies": {
|
|
25
|
-
"@things-factory/
|
|
25
|
+
"@things-factory/attachment-base": "^7.0.41",
|
|
26
|
+
"@things-factory/board-service": "^7.0.41",
|
|
26
27
|
"@things-factory/integration-base": "^7.0.38",
|
|
27
|
-
"@things-factory/
|
|
28
|
+
"@things-factory/shell": "^7.0.33",
|
|
28
29
|
"ejs": "^3.1.10",
|
|
29
30
|
"pdf-lib": "^1.17.1"
|
|
30
31
|
},
|
|
31
|
-
"gitHead": "
|
|
32
|
+
"gitHead": "9d9bd55f0ab565cf41cdc33fdaf416f7e5c26f5c"
|
|
32
33
|
}
|
|
@@ -59,6 +59,10 @@ export class HeadlessConnector implements Connector {
|
|
|
59
59
|
get description() {
|
|
60
60
|
return 'Headless Pool Connector'
|
|
61
61
|
}
|
|
62
|
+
|
|
63
|
+
get help() {
|
|
64
|
+
return 'integration/connector/headless-connector'
|
|
65
|
+
}
|
|
62
66
|
}
|
|
63
67
|
|
|
64
68
|
ConnectionManager.registerConnector('headless-connector', new HeadlessConnector())
|
|
@@ -267,7 +267,7 @@ HeadlessPDFCaptureBoard.parameterSpec = [
|
|
|
267
267
|
{
|
|
268
268
|
type: 'boolean',
|
|
269
269
|
name: 'draft',
|
|
270
|
-
label: 'draft',
|
|
270
|
+
label: 'board-draft',
|
|
271
271
|
defaultValue: false,
|
|
272
272
|
description: 'Set whether to get the current working version or the last released version'
|
|
273
273
|
},
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import * as fs from 'fs'
|
|
2
|
-
import * as path from 'path'
|
|
3
|
-
import { TaskRegistry } from '@things-factory/integration-base'
|
|
4
1
|
import { PDFDocument } from 'pdf-lib'
|
|
2
|
+
const { Readable } = require('stream')
|
|
3
|
+
|
|
4
|
+
import { TaskRegistry } from '@things-factory/integration-base'
|
|
5
|
+
import { Attachment, createAttachment } from '@things-factory/attachment-base'
|
|
6
|
+
import { getRepository } from '@things-factory/shell'
|
|
5
7
|
|
|
6
8
|
async function HeadlessPDFSave(step, context) {
|
|
7
|
-
var {
|
|
8
|
-
var { outputPath } = stepOptions || {}
|
|
9
|
-
var { __headless_pdf } = context
|
|
9
|
+
var { domain, user, __headless_pdf } = context
|
|
10
10
|
|
|
11
11
|
if (!__headless_pdf || !__headless_pdf.pdfDoc) {
|
|
12
12
|
throw new Error(
|
|
@@ -26,26 +26,49 @@ async function HeadlessPDFSave(step, context) {
|
|
|
26
26
|
const pdfBytes = await pdfDoc.save()
|
|
27
27
|
|
|
28
28
|
const finalFileName = __headless_pdf.fileName || `document-${Date.now()}.pdf`
|
|
29
|
-
const savePath = path.join(outputPath || './attachments', finalFileName)
|
|
30
29
|
|
|
31
|
-
|
|
32
|
-
|
|
30
|
+
const saved = await createAttachment(
|
|
31
|
+
null,
|
|
32
|
+
{
|
|
33
|
+
attachment: {
|
|
34
|
+
file: {
|
|
35
|
+
createReadStream: () =>
|
|
36
|
+
new Readable({
|
|
37
|
+
read() {
|
|
38
|
+
this.push(pdfBytes)
|
|
39
|
+
this.push(null)
|
|
40
|
+
}
|
|
41
|
+
}),
|
|
42
|
+
filename: finalFileName,
|
|
43
|
+
mimetype: 'application/pdf',
|
|
44
|
+
encoding: 'binary'
|
|
45
|
+
},
|
|
46
|
+
refType: 'headless-pdf-save',
|
|
47
|
+
refBy: 'pdf-published'
|
|
48
|
+
}
|
|
49
|
+
},
|
|
50
|
+
{
|
|
51
|
+
state: { domain, user }
|
|
52
|
+
}
|
|
53
|
+
)
|
|
54
|
+
|
|
55
|
+
const attachment = await getRepository(Attachment).findOne({
|
|
56
|
+
where: { id: saved.id }
|
|
57
|
+
})
|
|
33
58
|
|
|
34
59
|
return {
|
|
35
60
|
data: {
|
|
36
|
-
|
|
61
|
+
id: attachment.id,
|
|
62
|
+
name: attachment.name,
|
|
63
|
+
path: attachment.path,
|
|
64
|
+
mimetype: attachment.mimetype,
|
|
65
|
+
refBy: attachment.refBy,
|
|
66
|
+
fullpath: attachment.fullpath
|
|
37
67
|
}
|
|
38
68
|
}
|
|
39
69
|
}
|
|
40
70
|
|
|
41
|
-
HeadlessPDFSave.parameterSpec = [
|
|
42
|
-
{
|
|
43
|
-
type: 'string',
|
|
44
|
-
name: 'outputPath',
|
|
45
|
-
label: 'output-path',
|
|
46
|
-
description: 'The directory path where the PDF should be saved. Defaults to "./attachments".'
|
|
47
|
-
}
|
|
48
|
-
]
|
|
71
|
+
HeadlessPDFSave.parameterSpec = []
|
|
49
72
|
|
|
50
73
|
HeadlessPDFSave.help = 'integration/task/headless-pdf-save'
|
|
51
74
|
|
package/translations/en.json
CHANGED