@things-factory/integration-headless 8.0.0-beta.9 → 8.0.2
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 +14 -0
- package/dist-server/engine/connector/headless-connector.js +54 -0
- package/dist-server/engine/connector/headless-connector.js.map +1 -0
- package/dist-server/engine/connector/headless-pool.d.ts +3 -0
- package/dist-server/engine/connector/headless-pool.js +63 -0
- package/dist-server/engine/connector/headless-pool.js.map +1 -0
- package/dist-server/engine/connector/index.d.ts +1 -0
- package/dist-server/engine/connector/index.js +4 -0
- package/dist-server/engine/connector/index.js.map +1 -0
- package/dist-server/engine/index.d.ts +1 -0
- package/dist-server/engine/index.js +1 -0
- package/dist-server/engine/index.js.map +1 -1
- package/dist-server/engine/task/pdf-capture-util.d.ts +1 -1
- package/dist-server/engine/task/pdf-capture-util.js +3 -3
- package/dist-server/engine/task/pdf-capture-util.js.map +1 -1
- package/dist-server/tsconfig.tsbuildinfo +1 -1
- package/helps/integration/connector/headless-connector.ja.md +31 -183
- package/helps/integration/connector/headless-connector.ko.md +32 -177
- package/helps/integration/connector/headless-connector.md +31 -178
- package/helps/integration/connector/headless-connector.ms.md +32 -180
- package/helps/integration/connector/headless-connector.zh.md +31 -178
- package/package.json +6 -6
- package/server/engine/connector/headless-connector.ts +68 -0
- package/server/engine/connector/headless-pool.ts +69 -0
- package/server/engine/connector/index.ts +1 -0
- package/server/engine/index.ts +2 -0
- package/server/engine/task/headless-pdf-capture-board.ts +182 -0
- package/server/engine/task/headless-pdf-capture-markdown.ts +47 -0
- package/server/engine/task/headless-pdf-capture.ts +39 -0
- package/server/engine/task/headless-pdf-open.ts +98 -0
- package/server/engine/task/headless-pdf-save.ts +88 -0
- package/server/engine/task/index.ts +9 -0
- package/server/engine/task/pdf-capture-util.ts +331 -0
- package/server/index.ts +3 -0
- package/server/tsconfig.json +10 -0
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { Connector } from '@things-factory/integration-base';
|
|
2
|
+
export declare class HeadlessConnector implements Connector {
|
|
3
|
+
ready(connectionConfigs: any): Promise<void>;
|
|
4
|
+
connect(connection: any): Promise<void>;
|
|
5
|
+
disconnect(connection: any): Promise<void>;
|
|
6
|
+
get parameterSpec(): {
|
|
7
|
+
type: string;
|
|
8
|
+
name: string;
|
|
9
|
+
label: string;
|
|
10
|
+
}[];
|
|
11
|
+
get taskPrefixes(): string[];
|
|
12
|
+
get description(): string;
|
|
13
|
+
get help(): string;
|
|
14
|
+
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.HeadlessConnector = void 0;
|
|
4
|
+
const integration_base_1 = require("@things-factory/integration-base");
|
|
5
|
+
const headless_pool_1 = require("./headless-pool");
|
|
6
|
+
class HeadlessConnector {
|
|
7
|
+
async ready(connectionConfigs) {
|
|
8
|
+
await Promise.all(connectionConfigs.map(this.connect.bind(this)));
|
|
9
|
+
integration_base_1.ConnectionManager.logger.info('headless-connector connections are ready');
|
|
10
|
+
}
|
|
11
|
+
async connect(connection) {
|
|
12
|
+
var { endpoint: uri = '1', params: { min = 2, max = 10 } } = connection;
|
|
13
|
+
const headlessPool = (0, headless_pool_1.createHeadlessPool)({
|
|
14
|
+
min,
|
|
15
|
+
max,
|
|
16
|
+
testOnBorrow: true,
|
|
17
|
+
acquireTimeoutMillis: 15000
|
|
18
|
+
});
|
|
19
|
+
integration_base_1.ConnectionManager.addConnectionInstance(connection, headlessPool);
|
|
20
|
+
integration_base_1.ConnectionManager.logger.info(`headless-connector connection(${connection.name}:${connection.endpoint}) is connected`);
|
|
21
|
+
}
|
|
22
|
+
async disconnect(connection) {
|
|
23
|
+
const headlessPool = integration_base_1.ConnectionManager.getConnectionInstance(connection);
|
|
24
|
+
(0, headless_pool_1.destroyHeadlessPool)(headlessPool);
|
|
25
|
+
integration_base_1.ConnectionManager.removeConnectionInstance(connection);
|
|
26
|
+
integration_base_1.ConnectionManager.logger.info(`headless-connector connection(${connection.name}) is disconnected`);
|
|
27
|
+
}
|
|
28
|
+
get parameterSpec() {
|
|
29
|
+
return [
|
|
30
|
+
{
|
|
31
|
+
type: 'number',
|
|
32
|
+
name: 'min',
|
|
33
|
+
label: 'pool-size-min'
|
|
34
|
+
},
|
|
35
|
+
{
|
|
36
|
+
type: 'number',
|
|
37
|
+
name: 'max',
|
|
38
|
+
label: 'pool-size-max'
|
|
39
|
+
}
|
|
40
|
+
];
|
|
41
|
+
}
|
|
42
|
+
get taskPrefixes() {
|
|
43
|
+
return ['headless-pdf'];
|
|
44
|
+
}
|
|
45
|
+
get description() {
|
|
46
|
+
return 'Headless Pool Connector';
|
|
47
|
+
}
|
|
48
|
+
get help() {
|
|
49
|
+
return 'integration/connector/headless-connector';
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
exports.HeadlessConnector = HeadlessConnector;
|
|
53
|
+
integration_base_1.ConnectionManager.registerConnector('headless-connector', new HeadlessConnector());
|
|
54
|
+
//# sourceMappingURL=headless-connector.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"headless-connector.js","sourceRoot":"","sources":["../../../server/engine/connector/headless-connector.ts"],"names":[],"mappings":";;;AAAA,uEAA+E;AAC/E,mDAAyE;AAEzE,MAAa,iBAAiB;IAC5B,KAAK,CAAC,KAAK,CAAC,iBAAiB;QAC3B,MAAM,OAAO,CAAC,GAAG,CAAC,iBAAiB,CAAC,GAAG,CAAC,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,CAAA;QAEjE,oCAAiB,CAAC,MAAM,CAAC,IAAI,CAAC,0CAA0C,CAAC,CAAA;IAC3E,CAAC;IAED,KAAK,CAAC,OAAO,CAAC,UAAU;QACtB,IAAI,EACF,QAAQ,EAAE,GAAG,GAAG,GAAG,EACnB,MAAM,EAAE,EAAE,GAAG,GAAG,CAAC,EA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createHeadlessPool, destroyHeadlessPool } from './headless-pool'\n\nexport class HeadlessConnector implements Connector {\n async ready(connectionConfigs) {\n await Promise.all(connectionConfigs.map(this.connect.bind(this)))\n\n ConnectionManager.logger.info('headless-connector connections are ready')\n }\n\n async connect(connection) {\n var {\n endpoint: uri = '1',\n params: { min = 2, max = 10 }\n } = connection\n\n const headlessPool = createHeadlessPool({\n min,\n max,\n testOnBorrow: true,\n acquireTimeoutMillis: 15000\n })\n\n ConnectionManager.addConnectionInstance(connection, headlessPool)\n\n ConnectionManager.logger.info(\n `headless-connector connection(${connection.name}:${connection.endpoint}) is connected`\n )\n }\n\n async disconnect(connection) {\n const headlessPool = ConnectionManager.getConnectionInstance(connection)\n destroyHeadlessPool(headlessPool)\n\n ConnectionManager.removeConnectionInstance(connection)\n\n ConnectionManager.logger.info(`headless-connector connection(${connection.name}) is disconnected`)\n }\n\n get parameterSpec() {\n return [\n {\n type: 'number',\n name: 'min',\n label: 'pool-size-min'\n },\n {\n type: 'number',\n name: 'max',\n label: 'pool-size-max'\n }\n ]\n }\n\n get taskPrefixes() {\n return ['headless-pdf']\n }\n\n get description() {\n return 'Headless Pool Connector'\n }\n\n get help() {\n return 'integration/connector/headless-connector'\n }\n}\n\nConnectionManager.registerConnector('headless-connector', new HeadlessConnector())\n"]}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createHeadlessPool = createHeadlessPool;
|
|
4
|
+
exports.destroyHeadlessPool = destroyHeadlessPool;
|
|
5
|
+
const tslib_1 = require("tslib");
|
|
6
|
+
const genericPool = tslib_1.__importStar(require("generic-pool"));
|
|
7
|
+
const env_1 = require("@things-factory/env");
|
|
8
|
+
try {
|
|
9
|
+
var puppeteer = require('puppeteer');
|
|
10
|
+
}
|
|
11
|
+
catch (err) {
|
|
12
|
+
env_1.logger.error(err);
|
|
13
|
+
}
|
|
14
|
+
function createHeadlessPool(options) {
|
|
15
|
+
return genericPool.createPool({
|
|
16
|
+
create() {
|
|
17
|
+
console.log('headless instance in headless-pool-integration about to create');
|
|
18
|
+
return initializeChromium();
|
|
19
|
+
},
|
|
20
|
+
validate(browser) {
|
|
21
|
+
return Promise.race([
|
|
22
|
+
new Promise(res => setTimeout(() => res(false), 1500)),
|
|
23
|
+
browser
|
|
24
|
+
//@ts-ignore
|
|
25
|
+
.version()
|
|
26
|
+
.then(_ => true)
|
|
27
|
+
.catch(_ => false)
|
|
28
|
+
]);
|
|
29
|
+
},
|
|
30
|
+
destroy(browser) {
|
|
31
|
+
//@ts-ignore
|
|
32
|
+
return browser.close();
|
|
33
|
+
}
|
|
34
|
+
}, options);
|
|
35
|
+
}
|
|
36
|
+
async function destroyHeadlessPool(headlessPool) {
|
|
37
|
+
if (headlessPool) {
|
|
38
|
+
console.log('headless-pool-integration about to destroy');
|
|
39
|
+
await headlessPool.drain();
|
|
40
|
+
await headlessPool.clear();
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
const CHROMIUM_PATH = env_1.config.get('CHROMIUM_PATH');
|
|
44
|
+
async function initializeChromium() {
|
|
45
|
+
try {
|
|
46
|
+
if (!puppeteer) {
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
var launchSetting = {
|
|
50
|
+
args: ['--hide-scrollbars', '--mute-audio', '--no-sandbox', '--use-gl=egl'],
|
|
51
|
+
headless: 'shell'
|
|
52
|
+
};
|
|
53
|
+
if (CHROMIUM_PATH) {
|
|
54
|
+
launchSetting['executablePath'] = CHROMIUM_PATH;
|
|
55
|
+
}
|
|
56
|
+
const browser = await puppeteer.launch(launchSetting);
|
|
57
|
+
return browser;
|
|
58
|
+
}
|
|
59
|
+
catch (err) {
|
|
60
|
+
env_1.logger.error(err);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
//# sourceMappingURL=headless-pool.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"headless-pool.js","source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AG,CAAC,eAAe,CAAC,CAAA;AAEjD,KAAK,UAAU,kBAAkB;IAC/B,IAAI,CAAC;QACH,IAAI,CAAC,SAAS,EAAE,CAAC;YACf,OAAM;QACR,CAAC;QAED,IAAI,aAAa,GAAG;YAClB,IAAI,EAAE,CAAC,mBAAmB,EAAE,cAAc,EAAE,cAAc,EAAE,cAAc,CAAC;YAC3E,QAAQ,EAAE,OAAO;SAClB,CAAA;QAED,IAAI,aAAa,EAAE,CAAC;YAClB,aAAa,CAAC,gBAAgB,CAAC,GAAG,aAAa,CAAA;QACjD,CAAC;QAED,MAAM,OAAO,GAAG,MAAM,SAAS,CAAC,MAAM,CAAC,aAAa,CAAC,CAAA;QAErD,OAAO,OAAO,CAAA;IAChB,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACb,YAAM,CAAC,KAAK,CAAC,GAAG,CAAC,CAAA;IACnB,CAAC;AACH,CAAC","sourcesContent":["import * as genericPool from 'generic-pool'\n\nimport { config, logger } from '@things-factory/env'\n\ntry {\n var puppeteer = require('puppeteer')\n} catch (err) {\n logger.error(err)\n}\n\nexport function createHeadlessPool(options: genericPool.Options) {\n return genericPool.createPool(\n {\n create() {\n console.log('headless instance in headless-pool-integration about to create')\n return initializeChromium()\n },\n validate(browser) {\n return Promise.race([\n new Promise(res => setTimeout(() => res(false), 1500)),\n browser\n //@ts-ignore\n .version()\n .then(_ => true)\n .catch(_ => false)\n ])\n },\n destroy(browser) {\n //@ts-ignore\n return browser.close()\n }\n } as genericPool.Factory<any>,\n options\n )\n}\n\nexport async function destroyHeadlessPool(headlessPool: genericPool.Pool<any>) {\n if (headlessPool) {\n console.log('headless-pool-integration about to destroy')\n\n await headlessPool.drain()\n await headlessPool.clear()\n }\n}\n\nconst CHROMIUM_PATH = config.get('CHROMIUM_PATH')\n\nasync function initializeChromium() {\n try {\n if (!puppeteer) {\n return\n }\n\n var launchSetting = {\n args: ['--hide-scrollbars', '--mute-audio', '--no-sandbox', '--use-gl=egl'],\n headless: 'shell'\n }\n\n if (CHROMIUM_PATH) {\n launchSetting['executablePath'] = CHROMIUM_PATH\n }\n\n const browser = await puppeteer.launch(launchSetting)\n\n return browser\n } catch (err) {\n logger.error(err)\n }\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import './headless-connector';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../server/engine/connector/index.ts"],"names":[],"mappings":";;AAAA,gCAA6B","sourcesContent":["import './headless-connector'\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../server/engine/index.ts"],"names":[],"mappings":";;AAAA,kBAAe","sourcesContent":["import './task'\n"]}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../server/engine/index.ts"],"names":[],"mappings":";;AAAA,uBAAoB;AACpB,kBAAe","sourcesContent":["import './connector'\nimport './task'\n"]}
|
|
@@ -22,7 +22,7 @@ interface PDFContext {
|
|
|
22
22
|
}
|
|
23
23
|
export declare class PDFCaptureUtil {
|
|
24
24
|
private context;
|
|
25
|
-
private
|
|
25
|
+
private headlessPool;
|
|
26
26
|
browser: Browser | null;
|
|
27
27
|
constructor(context: PDFContext);
|
|
28
28
|
initBrowser(connectionName: string): Promise<void>;
|
|
@@ -13,13 +13,13 @@ class PDFCaptureUtil {
|
|
|
13
13
|
}
|
|
14
14
|
async initBrowser(connectionName) {
|
|
15
15
|
const { domain } = this.context;
|
|
16
|
-
this.
|
|
17
|
-
this.browser = await this.
|
|
16
|
+
this.headlessPool = integration_base_1.ConnectionManager.getConnectionInstanceByName(domain, connectionName);
|
|
17
|
+
this.browser = await this.headlessPool.acquire();
|
|
18
18
|
}
|
|
19
19
|
async closeBrowser() {
|
|
20
20
|
if (this.browser) {
|
|
21
21
|
await this.browser.close();
|
|
22
|
-
this.
|
|
22
|
+
this.headlessPool.release(this.browser);
|
|
23
23
|
}
|
|
24
24
|
}
|
|
25
25
|
renderTemplate(template, data) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pdf-capture-util.js","sourceRoot":"","sources":["../../../server/engine/task/pdf-capture-util.ts"],"names":[],"mappings":";;;AAkPA,wDA6FC;;AA/UD,iDAA0B;AAC1B,uEAAoE;AACpE,qCAAqC;AAyBrC,MAAa,cAAc;IAWzB,YAAY,OAAmB;QAFxB,YAAO,GAAmB,IAAI,CAAA;QAGnC,IAAI,CAAC,OAAO,GAAG,OAAO,CAAA;IACxB,CAAC;IAED,KAAK,CAAC,WAAW,CAAC,cAAsB;QACtC,MAAM,EAAE,MAAM,EAAE,GAAG,IAAI,CAAC,OAAO,CAAA;QAC/B,IAAI,CAAC,kBAAkB,GAAG,oCAAiB,CAAC,2BAA2B,CAAC,MAAM,EAAE,cAAc,CAAC,CAAA;QAC/F,IAAI,CAAC,OAAO,GAAG,MAAM,IAAI,CAAC,kBAAkB,CAAC,cAAc,EAAE,CAAA;IAC/D,CAAC;IAED,KAAK,CAAC,YAAY;QAChB,IAAI,IAAI,CAAC,OAAO,EAAE,CAAC;YACjB,MAAM,IAAI,CAAC,OAAO,CAAC,KAAK,EAAE,CAAA;YAC1B,IAAI,CAAC,kBAAkB,CAAC,cAAc,CAAC,IAAI,CAAC,OAAO,CAAC,CAAA;QACtD,CAAC;IACH,CAAC;IAED,cAAc,CAAC,QAAgB,EAAE,IAAS;QACxC,MAAM,EAAE,MAAM,EAAE,GAAG,IAAI,CAAC,OAAO,CAAA;QAC/B,IAAI,CAAC;YACH,OAAO,GAAG,CAAC,MAAM,CAAC,QAAQ,EAAE,IAAI,CAAC,CAAA;QACnC,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,MAAM,CAAC,IAAI,CAAC,6BAA6B,KAAK,CAAC,OAAO,EAAE,CAAC,CAAA;YACzD,OAAO,QAAQ,CAAA;QACjB,CAAC;IACH,CAAC;IAED,KAAK,CAAC,kBAAkB,CAAC,IAAU,EAAE,WAAgB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YAClB,WAAW,EAAE,oDAAoD;SAClE;QACD;YACE,IAAI,EAAE,SAAS;YACf,IAAI,EAAE,WAAW;YACjB,KAAK,EAAE,WAAW;YAClB,YAAY,EAAE,KAAK;YACnB,WAAW,EAAE,wCAAwC;SACtD;QACD;YACE,IAAI,EAAE,SAAS;YACf,IAAI,EAAE,mBAAmB;YACzB,KAAK,EAAE,sBAAsB;YAC7B,YAAY,EAAE,KAAK;YACnB,WAAW,EAAE,6EAA6E;SAC3F;KACF,CAAA;AACH,CAAC","sourcesContent":["import * as ejs from 'ejs'\nimport { ConnectionManager } from '@things-factory/integration-base'\nimport { PDFDocument } from 'pdf-lib'\nimport { Browser, Page } from 'puppeteer'\nimport { Logger } from 'winston'\n\ninterface StepOptions {\n format?: string\n width?: string\n height?: string\n marginTop?: string\n marginBottom?: string\n marginLeft?: string\n marginRight?: string\n scale?: number\n printBackground?: boolean\n landscape?: boolean\n preferCSSPageSize?: boolean\n}\n\ninterface PDFContext {\n domain: any\n data: any\n logger: Logger\n __headless_pdf: any\n}\n\nexport class PDFCaptureUtil {\n private context: PDFContext\n private headlessConnection: {\n acquireSessionPage: () => Promise<Page>\n releasePage: (page: Page) => Promise<void>\n acquireBrowser: () => Promise<Browser>\n releaseBrowser: (browser: Browser) => Promise<void>\n }\n\n public browser: Browser | null = null\n\n constructor(context: PDFContext) {\n this.context = context\n }\n\n async initBrowser(connectionName: string) {\n const { domain } = this.context\n this.headlessConnection = ConnectionManager.getConnectionInstanceByName(domain, connectionName)\n this.browser = await this.headlessConnection.acquireBrowser()\n }\n\n async closeBrowser() {\n if (this.browser) {\n await this.browser.close()\n this.headlessConnection.releaseBrowser(this.browser)\n }\n }\n\n renderTemplate(template: string, data: any): string {\n const { logger } = this.context\n try {\n return ejs.render(template, data)\n } catch (error) {\n logger.warn(`Template rendering error: ${error.message}`)\n return template\n }\n }\n\n async generatePDFContent(page: Page, pageOptions: any): Promise<PDFDocument> {\n const contentBuffer = await page.pdf(pageOptions)\n const contentPdfDoc = await PDFDocument.load(contentBuffer)\n return contentPdfDoc\n }\n\n async appendPDFContentToDocument(pdfDoc: PDFDocument, contentPdfDoc: PDFDocument) {\n const copiedPages = await pdfDoc.copyPages(contentPdfDoc, contentPdfDoc.getPageIndices())\n copiedPages.forEach(page => pdfDoc.addPage(page))\n this.context.__headless_pdf.pageCount += copiedPages.length\n }\n\n async processPageAndGeneratePDF(stepOptions: StepOptions, htmlContent: string, page?: Page) {\n if (!this.browser) throw new Error('Browser not initialized. Call initBrowser() first.')\n\n if (!page) {\n page = page || (await this.browser.newPage())\n }\n\n if (htmlContent) {\n // 페이지 컨텐츠 설정\n await page.setContent(htmlContent, { waitUntil: 'networkidle0' }) // HTML 컨텐츠가 완전히 로드될 때까지 대기\n }\n\n // 페이지가 완전히 로드된 후에 워터마크와 머릿글 적용\n const { __headless_pdf } = this.context\n const { header, footer, watermark, landscape } = __headless_pdf\n\n if (header || footer || watermark) {\n await this.applyHeaderFooterWatermark(page, { header, footer, watermark, landscape, data: __headless_pdf })\n }\n\n const pageOptions = this.buildPageOptions(stepOptions)\n const contentPdfDoc = await this.generatePDFContent(page, pageOptions)\n await this.appendPDFContentToDocument(__headless_pdf.pdfDoc, contentPdfDoc)\n await page.close()\n }\n\n buildPageOptions({\n format,\n width,\n height,\n marginTop,\n marginBottom,\n marginLeft,\n marginRight,\n scale,\n printBackground,\n landscape,\n preferCSSPageSize\n }: StepOptions): any {\n if (preferCSSPageSize) {\n width = undefined\n height = undefined\n }\n\n return {\n format,\n width,\n height,\n margin: {\n top: marginTop,\n right: marginRight,\n bottom: marginBottom,\n left: marginLeft\n },\n scale,\n printBackground,\n landscape,\n displayHeaderFooter: false,\n preferCSSPageSize\n }\n }\n\n async applyHeaderFooterWatermark(\n page: Page,\n {\n header,\n footer,\n watermark,\n landscape,\n data\n }: { header: string; footer: string; watermark: string; landscape: boolean; data: any }\n ) {\n await page.evaluate(\n ({ header, footer, watermark, landscape, data }) => {\n const setPositioning = (element: HTMLElement, position: 'header' | 'footer') => {\n element.style.position = 'fixed'\n element.style.left = '0'\n element.style.width = '100%'\n element.style.textAlign = 'center'\n element.style.fontSize = '12px'\n element.style.margin = '0'\n element.style.padding = '0'\n element.style.zIndex = '1000'\n\n if (position === 'header') {\n element.style.top = '0'\n } else if (position === 'footer') {\n element.style.bottom = '0'\n }\n }\n\n if (header) {\n const headerElement = document.createElement('div')\n headerElement.innerHTML = header\n setPositioning(headerElement, 'header')\n document.body.appendChild(headerElement)\n }\n\n if (footer) {\n const footerElement = document.createElement('div')\n footerElement.innerHTML = footer\n setPositioning(footerElement, 'footer')\n document.body.appendChild(footerElement)\n }\n\n if (watermark) {\n const watermarkElement = document.createElement('div')\n watermarkElement.innerHTML = watermark\n watermarkElement.style.position = 'fixed'\n watermarkElement.style.top = landscape ? '40%' : '50%'\n watermarkElement.style.left = '50%'\n watermarkElement.style.transform = 'translate(-50%, -50%) rotate(-45deg)'\n watermarkElement.style.opacity = '0.2'\n watermarkElement.style.fontSize = '50px'\n watermarkElement.style.color = 'red'\n watermarkElement.style.pointerEvents = 'none'\n watermarkElement.style.zIndex = '9999'\n document.body.appendChild(watermarkElement)\n }\n },\n {\n header: header && this.renderTemplate(header, data),\n footer: footer && this.renderTemplate(footer, data),\n watermark: watermark && this.renderTemplate(watermark, data),\n landscape,\n data\n }\n )\n }\n\n /**\n * Generates a PDF buffer for the last page.\n * @param stepOptions - Options used for generating the PDF.\n * @param htmlContent - HTML content to be converted to PDF.\n * @returns {Promise<Uint8Array>} - The generated PDF as a buffer.\n */\n async generateLastPageBuffer(stepOptions: StepOptions, htmlContent: string): Promise<Uint8Array> {\n if (!this.browser) throw new Error('Browser not initialized. Call initBrowser() first.')\n\n const page = await this.browser.newPage()\n\n // 페이지에 HTML 콘텐츠를 설정합니다.\n await page.setContent(htmlContent, { waitUntil: 'networkidle0' })\n\n // 페이지가 완전히 로드된 후에 워터마크와 머릿글 적용\n const { __headless_pdf } = this.context\n const { header, footer, watermark, landscape } = __headless_pdf\n\n if (header || footer || watermark) {\n await this.applyHeaderFooterWatermark(page, { header, footer, watermark, landscape, data: __headless_pdf })\n }\n\n // 페이지 옵션 설정\n const pageOptions = this.buildPageOptions(stepOptions)\n\n // PDF를 생성하고 버퍼를 반환합니다.\n const lastPageBuffer = await page.pdf(pageOptions)\n\n // 페이지 닫기\n await page.close()\n\n return lastPageBuffer\n }\n}\n\nexport function getCommonParameterSpec() {\n return [\n {\n type: 'scenario-step-input',\n name: 'accessor',\n label: 'accessor'\n },\n {\n type: 'select',\n name: 'format',\n label: 'page-format',\n property: {\n options: [\n { display: '', value: '' },\n { display: 'A4', value: 'A4' },\n { display: 'A3', value: 'A3' },\n { display: 'Letter', value: 'Letter' },\n { display: 'Legal', value: 'Legal' }\n ]\n },\n description: 'Select the paper format for the PDF'\n },\n {\n type: 'string',\n name: 'width',\n label: 'page-width',\n placeholder: '(e.g., \"8.5in\", \"21cm\", \"600px\")',\n description: 'Specify the width of the page (e.g., \"8.5in\", \"21cm\", \"600px\")'\n },\n {\n type: 'string',\n name: 'height',\n label: 'page-height',\n placeholder: '(e.g., \"11in\", \"29.7cm\", \"800px\")',\n description: 'Specify the height of the page (e.g., \"11in\", \"29.7cm\", \"800px\")'\n },\n {\n type: 'string',\n name: 'marginTop',\n label: 'page-margin-top',\n placeholder: '(e.g., \"0.5in\", \"1cm\", \"100px\")',\n description: 'Set the top margin for the page'\n },\n {\n type: 'string',\n name: 'marginBottom',\n label: 'page-margin-bottom',\n placeholder: '(e.g., \"0.5in\", \"1cm\", \"100px\")',\n description: 'Set the bottom margin for the page'\n },\n {\n type: 'string',\n name: 'marginLeft',\n label: 'page-margin-left',\n placeholder: '(e.g., \"0.5in\", \"1cm\", \"100px\")',\n description: 'Set the left margin for the page'\n },\n {\n type: 'string',\n name: 'marginRight',\n label: 'page-margin-right',\n placeholder: '(e.g., \"0.5in\", \"1cm\", \"100px\")',\n description: 'Set the right margin for the page'\n },\n {\n type: 'number',\n name: 'scale',\n label: 'page-scale',\n defaultValue: 1,\n description: 'Set the scale of the page content (default is 1)'\n },\n {\n type: 'boolean',\n name: 'printBackground',\n label: 'print-background',\n defaultValue: true,\n description: 'Include background graphics when printing the page'\n },\n {\n type: 'boolean',\n name: 'landscape',\n label: 'landscape',\n defaultValue: false,\n description: 'Print the PDF in landscape orientation'\n },\n {\n type: 'boolean',\n name: 'preferCSSPageSize',\n label: 'prefer-css-page-size',\n defaultValue: false,\n description: 'Whether to prefer the CSS-defined page size over the given width and height'\n }\n ]\n}\n"]}
|
|
1
|
+
{"version":3,"file":"pdf-capture-util.js","sourceRoot":"","sources":["../../../server/engine/task/pdf-capture-util.ts"],"names":[],"mappings":";;;AA6OA,wDA6FC;;AA1UD,iDAA0B;AAC1B,uEAAoE;AACpE,qCAAqC;AAyBrC,MAAa,cAAc;IAMzB,YAAY,OAAmB;QAFxB,YAAO,GAAmB,IAAI,CAAA;QAGnC,IAAI,CAAC,OAAO,GAAG,OAAO,CAAA;IACxB,CAAC;IAED,KAAK,CAAC,WAAW,CAAC,cAAsB;QACtC,MAAM,EAAE,MAAM,EAAE,GAAG,IAAI,CAAC,OAAO,CAAA;QAC/B,IAAI,CAAC,YAAY,GAAG,oCAAiB,CAAC,2BAA2B,CAAC,MAAM,EAAE,cAAc,CAAC,CAAA;QACzF,IAAI,CAAC,OAAO,GAAG,MAAM,IAAI,CAAC,YAAY,CAAC,OAAO,EAAE,CAAA;IAClD,CAAC;IAED,KAAK,CAAC,YAAY;QAChB,IAAI,IAAI,CAAC,OAAO,EAAE,CAAC;YACjB,MAAM,IAAI,CAAC,OAAO,CAAC,KAAK,EAAE,CAAA;YAC1B,IAAI,CAAC,YAAY,CAAC,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,CAAA;QACzC,CAAC;IACH,CAAC;IAED,cAAc,CAAC,QAAgB,EAAE,IAAS;QACxC,MAAM,EAAE,MAAM,EAAE,GAAG,IAAI,CAAC,OAAO,CAAA;QAC/B,IAAI,CAAC;YACH,OAAO,GAAG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C9C,WAAW,EAAE,mCAAmC;SACjD;QACD;YACE,IAAI,EAAE,QAAQ;YACd,IAAI,EAAE,OAAO;YACb,KAAK,EAAE,YAAY;YACnB,YAAY,EAAE,CAAC;YACf,WAAW,EAAE,kDAAkD;SAChE;QACD;YACE,IAAI,EAAE,SAAS;YACf,IAAI,EAAE,iBAAiB;YACvB,KAAK,EAAE,kBAAkB;YACzB,YAAY,EAAE,IAAI;YAClB,WAAW,EAAE,oDAAoD;SAClE;QACD;YACE,IAAI,EAAE,SAAS;YACf,IAAI,EAAE,WAAW;YACjB,KAAK,EAAE,WAAW;YAClB,YAAY,EAAE,KAAK;YACnB,WAAW,EAAE,wCAAwC;SACtD;QACD;YACE,IAAI,EAAE,SAAS;YACf,IAAI,EAAE,mBAAmB;YACzB,KAAK,EAAE,sBAAsB;YAC7B,YAAY,EAAE,KAAK;YACnB,WAAW,EAAE,6EAA6E;SAC3F;KACF,CAAA;AACH,CAAC","sourcesContent":["import * as ejs from 'ejs'\nimport { ConnectionManager } from '@things-factory/integration-base'\nimport { PDFDocument } from 'pdf-lib'\nimport { Browser, Page } from 'puppeteer'\nimport { Logger } from 'winston'\n\ninterface StepOptions {\n format?: string\n width?: string\n height?: string\n marginTop?: string\n marginBottom?: string\n marginLeft?: string\n marginRight?: string\n scale?: number\n printBackground?: boolean\n landscape?: boolean\n preferCSSPageSize?: boolean\n}\n\ninterface PDFContext {\n domain: any\n data: any\n logger: Logger\n __headless_pdf: any\n}\n\nexport class PDFCaptureUtil {\n private context: PDFContext\n private headlessPool: any\n\n public browser: Browser | null = null\n\n constructor(context: PDFContext) {\n this.context = context\n }\n\n async initBrowser(connectionName: string) {\n const { domain } = this.context\n this.headlessPool = ConnectionManager.getConnectionInstanceByName(domain, connectionName)\n this.browser = await this.headlessPool.acquire()\n }\n\n async closeBrowser() {\n if (this.browser) {\n await this.browser.close()\n this.headlessPool.release(this.browser)\n }\n }\n\n renderTemplate(template: string, data: any): string {\n const { logger } = this.context\n try {\n return ejs.render(template, data)\n } catch (error) {\n logger.warn(`Template rendering error: ${error.message}`)\n return template\n }\n }\n\n async generatePDFContent(page: Page, pageOptions: any): Promise<PDFDocument> {\n const contentBuffer = await page.pdf(pageOptions)\n const contentPdfDoc = await PDFDocument.load(contentBuffer)\n return contentPdfDoc\n }\n\n async appendPDFContentToDocument(pdfDoc: PDFDocument, contentPdfDoc: PDFDocument) {\n const copiedPages = await pdfDoc.copyPages(contentPdfDoc, contentPdfDoc.getPageIndices())\n copiedPages.forEach(page => pdfDoc.addPage(page))\n this.context.__headless_pdf.pageCount += copiedPages.length\n }\n\n async processPageAndGeneratePDF(stepOptions: StepOptions, htmlContent: string, page?: Page) {\n if (!this.browser) throw new Error('Browser not initialized. Call initBrowser() first.')\n\n if (!page) {\n page = page || (await this.browser.newPage())\n }\n\n if (htmlContent) {\n // 페이지 컨텐츠 설정\n await page.setContent(htmlContent, { waitUntil: 'networkidle0' }) // HTML 컨텐츠가 완전히 로드될 때까지 대기\n }\n\n // 페이지가 완전히 로드된 후에 워터마크와 머릿글 적용\n const { __headless_pdf } = this.context\n const { header, footer, watermark, landscape } = __headless_pdf\n\n if (header || footer || watermark) {\n await this.applyHeaderFooterWatermark(page, { header, footer, watermark, landscape, data: __headless_pdf })\n }\n\n const pageOptions = this.buildPageOptions(stepOptions)\n const contentPdfDoc = await this.generatePDFContent(page, pageOptions)\n await this.appendPDFContentToDocument(__headless_pdf.pdfDoc, contentPdfDoc)\n await page.close()\n }\n\n buildPageOptions({\n format,\n width,\n height,\n marginTop,\n marginBottom,\n marginLeft,\n marginRight,\n scale,\n printBackground,\n landscape,\n preferCSSPageSize\n }: StepOptions): any {\n if (preferCSSPageSize) {\n width = undefined\n height = undefined\n }\n\n return {\n format,\n width,\n height,\n margin: {\n top: marginTop,\n right: marginRight,\n bottom: marginBottom,\n left: marginLeft\n },\n scale,\n printBackground,\n landscape,\n displayHeaderFooter: false,\n preferCSSPageSize\n }\n }\n\n async applyHeaderFooterWatermark(\n page: Page,\n {\n header,\n footer,\n watermark,\n landscape,\n data\n }: { header: string; footer: string; watermark: string; landscape: boolean; data: any }\n ) {\n await page.evaluate(\n ({ header, footer, watermark, landscape, data }) => {\n const setPositioning = (element: HTMLElement, position: 'header' | 'footer') => {\n element.style.position = 'fixed'\n element.style.left = '0'\n element.style.width = '100%'\n element.style.textAlign = 'center'\n element.style.fontSize = '12px'\n element.style.margin = '0'\n element.style.padding = '0'\n element.style.zIndex = '1000'\n\n if (position === 'header') {\n element.style.top = '0'\n } else if (position === 'footer') {\n element.style.bottom = '0'\n }\n }\n\n if (header) {\n const headerElement = document.createElement('div')\n headerElement.innerHTML = header\n setPositioning(headerElement, 'header')\n document.body.appendChild(headerElement)\n }\n\n if (footer) {\n const footerElement = document.createElement('div')\n footerElement.innerHTML = footer\n setPositioning(footerElement, 'footer')\n document.body.appendChild(footerElement)\n }\n\n if (watermark) {\n const watermarkElement = document.createElement('div')\n watermarkElement.innerHTML = watermark\n watermarkElement.style.position = 'fixed'\n watermarkElement.style.top = landscape ? '40%' : '50%'\n watermarkElement.style.left = '50%'\n watermarkElement.style.transform = 'translate(-50%, -50%) rotate(-45deg)'\n watermarkElement.style.opacity = '0.2'\n watermarkElement.style.fontSize = '50px'\n watermarkElement.style.color = 'red'\n watermarkElement.style.pointerEvents = 'none'\n watermarkElement.style.zIndex = '9999'\n document.body.appendChild(watermarkElement)\n }\n },\n {\n header: header && this.renderTemplate(header, data),\n footer: footer && this.renderTemplate(footer, data),\n watermark: watermark && this.renderTemplate(watermark, data),\n landscape,\n data\n }\n )\n }\n\n /**\n * Generates a PDF buffer for the last page.\n * @param stepOptions - Options used for generating the PDF.\n * @param htmlContent - HTML content to be converted to PDF.\n * @returns {Promise<Uint8Array>} - The generated PDF as a buffer.\n */\n async generateLastPageBuffer(stepOptions: StepOptions, htmlContent: string): Promise<Uint8Array> {\n if (!this.browser) throw new Error('Browser not initialized. Call initBrowser() first.')\n\n const page = await this.browser.newPage()\n\n // 페이지에 HTML 콘텐츠를 설정합니다.\n await page.setContent(htmlContent, { waitUntil: 'networkidle0' })\n\n // 페이지가 완전히 로드된 후에 워터마크와 머릿글 적용\n const { __headless_pdf } = this.context\n const { header, footer, watermark, landscape } = __headless_pdf\n\n if (header || footer || watermark) {\n await this.applyHeaderFooterWatermark(page, { header, footer, watermark, landscape, data: __headless_pdf })\n }\n\n // 페이지 옵션 설정\n const pageOptions = this.buildPageOptions(stepOptions)\n\n // PDF를 생성하고 버퍼를 반환합니다.\n const lastPageBuffer = await page.pdf(pageOptions)\n\n // 페이지 닫기\n await page.close()\n\n return lastPageBuffer\n }\n}\n\nexport function getCommonParameterSpec() {\n return [\n {\n type: 'scenario-step-input',\n name: 'accessor',\n label: 'accessor'\n },\n {\n type: 'select',\n name: 'format',\n label: 'page-format',\n property: {\n options: [\n { display: '', value: '' },\n { display: 'A4', value: 'A4' },\n { display: 'A3', value: 'A3' },\n { display: 'Letter', value: 'Letter' },\n { display: 'Legal', value: 'Legal' }\n ]\n },\n description: 'Select the paper format for the PDF'\n },\n {\n type: 'string',\n name: 'width',\n label: 'page-width',\n placeholder: '(e.g., \"8.5in\", \"21cm\", \"600px\")',\n description: 'Specify the width of the page (e.g., \"8.5in\", \"21cm\", \"600px\")'\n },\n {\n type: 'string',\n name: 'height',\n label: 'page-height',\n placeholder: '(e.g., \"11in\", \"29.7cm\", \"800px\")',\n description: 'Specify the height of the page (e.g., \"11in\", \"29.7cm\", \"800px\")'\n },\n {\n type: 'string',\n name: 'marginTop',\n label: 'page-margin-top',\n placeholder: '(e.g., \"0.5in\", \"1cm\", \"100px\")',\n description: 'Set the top margin for the page'\n },\n {\n type: 'string',\n name: 'marginBottom',\n label: 'page-margin-bottom',\n placeholder: '(e.g., \"0.5in\", \"1cm\", \"100px\")',\n description: 'Set the bottom margin for the page'\n },\n {\n type: 'string',\n name: 'marginLeft',\n label: 'page-margin-left',\n placeholder: '(e.g., \"0.5in\", \"1cm\", \"100px\")',\n description: 'Set the left margin for the page'\n },\n {\n type: 'string',\n name: 'marginRight',\n label: 'page-margin-right',\n placeholder: '(e.g., \"0.5in\", \"1cm\", \"100px\")',\n description: 'Set the right margin for the page'\n },\n {\n type: 'number',\n name: 'scale',\n label: 'page-scale',\n defaultValue: 1,\n description: 'Set the scale of the page content (default is 1)'\n },\n {\n type: 'boolean',\n name: 'printBackground',\n label: 'print-background',\n defaultValue: true,\n description: 'Include background graphics when printing the page'\n },\n {\n type: 'boolean',\n name: 'landscape',\n label: 'landscape',\n defaultValue: false,\n description: 'Print the PDF in landscape orientation'\n },\n {\n type: 'boolean',\n name: 'preferCSSPageSize',\n label: 'prefer-css-page-size',\n defaultValue: false,\n description: 'Whether to prefer the CSS-defined page size over the given width and height'\n }\n ]\n}\n"]}
|