chromiumly 2.6.0 → 2.8.0
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/README.md +147 -42
- package/dist/chromium/converters/converter.d.ts +1 -1
- package/dist/chromium/converters/converter.js +1 -1
- package/dist/chromium/converters/converter.js.map +1 -1
- package/dist/chromium/converters/html.converter.d.ts +9 -4
- package/dist/chromium/converters/html.converter.js +7 -3
- package/dist/chromium/converters/html.converter.js.map +1 -1
- package/dist/chromium/converters/markdown.converter.d.ts +9 -4
- package/dist/chromium/converters/markdown.converter.js +7 -3
- package/dist/chromium/converters/markdown.converter.js.map +1 -1
- package/dist/chromium/converters/url.converter.d.ts +9 -4
- package/dist/chromium/converters/url.converter.js +6 -2
- package/dist/chromium/converters/url.converter.js.map +1 -1
- package/dist/chromium/index.d.ts +6 -3
- package/dist/chromium/index.js +7 -1
- package/dist/chromium/index.js.map +1 -1
- package/dist/chromium/interfaces/common.types.d.ts +13 -0
- package/dist/chromium/interfaces/common.types.js +3 -0
- package/dist/chromium/interfaces/common.types.js.map +1 -0
- package/dist/chromium/interfaces/converter.types.d.ts +4 -10
- package/dist/chromium/interfaces/screenshot.types.d.ts +10 -0
- package/dist/chromium/interfaces/screenshot.types.js +3 -0
- package/dist/chromium/interfaces/screenshot.types.js.map +1 -0
- package/dist/chromium/screenshots/html.screenshot.d.ts +54 -0
- package/dist/chromium/screenshots/html.screenshot.js +67 -0
- package/dist/chromium/screenshots/html.screenshot.js.map +1 -0
- package/dist/chromium/screenshots/markdown.screenshot.d.ts +52 -0
- package/dist/chromium/screenshots/markdown.screenshot.js +66 -0
- package/dist/chromium/screenshots/markdown.screenshot.js.map +1 -0
- package/dist/chromium/screenshots/screenshot.d.ts +18 -0
- package/dist/chromium/screenshots/screenshot.js +21 -0
- package/dist/chromium/screenshots/screenshot.js.map +1 -0
- package/dist/chromium/screenshots/url.screenshot.d.ts +50 -0
- package/dist/chromium/screenshots/url.screenshot.js +66 -0
- package/dist/chromium/screenshots/url.screenshot.js.map +1 -0
- package/dist/chromium/utils/converter.utils.d.ts +2 -12
- package/dist/chromium/utils/converter.utils.js +36 -50
- package/dist/chromium/utils/converter.utils.js.map +1 -1
- package/dist/chromium/utils/screenshot.utils.d.ts +22 -0
- package/dist/chromium/utils/screenshot.utils.js +75 -0
- package/dist/chromium/utils/screenshot.utils.js.map +1 -0
- package/dist/common/gotenberg.utils.d.ts +11 -1
- package/dist/common/gotenberg.utils.js +25 -2
- package/dist/common/gotenberg.utils.js.map +1 -1
- package/dist/common/index.d.ts +3 -3
- package/dist/common/index.js.map +1 -1
- package/dist/common/types.d.ts +1 -1
- package/dist/gotenberg.js +4 -3
- package/dist/gotenberg.js.map +1 -1
- package/dist/libre-office/index.d.ts +2 -2
- package/dist/libre-office/index.js.map +1 -1
- package/dist/libre-office/utils/constants.js +80 -76
- package/dist/libre-office/utils/constants.js.map +1 -1
- package/dist/libre-office/utils/libre-office.utils.d.ts +3 -3
- package/dist/libre-office/utils/libre-office.utils.js +5 -5
- package/dist/libre-office/utils/libre-office.utils.js.map +1 -1
- package/dist/main.config.d.ts +6 -1
- package/dist/main.config.js +11 -6
- package/dist/main.config.js.map +1 -1
- package/dist/main.d.ts +3 -3
- package/dist/main.js +4 -1
- package/dist/main.js.map +1 -1
- package/dist/pdf-engines/index.d.ts +1 -1
- package/dist/pdf-engines/index.js.map +1 -1
- package/dist/pdf-engines/pdf.engine.d.ts +3 -3
- package/dist/pdf-engines/pdf.engine.js +5 -5
- package/dist/pdf-engines/pdf.engine.js.map +1 -1
- package/dist/pdf-engines/utils/engine.utils.d.ts +2 -2
- package/dist/pdf-engines/utils/engine.utils.js +3 -3
- package/dist/pdf-engines/utils/engine.utils.js.map +1 -1
- package/package.json +20 -12
- package/src/.prettierrc.yml +4 -0
- package/src/chromium/converters/converter.ts +2 -2
- package/src/chromium/converters/html.converter.ts +37 -27
- package/src/chromium/converters/markdown.converter.ts +32 -26
- package/src/chromium/converters/tests/html.converter.test.ts +97 -73
- package/src/chromium/converters/tests/markdown.converter.test.ts +102 -77
- package/src/chromium/converters/tests/url.converter.test.ts +90 -66
- package/src/chromium/converters/url.converter.ts +31 -25
- package/src/chromium/index.ts +6 -3
- package/src/chromium/interfaces/common.types.ts +15 -0
- package/src/chromium/interfaces/converter.types.ts +4 -12
- package/src/chromium/interfaces/screenshot.types.ts +12 -0
- package/src/chromium/screenshots/html.screenshot.ts +100 -0
- package/src/chromium/screenshots/markdown.screenshot.ts +95 -0
- package/src/chromium/screenshots/screenshot.ts +22 -0
- package/src/chromium/screenshots/tests/html.screenshot.test.ts +192 -0
- package/src/chromium/screenshots/tests/markdown.screenshot.test.ts +176 -0
- package/src/chromium/screenshots/tests/url.screenshot.test.ts +166 -0
- package/src/chromium/screenshots/url.screenshot.ts +91 -0
- package/src/chromium/utils/converter.utils.ts +67 -60
- package/src/chromium/utils/screenshot.utils.ts +115 -0
- package/src/chromium/utils/tests/converter.utils.test.ts +250 -168
- package/src/chromium/utils/tests/screenshot.utils.test.ts +284 -0
- package/src/common/constants.ts +3 -3
- package/src/common/gotenberg.utils.ts +39 -8
- package/src/common/index.ts +3 -3
- package/src/common/tests/gotenberg.utils.test.ts +84 -31
- package/src/common/types.ts +2 -2
- package/src/gotenberg.ts +9 -9
- package/src/libre-office/index.ts +2 -2
- package/src/libre-office/utils/constants.ts +80 -76
- package/src/libre-office/utils/libre-office.utils.ts +21 -18
- package/src/libre-office/utils/tests/libre-office.utils.test.ts +58 -49
- package/src/main.config.ts +19 -13
- package/src/main.ts +10 -3
- package/src/pdf-engines/index.ts +1 -1
- package/src/pdf-engines/pdf.engine.ts +23 -19
- package/src/pdf-engines/tests/pdf.engine.test.ts +52 -49
- package/src/pdf-engines/utils/engine.utils.ts +12 -9
- package/src/pdf-engines/utils/tests/engine.utils.test.ts +23 -23
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { ChromiumOptions } from './common.types';
|
|
2
|
+
export type ImageProperties = {
|
|
3
|
+
format: 'png' | 'jpeg' | 'webp';
|
|
4
|
+
quality?: number;
|
|
5
|
+
omitBackground?: boolean;
|
|
6
|
+
};
|
|
7
|
+
export type ScreenshotOptions = ChromiumOptions & {
|
|
8
|
+
properties?: ImageProperties;
|
|
9
|
+
optimizeForSpeed?: boolean;
|
|
10
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"screenshot.types.js","sourceRoot":"","sources":["../../../src/chromium/interfaces/screenshot.types.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import { PathLikeOrReadStream } from '../../common';
|
|
3
|
+
import { EmulatedMediaType } from '../interfaces/common.types';
|
|
4
|
+
import { Screenshot } from './screenshot';
|
|
5
|
+
import { ImageProperties } from '../interfaces/screenshot.types';
|
|
6
|
+
/**
|
|
7
|
+
* Class representing an HTML Screenshot that extends the base Screenshot class.
|
|
8
|
+
* This class is used to screenshot HTML content using Gotenberg service.
|
|
9
|
+
*
|
|
10
|
+
* @extends Screenshot
|
|
11
|
+
*/
|
|
12
|
+
export declare class HtmlScreenshot extends Screenshot {
|
|
13
|
+
/**
|
|
14
|
+
* Creates an instance of HtmlScreenshot.
|
|
15
|
+
* Initializes the Screenshot with the HTML screenshot route.
|
|
16
|
+
*/
|
|
17
|
+
constructor();
|
|
18
|
+
/**
|
|
19
|
+
* Screenshots HTML content.
|
|
20
|
+
*
|
|
21
|
+
* @param {Object} options - Screenshot options.
|
|
22
|
+
* @param {PathLikeOrReadStream} options.html - PathLike or ReadStream of the HTML content to be screenshoted.
|
|
23
|
+
* @param {PathLikeOrReadStream} [options.header] - PathLike or ReadStream of the header HTML content.
|
|
24
|
+
* @param {PathLikeOrReadStream} [options.footer] - PathLike or ReadStream of the footer HTML content.
|
|
25
|
+
* @param {ImageProperties} [options.properties] - Image properties for the screenshot.
|
|
26
|
+
* @param {EmulatedMediaType} [options.emulatedMediaType] - Emulated media type for the screenshot.
|
|
27
|
+
* @param {string} [options.waitDelay] - Delay before the screenshot process starts.
|
|
28
|
+
* @param {string} [options.waitForExpression] - JavaScript expression to wait for before completing the screenshot.
|
|
29
|
+
* @param {Record<string, string>} [options.extraHttpHeaders] - Additional HTTP headers for the screenshot.
|
|
30
|
+
* @param {number []} [options.failOnHttpStatusCodes] - Whether to fail on HTTP status code.
|
|
31
|
+
* @param {boolean} [options.failOnConsoleExceptions] - Whether to fail on console exceptions during screenshot.
|
|
32
|
+
* @param {boolean} [options.skipNetworkIdleEvent] - Whether to skip network idle event.
|
|
33
|
+
* @param {boolean} [options.optimizeForSpeed] - Whether to optimize for speed.
|
|
34
|
+
* @returns {Promise<Buffer>} A Promise resolving to the image buffer.
|
|
35
|
+
*/
|
|
36
|
+
capture({ html, assets, header, footer, properties, emulatedMediaType, waitDelay, waitForExpression, extraHttpHeaders, failOnConsoleExceptions, failOnHttpStatusCodes, skipNetworkIdleEvent, optimizeForSpeed }: {
|
|
37
|
+
html: PathLikeOrReadStream;
|
|
38
|
+
assets?: {
|
|
39
|
+
file: PathLikeOrReadStream;
|
|
40
|
+
name: string;
|
|
41
|
+
}[];
|
|
42
|
+
header?: PathLikeOrReadStream;
|
|
43
|
+
footer?: PathLikeOrReadStream;
|
|
44
|
+
properties?: ImageProperties;
|
|
45
|
+
emulatedMediaType?: EmulatedMediaType;
|
|
46
|
+
waitDelay?: string;
|
|
47
|
+
waitForExpression?: string;
|
|
48
|
+
extraHttpHeaders?: Record<string, string>;
|
|
49
|
+
failOnConsoleExceptions?: boolean;
|
|
50
|
+
failOnHttpStatusCodes?: number[];
|
|
51
|
+
skipNetworkIdleEvent?: boolean;
|
|
52
|
+
optimizeForSpeed?: boolean;
|
|
53
|
+
}): Promise<Buffer>;
|
|
54
|
+
}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.HtmlScreenshot = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const form_data_1 = tslib_1.__importDefault(require("form-data"));
|
|
6
|
+
const common_1 = require("../../common");
|
|
7
|
+
const main_config_1 = require("../../main.config");
|
|
8
|
+
const screenshot_utils_1 = require("../utils/screenshot.utils");
|
|
9
|
+
const screenshot_1 = require("./screenshot");
|
|
10
|
+
/**
|
|
11
|
+
* Class representing an HTML Screenshot that extends the base Screenshot class.
|
|
12
|
+
* This class is used to screenshot HTML content using Gotenberg service.
|
|
13
|
+
*
|
|
14
|
+
* @extends Screenshot
|
|
15
|
+
*/
|
|
16
|
+
class HtmlScreenshot extends screenshot_1.Screenshot {
|
|
17
|
+
/**
|
|
18
|
+
* Creates an instance of HtmlScreenshot.
|
|
19
|
+
* Initializes the Screenshot with the HTML screenshot route.
|
|
20
|
+
*/
|
|
21
|
+
constructor() {
|
|
22
|
+
super(main_config_1.ChromiumRoute.HTML);
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Screenshots HTML content.
|
|
26
|
+
*
|
|
27
|
+
* @param {Object} options - Screenshot options.
|
|
28
|
+
* @param {PathLikeOrReadStream} options.html - PathLike or ReadStream of the HTML content to be screenshoted.
|
|
29
|
+
* @param {PathLikeOrReadStream} [options.header] - PathLike or ReadStream of the header HTML content.
|
|
30
|
+
* @param {PathLikeOrReadStream} [options.footer] - PathLike or ReadStream of the footer HTML content.
|
|
31
|
+
* @param {ImageProperties} [options.properties] - Image properties for the screenshot.
|
|
32
|
+
* @param {EmulatedMediaType} [options.emulatedMediaType] - Emulated media type for the screenshot.
|
|
33
|
+
* @param {string} [options.waitDelay] - Delay before the screenshot process starts.
|
|
34
|
+
* @param {string} [options.waitForExpression] - JavaScript expression to wait for before completing the screenshot.
|
|
35
|
+
* @param {Record<string, string>} [options.extraHttpHeaders] - Additional HTTP headers for the screenshot.
|
|
36
|
+
* @param {number []} [options.failOnHttpStatusCodes] - Whether to fail on HTTP status code.
|
|
37
|
+
* @param {boolean} [options.failOnConsoleExceptions] - Whether to fail on console exceptions during screenshot.
|
|
38
|
+
* @param {boolean} [options.skipNetworkIdleEvent] - Whether to skip network idle event.
|
|
39
|
+
* @param {boolean} [options.optimizeForSpeed] - Whether to optimize for speed.
|
|
40
|
+
* @returns {Promise<Buffer>} A Promise resolving to the image buffer.
|
|
41
|
+
*/
|
|
42
|
+
capture({ html, assets, header, footer, properties, emulatedMediaType, waitDelay, waitForExpression, extraHttpHeaders, failOnConsoleExceptions, failOnHttpStatusCodes, skipNetworkIdleEvent, optimizeForSpeed }) {
|
|
43
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
44
|
+
const data = new form_data_1.default();
|
|
45
|
+
yield common_1.GotenbergUtils.addFile(data, html, 'index.html');
|
|
46
|
+
if (assets === null || assets === void 0 ? void 0 : assets.length) {
|
|
47
|
+
yield Promise.all(assets.map(({ file, name }) => common_1.GotenbergUtils.addFile(data, file, name)));
|
|
48
|
+
}
|
|
49
|
+
yield screenshot_utils_1.ScreenshotUtils.customize(data, {
|
|
50
|
+
header,
|
|
51
|
+
footer,
|
|
52
|
+
properties,
|
|
53
|
+
emulatedMediaType,
|
|
54
|
+
waitDelay,
|
|
55
|
+
waitForExpression,
|
|
56
|
+
extraHttpHeaders,
|
|
57
|
+
failOnHttpStatusCodes,
|
|
58
|
+
failOnConsoleExceptions,
|
|
59
|
+
skipNetworkIdleEvent,
|
|
60
|
+
optimizeForSpeed
|
|
61
|
+
});
|
|
62
|
+
return common_1.GotenbergUtils.fetch(this.endpoint, data);
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
exports.HtmlScreenshot = HtmlScreenshot;
|
|
67
|
+
//# sourceMappingURL=html.screenshot.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"html.screenshot.js","sourceRoot":"","sources":["../../../src/chromium/screenshots/html.screenshot.ts"],"names":[],"mappings":";;;;AAAA,kEAAiC;AAEjC,yCAAoE;AACpE,mDAAkD;AAElD,gEAA4D;AAC5D,6CAA0C;AAG1C;;;;;GAKG;AACH,MAAa,cAAe,SAAQ,uBAAU;IAC1C;;;OAGG;IACH;QACI,KAAK,CAAC,2BAAa,CAAC,IAAI,CAAC,CAAC;IAC9B,CAAC;IAED;;;;;;;;;;;;;;;;;OAiBG;IACG,OAAO,CAAC,EACV,IAAI,EACJ,MAAM,EACN,MAAM,EACN,MAAM,EACN,UAAU,EACV,iBAAiB,EACjB,SAAS,EACT,iBAAiB,EACjB,gBAAgB,EAChB,uBAAuB,EACvB,qBAAqB,EACrB,oBAAoB,EACpB,gBAAgB,EAenB;;YACG,MAAM,IAAI,GAAG,IAAI,mBAAQ,EAAE,CAAC;YAE5B,MAAM,uBAAc,CAAC,OAAO,CAAC,IAAI,EAAE,IAAI,EAAE,YAAY,CAAC,CAAC;YAEvD,IAAI,MAAM,aAAN,MAAM,uBAAN,MAAM,CAAE,MAAM,EAAE,CAAC;gBACjB,MAAM,OAAO,CAAC,GAAG,CACb,MAAM,CAAC,GAAG,CAAC,CAAC,EAAE,IAAI,EAAE,IAAI,EAAE,EAAE,EAAE,CAC1B,uBAAc,CAAC,OAAO,CAAC,IAAI,EAAE,IAAI,EAAE,IAAI,CAAC,CAC3C,CACJ,CAAC;YACN,CAAC;YAED,MAAM,kCAAe,CAAC,SAAS,CAAC,IAAI,EAAE;gBAClC,MAAM;gBACN,MAAM;gBACN,UAAU;gBACV,iBAAiB;gBACjB,SAAS;gBACT,iBAAiB;gBACjB,gBAAgB;gBAChB,qBAAqB;gBACrB,uBAAuB;gBACvB,oBAAoB;gBACpB,gBAAgB;aACnB,CAAC,CAAC;YAEH,OAAO,uBAAc,CAAC,KAAK,CAAC,IAAI,CAAC,QAAQ,EAAE,IAAI,CAAC,CAAC;QACrD,CAAC;KAAA;CACJ;AApFD,wCAoFC"}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import { PathLikeOrReadStream } from '../../common';
|
|
3
|
+
import { ImageProperties } from '../interfaces/screenshot.types';
|
|
4
|
+
import { Screenshot } from './screenshot';
|
|
5
|
+
import { EmulatedMediaType } from '../interfaces/common.types';
|
|
6
|
+
/**
|
|
7
|
+
* Class representing a Markdown screenshot that extends the base Screenshot class.
|
|
8
|
+
* This class is used to screenshots HTML with markdown content using Gotenberg service.
|
|
9
|
+
*
|
|
10
|
+
* @extends Screenshot
|
|
11
|
+
*/
|
|
12
|
+
export declare class MarkdownScreenshot extends Screenshot {
|
|
13
|
+
/**
|
|
14
|
+
* Creates an instance of MarkdownScreenshot.
|
|
15
|
+
* Initializes the Screenshot with the Markdown screenshot route.
|
|
16
|
+
*/
|
|
17
|
+
constructor();
|
|
18
|
+
/**
|
|
19
|
+
* Screenshots HTML with markdown.
|
|
20
|
+
*
|
|
21
|
+
* @param {Object} options - Screenshot options.
|
|
22
|
+
* @param {PathLikeOrReadStream} options.html - PathLike or ReadStream of the HTML content to be screenshoted.
|
|
23
|
+
* @param {PathLikeOrReadStream} options.markdown - PathLike or ReadStream of the Markdown content to be screenshoted.
|
|
24
|
+
* @param {PathLikeOrReadStream} [options.header] - PathLike or ReadStream of the header HTML content.
|
|
25
|
+
* @param {PathLikeOrReadStream} [options.footer] - PathLike or ReadStream of the footer HTML content.
|
|
26
|
+
* @param {ImageProperties} [options.properties] - Image properties for the screenshot.
|
|
27
|
+
* @param {EmulatedMediaType} [options.emulatedMediaType] - Emulated media type for the screenshot.
|
|
28
|
+
* @param {string} [options.waitDelay] - Delay before the screenshot process starts.
|
|
29
|
+
* @param {string} [options.waitForExpression] - JavaScript expression to wait for before completing the screenshot.
|
|
30
|
+
* @param {Record<string, string>} [options.extraHttpHeaders] - Additional HTTP headers for the screenshot.
|
|
31
|
+
* @param {number []} [options.failOnHttpStatusCodes] - Whether to fail on HTTP status code.
|
|
32
|
+
* @param {boolean} [options.failOnConsoleExceptions] - Whether to fail on console exceptions during screenshot.
|
|
33
|
+
* @param {boolean} [options.skipNetworkIdleEvent] - Whether to skip network idle event.
|
|
34
|
+
* @param {boolean} [options.optimizeForSpeed] - Whether to optimize for speed.
|
|
35
|
+
* @returns {Promise<Buffer>} A Promise resolving to the image buffer.
|
|
36
|
+
*/
|
|
37
|
+
capture({ html, markdown, header, footer, properties, emulatedMediaType, waitDelay, waitForExpression, extraHttpHeaders, failOnHttpStatusCodes, failOnConsoleExceptions, skipNetworkIdleEvent, optimizeForSpeed }: {
|
|
38
|
+
html: PathLikeOrReadStream;
|
|
39
|
+
markdown: PathLikeOrReadStream;
|
|
40
|
+
header?: PathLikeOrReadStream;
|
|
41
|
+
footer?: PathLikeOrReadStream;
|
|
42
|
+
properties?: ImageProperties;
|
|
43
|
+
emulatedMediaType?: EmulatedMediaType;
|
|
44
|
+
waitDelay?: string;
|
|
45
|
+
waitForExpression?: string;
|
|
46
|
+
extraHttpHeaders?: Record<string, string>;
|
|
47
|
+
failOnHttpStatusCodes?: number[];
|
|
48
|
+
failOnConsoleExceptions?: boolean;
|
|
49
|
+
skipNetworkIdleEvent?: boolean;
|
|
50
|
+
optimizeForSpeed?: boolean;
|
|
51
|
+
}): Promise<Buffer>;
|
|
52
|
+
}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.MarkdownScreenshot = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const form_data_1 = tslib_1.__importDefault(require("form-data"));
|
|
6
|
+
const common_1 = require("../../common");
|
|
7
|
+
const screenshot_utils_1 = require("../utils/screenshot.utils");
|
|
8
|
+
const screenshot_1 = require("./screenshot");
|
|
9
|
+
const main_config_1 = require("../../main.config");
|
|
10
|
+
/**
|
|
11
|
+
* Class representing a Markdown screenshot that extends the base Screenshot class.
|
|
12
|
+
* This class is used to screenshots HTML with markdown content using Gotenberg service.
|
|
13
|
+
*
|
|
14
|
+
* @extends Screenshot
|
|
15
|
+
*/
|
|
16
|
+
class MarkdownScreenshot extends screenshot_1.Screenshot {
|
|
17
|
+
/**
|
|
18
|
+
* Creates an instance of MarkdownScreenshot.
|
|
19
|
+
* Initializes the Screenshot with the Markdown screenshot route.
|
|
20
|
+
*/
|
|
21
|
+
constructor() {
|
|
22
|
+
super(main_config_1.ChromiumRoute.MARKDOWN);
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Screenshots HTML with markdown.
|
|
26
|
+
*
|
|
27
|
+
* @param {Object} options - Screenshot options.
|
|
28
|
+
* @param {PathLikeOrReadStream} options.html - PathLike or ReadStream of the HTML content to be screenshoted.
|
|
29
|
+
* @param {PathLikeOrReadStream} options.markdown - PathLike or ReadStream of the Markdown content to be screenshoted.
|
|
30
|
+
* @param {PathLikeOrReadStream} [options.header] - PathLike or ReadStream of the header HTML content.
|
|
31
|
+
* @param {PathLikeOrReadStream} [options.footer] - PathLike or ReadStream of the footer HTML content.
|
|
32
|
+
* @param {ImageProperties} [options.properties] - Image properties for the screenshot.
|
|
33
|
+
* @param {EmulatedMediaType} [options.emulatedMediaType] - Emulated media type for the screenshot.
|
|
34
|
+
* @param {string} [options.waitDelay] - Delay before the screenshot process starts.
|
|
35
|
+
* @param {string} [options.waitForExpression] - JavaScript expression to wait for before completing the screenshot.
|
|
36
|
+
* @param {Record<string, string>} [options.extraHttpHeaders] - Additional HTTP headers for the screenshot.
|
|
37
|
+
* @param {number []} [options.failOnHttpStatusCodes] - Whether to fail on HTTP status code.
|
|
38
|
+
* @param {boolean} [options.failOnConsoleExceptions] - Whether to fail on console exceptions during screenshot.
|
|
39
|
+
* @param {boolean} [options.skipNetworkIdleEvent] - Whether to skip network idle event.
|
|
40
|
+
* @param {boolean} [options.optimizeForSpeed] - Whether to optimize for speed.
|
|
41
|
+
* @returns {Promise<Buffer>} A Promise resolving to the image buffer.
|
|
42
|
+
*/
|
|
43
|
+
capture({ html, markdown, header, footer, properties, emulatedMediaType, waitDelay, waitForExpression, extraHttpHeaders, failOnHttpStatusCodes, failOnConsoleExceptions, skipNetworkIdleEvent, optimizeForSpeed }) {
|
|
44
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
45
|
+
const data = new form_data_1.default();
|
|
46
|
+
yield common_1.GotenbergUtils.addFile(data, html, 'index.html');
|
|
47
|
+
yield common_1.GotenbergUtils.addFile(data, markdown, 'file.md');
|
|
48
|
+
yield screenshot_utils_1.ScreenshotUtils.customize(data, {
|
|
49
|
+
header,
|
|
50
|
+
footer,
|
|
51
|
+
properties,
|
|
52
|
+
emulatedMediaType,
|
|
53
|
+
waitDelay,
|
|
54
|
+
waitForExpression,
|
|
55
|
+
extraHttpHeaders,
|
|
56
|
+
failOnHttpStatusCodes,
|
|
57
|
+
failOnConsoleExceptions,
|
|
58
|
+
skipNetworkIdleEvent,
|
|
59
|
+
optimizeForSpeed
|
|
60
|
+
});
|
|
61
|
+
return common_1.GotenbergUtils.fetch(this.endpoint, data);
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
exports.MarkdownScreenshot = MarkdownScreenshot;
|
|
66
|
+
//# sourceMappingURL=markdown.screenshot.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"markdown.screenshot.js","sourceRoot":"","sources":["../../../src/chromium/screenshots/markdown.screenshot.ts"],"names":[],"mappings":";;;;AAAA,kEAAiC;AAEjC,yCAAoE;AAEpE,gEAA4D;AAC5D,6CAA0C;AAC1C,mDAAkD;AAGlD;;;;;GAKG;AACH,MAAa,kBAAmB,SAAQ,uBAAU;IAC9C;;;OAGG;IACH;QACI,KAAK,CAAC,2BAAa,CAAC,QAAQ,CAAC,CAAC;IAClC,CAAC;IAED;;;;;;;;;;;;;;;;;;OAkBG;IACG,OAAO,CAAC,EACV,IAAI,EACJ,QAAQ,EACR,MAAM,EACN,MAAM,EACN,UAAU,EACV,iBAAiB,EACjB,SAAS,EACT,iBAAiB,EACjB,gBAAgB,EAChB,qBAAqB,EACrB,uBAAuB,EACvB,oBAAoB,EACpB,gBAAgB,EAenB;;YACG,MAAM,IAAI,GAAG,IAAI,mBAAQ,EAAE,CAAC;YAE5B,MAAM,uBAAc,CAAC,OAAO,CAAC,IAAI,EAAE,IAAI,EAAE,YAAY,CAAC,CAAC;YAEvD,MAAM,uBAAc,CAAC,OAAO,CAAC,IAAI,EAAE,QAAQ,EAAE,SAAS,CAAC,CAAC;YAExD,MAAM,kCAAe,CAAC,SAAS,CAAC,IAAI,EAAE;gBAClC,MAAM;gBACN,MAAM;gBACN,UAAU;gBACV,iBAAiB;gBACjB,SAAS;gBACT,iBAAiB;gBACjB,gBAAgB;gBAChB,qBAAqB;gBACrB,uBAAuB;gBACvB,oBAAoB;gBACpB,gBAAgB;aACnB,CAAC,CAAC;YAEH,OAAO,uBAAc,CAAC,KAAK,CAAC,IAAI,CAAC,QAAQ,EAAE,IAAI,CAAC,CAAC;QACrD,CAAC;KAAA;CACJ;AA/ED,gDA+EC"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { ChromiumRoute } from '../../main.config';
|
|
2
|
+
/**
|
|
3
|
+
* Abstract class representing a generic screenshot.
|
|
4
|
+
* Concrete screenshot classes should extend this class and implement specific screenshot logic.
|
|
5
|
+
*/
|
|
6
|
+
export declare abstract class Screenshot {
|
|
7
|
+
/**
|
|
8
|
+
* The endpoint URL for the screenshot.
|
|
9
|
+
*/
|
|
10
|
+
readonly endpoint: string;
|
|
11
|
+
/**
|
|
12
|
+
* Creates an instance of the screenshot class.
|
|
13
|
+
* Initializes the endpoint URL based on the provided ChromiumRoute.
|
|
14
|
+
*
|
|
15
|
+
* @param {ChromiumRoute} route - The ChromiumRoute enum value representing the screenshot route.
|
|
16
|
+
*/
|
|
17
|
+
constructor(route: ChromiumRoute);
|
|
18
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Screenshot = void 0;
|
|
4
|
+
const main_config_1 = require("../../main.config");
|
|
5
|
+
/**
|
|
6
|
+
* Abstract class representing a generic screenshot.
|
|
7
|
+
* Concrete screenshot classes should extend this class and implement specific screenshot logic.
|
|
8
|
+
*/
|
|
9
|
+
class Screenshot {
|
|
10
|
+
/**
|
|
11
|
+
* Creates an instance of the screenshot class.
|
|
12
|
+
* Initializes the endpoint URL based on the provided ChromiumRoute.
|
|
13
|
+
*
|
|
14
|
+
* @param {ChromiumRoute} route - The ChromiumRoute enum value representing the screenshot route.
|
|
15
|
+
*/
|
|
16
|
+
constructor(route) {
|
|
17
|
+
this.endpoint = `${main_config_1.Chromiumly.GOTENBERG_ENDPOINT}/${main_config_1.Chromiumly.CHROMIUM_SCREENSHOT_PATH}/${main_config_1.Chromiumly.CHROMIUM_ROUTES[route]}`;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
exports.Screenshot = Screenshot;
|
|
21
|
+
//# sourceMappingURL=screenshot.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"screenshot.js","sourceRoot":"","sources":["../../../src/chromium/screenshots/screenshot.ts"],"names":[],"mappings":";;;AAAA,mDAA8D;AAE9D;;;GAGG;AACH,MAAsB,UAAU;IAM5B;;;;;OAKG;IACH,YAAY,KAAoB;QAC5B,IAAI,CAAC,QAAQ,GAAG,GAAG,wBAAU,CAAC,kBAAkB,IAAI,wBAAU,CAAC,wBAAwB,IAAI,wBAAU,CAAC,eAAe,CAAC,KAAK,CAAC,EAAE,CAAC;IACnI,CAAC;CACJ;AAfD,gCAeC"}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import { PathLikeOrReadStream } from '../../common';
|
|
3
|
+
import { ImageProperties } from '../interfaces/screenshot.types';
|
|
4
|
+
import { Screenshot } from './screenshot';
|
|
5
|
+
import { EmulatedMediaType } from '../interfaces/common.types';
|
|
6
|
+
/**
|
|
7
|
+
* Class representing a URL screenshot that extends the base screenshot class.
|
|
8
|
+
* This class is used to screenshot a URL using Gotenberg service.
|
|
9
|
+
*
|
|
10
|
+
* @extends Screenshot
|
|
11
|
+
*/
|
|
12
|
+
export declare class UrlScreenshot extends Screenshot {
|
|
13
|
+
/**
|
|
14
|
+
* Creates an instance of UrlScreenshot.
|
|
15
|
+
* Initializes the screenshot with the URL screenshot route.
|
|
16
|
+
*/
|
|
17
|
+
constructor();
|
|
18
|
+
/**
|
|
19
|
+
* Screenshots URL.
|
|
20
|
+
*
|
|
21
|
+
* @param {Object} options - Screenshot options.
|
|
22
|
+
* @param {string} options.url - The URL of the content to be screenshoted
|
|
23
|
+
* @param {PathLikeOrReadStream} [options.header] - PathLike or ReadStream of the header HTML content.
|
|
24
|
+
* @param {PathLikeOrReadStream} [options.footer] - PathLike or ReadStream of the footer HTML content.
|
|
25
|
+
* @param {ImageProperties} [options.properties] - Image properties for the screenshot.
|
|
26
|
+
* @param {EmulatedMediaType} [options.emulatedMediaType] - Emulated media type for the screenshot.
|
|
27
|
+
* @param {string} [options.waitDelay] - Delay before the screenshot process starts.
|
|
28
|
+
* @param {string} [options.waitForExpression] - JavaScript expression to wait for before completing the screenshot.
|
|
29
|
+
* @param {Record<string, string>} [options.extraHttpHeaders] - Additional HTTP headers for the screenshot.
|
|
30
|
+
* @param {number []} [options.failOnHttpStatusCodes] - Whether to fail on HTTP status code.
|
|
31
|
+
* @param {boolean} [options.failOnConsoleExceptions] - Whether to fail on console exceptions during screenshot.
|
|
32
|
+
* @param {boolean} [options.skipNetworkIdleEvent] - Whether to skip network idle event.
|
|
33
|
+
* @param {boolean} [options.optimizeForSpeed] - Whether to optimize for speed.
|
|
34
|
+
* @returns {Promise<Buffer>} A Promise resolving to the image buffer.
|
|
35
|
+
*/
|
|
36
|
+
capture({ url, header, footer, properties, emulatedMediaType, waitDelay, waitForExpression, extraHttpHeaders, failOnHttpStatusCodes, failOnConsoleExceptions, skipNetworkIdleEvent, optimizeForSpeed }: {
|
|
37
|
+
url: string;
|
|
38
|
+
header?: PathLikeOrReadStream;
|
|
39
|
+
footer?: PathLikeOrReadStream;
|
|
40
|
+
properties?: ImageProperties;
|
|
41
|
+
emulatedMediaType?: EmulatedMediaType;
|
|
42
|
+
waitDelay?: string;
|
|
43
|
+
waitForExpression?: string;
|
|
44
|
+
extraHttpHeaders?: Record<string, string>;
|
|
45
|
+
failOnHttpStatusCodes?: number[];
|
|
46
|
+
failOnConsoleExceptions?: boolean;
|
|
47
|
+
skipNetworkIdleEvent?: boolean;
|
|
48
|
+
optimizeForSpeed?: boolean;
|
|
49
|
+
}): Promise<Buffer>;
|
|
50
|
+
}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.UrlScreenshot = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const url_1 = require("url");
|
|
6
|
+
const form_data_1 = tslib_1.__importDefault(require("form-data"));
|
|
7
|
+
const common_1 = require("../../common");
|
|
8
|
+
const screenshot_utils_1 = require("../utils/screenshot.utils");
|
|
9
|
+
const screenshot_1 = require("./screenshot");
|
|
10
|
+
const main_config_1 = require("../../main.config");
|
|
11
|
+
/**
|
|
12
|
+
* Class representing a URL screenshot that extends the base screenshot class.
|
|
13
|
+
* This class is used to screenshot a URL using Gotenberg service.
|
|
14
|
+
*
|
|
15
|
+
* @extends Screenshot
|
|
16
|
+
*/
|
|
17
|
+
class UrlScreenshot extends screenshot_1.Screenshot {
|
|
18
|
+
/**
|
|
19
|
+
* Creates an instance of UrlScreenshot.
|
|
20
|
+
* Initializes the screenshot with the URL screenshot route.
|
|
21
|
+
*/
|
|
22
|
+
constructor() {
|
|
23
|
+
super(main_config_1.ChromiumRoute.URL);
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Screenshots URL.
|
|
27
|
+
*
|
|
28
|
+
* @param {Object} options - Screenshot options.
|
|
29
|
+
* @param {string} options.url - The URL of the content to be screenshoted
|
|
30
|
+
* @param {PathLikeOrReadStream} [options.header] - PathLike or ReadStream of the header HTML content.
|
|
31
|
+
* @param {PathLikeOrReadStream} [options.footer] - PathLike or ReadStream of the footer HTML content.
|
|
32
|
+
* @param {ImageProperties} [options.properties] - Image properties for the screenshot.
|
|
33
|
+
* @param {EmulatedMediaType} [options.emulatedMediaType] - Emulated media type for the screenshot.
|
|
34
|
+
* @param {string} [options.waitDelay] - Delay before the screenshot process starts.
|
|
35
|
+
* @param {string} [options.waitForExpression] - JavaScript expression to wait for before completing the screenshot.
|
|
36
|
+
* @param {Record<string, string>} [options.extraHttpHeaders] - Additional HTTP headers for the screenshot.
|
|
37
|
+
* @param {number []} [options.failOnHttpStatusCodes] - Whether to fail on HTTP status code.
|
|
38
|
+
* @param {boolean} [options.failOnConsoleExceptions] - Whether to fail on console exceptions during screenshot.
|
|
39
|
+
* @param {boolean} [options.skipNetworkIdleEvent] - Whether to skip network idle event.
|
|
40
|
+
* @param {boolean} [options.optimizeForSpeed] - Whether to optimize for speed.
|
|
41
|
+
* @returns {Promise<Buffer>} A Promise resolving to the image buffer.
|
|
42
|
+
*/
|
|
43
|
+
capture({ url, header, footer, properties, emulatedMediaType, waitDelay, waitForExpression, extraHttpHeaders, failOnHttpStatusCodes, failOnConsoleExceptions, skipNetworkIdleEvent, optimizeForSpeed }) {
|
|
44
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
45
|
+
const _url = new url_1.URL(url);
|
|
46
|
+
const data = new form_data_1.default();
|
|
47
|
+
data.append('url', _url.href);
|
|
48
|
+
yield screenshot_utils_1.ScreenshotUtils.customize(data, {
|
|
49
|
+
header,
|
|
50
|
+
footer,
|
|
51
|
+
properties,
|
|
52
|
+
emulatedMediaType,
|
|
53
|
+
waitDelay,
|
|
54
|
+
waitForExpression,
|
|
55
|
+
extraHttpHeaders,
|
|
56
|
+
failOnHttpStatusCodes,
|
|
57
|
+
failOnConsoleExceptions,
|
|
58
|
+
skipNetworkIdleEvent,
|
|
59
|
+
optimizeForSpeed
|
|
60
|
+
});
|
|
61
|
+
return common_1.GotenbergUtils.fetch(this.endpoint, data);
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
exports.UrlScreenshot = UrlScreenshot;
|
|
66
|
+
//# sourceMappingURL=url.screenshot.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"url.screenshot.js","sourceRoot":"","sources":["../../../src/chromium/screenshots/url.screenshot.ts"],"names":[],"mappings":";;;;AAAA,6BAA0B;AAC1B,kEAAiC;AACjC,yCAAoE;AAEpE,gEAA4D;AAC5D,6CAA0C;AAC1C,mDAAkD;AAGlD;;;;;GAKG;AACH,MAAa,aAAc,SAAQ,uBAAU;IACzC;;;OAGG;IACH;QACI,KAAK,CAAC,2BAAa,CAAC,GAAG,CAAC,CAAC;IAC7B,CAAC;IAED;;;;;;;;;;;;;;;;;OAiBG;IACG,OAAO,CAAC,EACV,GAAG,EACH,MAAM,EACN,MAAM,EACN,UAAU,EACV,iBAAiB,EACjB,SAAS,EACT,iBAAiB,EACjB,gBAAgB,EAChB,qBAAqB,EACrB,uBAAuB,EACvB,oBAAoB,EACpB,gBAAgB,EAcnB;;YACG,MAAM,IAAI,GAAG,IAAI,SAAG,CAAC,GAAG,CAAC,CAAC;YAC1B,MAAM,IAAI,GAAG,IAAI,mBAAQ,EAAE,CAAC;YAE5B,IAAI,CAAC,MAAM,CAAC,KAAK,EAAE,IAAI,CAAC,IAAI,CAAC,CAAC;YAE9B,MAAM,kCAAe,CAAC,SAAS,CAAC,IAAI,EAAE;gBAClC,MAAM;gBACN,MAAM;gBACN,UAAU;gBACV,iBAAiB;gBACjB,SAAS;gBACT,iBAAiB;gBACjB,gBAAgB;gBAChB,qBAAqB;gBACrB,uBAAuB;gBACvB,oBAAoB;gBACpB,gBAAgB;aACnB,CAAC,CAAC;YAEH,OAAO,uBAAc,CAAC,KAAK,CAAC,IAAI,CAAC,QAAQ,EAAE,IAAI,CAAC,CAAC;QACrD,CAAC;KAAA;CACJ;AA3ED,sCA2EC"}
|
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import FormData from
|
|
2
|
-
import { ConversionOptions, PageProperties } from
|
|
3
|
-
import { PathLikeOrReadStream } from "../../common";
|
|
1
|
+
import FormData from 'form-data';
|
|
2
|
+
import { ConversionOptions, PageProperties } from '../interfaces/converter.types';
|
|
4
3
|
/**
|
|
5
4
|
* Utility class for handling common tasks related to conversion.
|
|
6
5
|
*/
|
|
@@ -12,15 +11,6 @@ export declare class ConverterUtils {
|
|
|
12
11
|
* @param {PageProperties} pageProperties - The page properties to be added to the FormData.
|
|
13
12
|
*/
|
|
14
13
|
static addPageProperties(data: FormData, pageProperties: PageProperties): void;
|
|
15
|
-
/**
|
|
16
|
-
* Adds a file to the FormData object.
|
|
17
|
-
*
|
|
18
|
-
* @param {FormData} data - The FormData object to which the file will be added.
|
|
19
|
-
* @param {PathLikeOrReadStream} file - The file to be added (either a PathLike or a ReadStream).
|
|
20
|
-
* @param {string} name - The name to be used for the file in the FormData.
|
|
21
|
-
* @returns {Promise<void>} A Promise that resolves once the file has been added.
|
|
22
|
-
*/
|
|
23
|
-
static addFile(data: FormData, file: PathLikeOrReadStream, name: string): Promise<void>;
|
|
24
14
|
/**
|
|
25
15
|
* Customizes the FormData object based on the provided conversion options.
|
|
26
16
|
*
|
|
@@ -2,9 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.ConverterUtils = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
|
-
const fs_1 = require("fs");
|
|
6
5
|
const common_1 = require("../../common");
|
|
7
|
-
const fs_2 = require("fs");
|
|
8
6
|
/**
|
|
9
7
|
* Utility class for handling common tasks related to conversion.
|
|
10
8
|
*/
|
|
@@ -16,67 +14,49 @@ class ConverterUtils {
|
|
|
16
14
|
* @param {PageProperties} pageProperties - The page properties to be added to the FormData.
|
|
17
15
|
*/
|
|
18
16
|
static addPageProperties(data, pageProperties) {
|
|
17
|
+
if (pageProperties.singlePage) {
|
|
18
|
+
data.append('singlePage', String(pageProperties.singlePage));
|
|
19
|
+
}
|
|
19
20
|
if (pageProperties.size) {
|
|
20
|
-
common_1.GotenbergUtils.assert(pageProperties.size.width >= 1.0 &&
|
|
21
|
-
|
|
22
|
-
data.append(
|
|
21
|
+
common_1.GotenbergUtils.assert(pageProperties.size.width >= 1.0 &&
|
|
22
|
+
pageProperties.size.height >= 1.5, 'size is smaller than the minimum printing requirements (i.e. 1.0 x 1.5 in)');
|
|
23
|
+
data.append('paperWidth', pageProperties.size.width);
|
|
24
|
+
data.append('paperHeight', pageProperties.size.height);
|
|
23
25
|
}
|
|
24
26
|
if (pageProperties.margins) {
|
|
25
27
|
common_1.GotenbergUtils.assert(pageProperties.margins.top >= 0 &&
|
|
26
28
|
pageProperties.margins.bottom >= 0 &&
|
|
27
29
|
pageProperties.margins.left >= 0 &&
|
|
28
|
-
pageProperties.margins.left >= 0,
|
|
29
|
-
data.append(
|
|
30
|
-
data.append(
|
|
31
|
-
data.append(
|
|
32
|
-
data.append(
|
|
30
|
+
pageProperties.margins.left >= 0, 'negative margins are not allowed');
|
|
31
|
+
data.append('marginTop', pageProperties.margins.top);
|
|
32
|
+
data.append('marginBottom', pageProperties.margins.bottom);
|
|
33
|
+
data.append('marginLeft', pageProperties.margins.left);
|
|
34
|
+
data.append('marginRight', pageProperties.margins.right);
|
|
33
35
|
}
|
|
34
36
|
if (pageProperties.preferCssPageSize) {
|
|
35
|
-
data.append(
|
|
37
|
+
data.append('preferCssPageSize', String(pageProperties.preferCssPageSize));
|
|
36
38
|
}
|
|
37
39
|
if (pageProperties.printBackground) {
|
|
38
|
-
data.append(
|
|
40
|
+
data.append('printBackground', String(pageProperties.printBackground));
|
|
39
41
|
}
|
|
40
42
|
if (pageProperties.omitBackground) {
|
|
41
|
-
data.append(
|
|
43
|
+
data.append('omitBackground', String(pageProperties.omitBackground));
|
|
42
44
|
}
|
|
43
45
|
if (pageProperties.landscape) {
|
|
44
|
-
data.append(
|
|
46
|
+
data.append('landscape', String(pageProperties.landscape));
|
|
45
47
|
}
|
|
46
48
|
if (pageProperties.scale) {
|
|
47
|
-
common_1.GotenbergUtils.assert(pageProperties.scale >= 0.1 && pageProperties.scale <= 2.0,
|
|
48
|
-
data.append(
|
|
49
|
+
common_1.GotenbergUtils.assert(pageProperties.scale >= 0.1 && pageProperties.scale <= 2.0, 'scale is outside of [0.1 - 2] range');
|
|
50
|
+
data.append('scale', pageProperties.scale);
|
|
49
51
|
}
|
|
50
52
|
if (pageProperties.nativePageRanges) {
|
|
51
53
|
common_1.GotenbergUtils.assert(pageProperties.nativePageRanges.from > 0 &&
|
|
52
54
|
pageProperties.nativePageRanges.to > 0 &&
|
|
53
55
|
pageProperties.nativePageRanges.to >=
|
|
54
|
-
pageProperties.nativePageRanges.from,
|
|
55
|
-
data.append(
|
|
56
|
+
pageProperties.nativePageRanges.from, 'page ranges syntax error');
|
|
57
|
+
data.append('nativePageRanges', `${pageProperties.nativePageRanges.from}-${pageProperties.nativePageRanges.to}`);
|
|
56
58
|
}
|
|
57
59
|
}
|
|
58
|
-
/**
|
|
59
|
-
* Adds a file to the FormData object.
|
|
60
|
-
*
|
|
61
|
-
* @param {FormData} data - The FormData object to which the file will be added.
|
|
62
|
-
* @param {PathLikeOrReadStream} file - The file to be added (either a PathLike or a ReadStream).
|
|
63
|
-
* @param {string} name - The name to be used for the file in the FormData.
|
|
64
|
-
* @returns {Promise<void>} A Promise that resolves once the file has been added.
|
|
65
|
-
*/
|
|
66
|
-
static addFile(data, file, name) {
|
|
67
|
-
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
68
|
-
if (Buffer.isBuffer(file)) {
|
|
69
|
-
data.append("files", file, name);
|
|
70
|
-
}
|
|
71
|
-
else if (file instanceof fs_2.ReadStream) {
|
|
72
|
-
data.append("files", file, name);
|
|
73
|
-
}
|
|
74
|
-
else {
|
|
75
|
-
yield fs_1.promises.access(file, fs_1.constants.R_OK);
|
|
76
|
-
data.append("files", (0, fs_1.createReadStream)(file), name);
|
|
77
|
-
}
|
|
78
|
-
});
|
|
79
|
-
}
|
|
80
60
|
/**
|
|
81
61
|
* Customizes the FormData object based on the provided conversion options.
|
|
82
62
|
*
|
|
@@ -87,39 +67,45 @@ class ConverterUtils {
|
|
|
87
67
|
static customize(data, options) {
|
|
88
68
|
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
89
69
|
if (options.pdfFormat) {
|
|
90
|
-
data.append(
|
|
70
|
+
data.append('pdfa', options.pdfFormat);
|
|
91
71
|
}
|
|
92
72
|
if (options.pdfUA) {
|
|
93
|
-
data.append(
|
|
73
|
+
data.append('pdfua', String(options.pdfUA));
|
|
94
74
|
}
|
|
95
75
|
if (options.header) {
|
|
96
76
|
const { header } = options;
|
|
97
|
-
yield
|
|
77
|
+
yield common_1.GotenbergUtils.addFile(data, header, 'header.html');
|
|
98
78
|
}
|
|
99
79
|
if (options.footer) {
|
|
100
80
|
const { footer } = options;
|
|
101
|
-
yield
|
|
81
|
+
yield common_1.GotenbergUtils.addFile(data, footer, 'footer.html');
|
|
102
82
|
}
|
|
103
83
|
if (options.emulatedMediaType) {
|
|
104
|
-
data.append(
|
|
84
|
+
data.append('emulatedMediaType', options.emulatedMediaType);
|
|
105
85
|
}
|
|
106
86
|
if (options.properties) {
|
|
107
87
|
ConverterUtils.addPageProperties(data, options.properties);
|
|
108
88
|
}
|
|
109
89
|
if (options.waitDelay) {
|
|
110
|
-
data.append(
|
|
90
|
+
data.append('waitDelay', options.waitDelay);
|
|
111
91
|
}
|
|
112
92
|
if (options.waitForExpression) {
|
|
113
|
-
data.append(
|
|
93
|
+
data.append('waitForExpression', options.waitForExpression);
|
|
114
94
|
}
|
|
115
95
|
if (options.userAgent) {
|
|
116
|
-
data.append(
|
|
96
|
+
data.append('userAgent', options.userAgent);
|
|
117
97
|
}
|
|
118
98
|
if (options.extraHttpHeaders) {
|
|
119
|
-
data.append(
|
|
99
|
+
data.append('extraHttpHeaders', JSON.stringify(options.extraHttpHeaders));
|
|
100
|
+
}
|
|
101
|
+
if (options.failOnHttpStatusCodes) {
|
|
102
|
+
data.append('failOnHttpStatusCodes', JSON.stringify(options.failOnHttpStatusCodes));
|
|
120
103
|
}
|
|
121
104
|
if (options.failOnConsoleExceptions) {
|
|
122
|
-
data.append(
|
|
105
|
+
data.append('failOnConsoleExceptions', String(options.failOnConsoleExceptions));
|
|
106
|
+
}
|
|
107
|
+
if (options.skipNetworkIdleEvent) {
|
|
108
|
+
data.append('skipNetworkIdleEvent', String(options.skipNetworkIdleEvent));
|
|
123
109
|
}
|
|
124
110
|
});
|
|
125
111
|
}
|