chromiumly 3.2.1 → 3.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (77) hide show
  1. package/README.md +21 -2
  2. package/dist/chromium/converters/converter.js +1 -1
  3. package/dist/chromium/converters/converter.js.map +1 -1
  4. package/dist/chromium/converters/html.converter.js +1 -1
  5. package/dist/chromium/converters/html.converter.js.map +1 -1
  6. package/dist/chromium/converters/markdown.converter.js +1 -1
  7. package/dist/chromium/converters/markdown.converter.js.map +1 -1
  8. package/dist/chromium/converters/url.converter.js +1 -1
  9. package/dist/chromium/converters/url.converter.js.map +1 -1
  10. package/dist/chromium/screenshots/html.screenshot.js +1 -1
  11. package/dist/chromium/screenshots/html.screenshot.js.map +1 -1
  12. package/dist/chromium/screenshots/markdown.screenshot.js +1 -1
  13. package/dist/chromium/screenshots/markdown.screenshot.js.map +1 -1
  14. package/dist/chromium/screenshots/screenshot.js +1 -1
  15. package/dist/chromium/screenshots/screenshot.js.map +1 -1
  16. package/dist/chromium/screenshots/url.screenshot.js +1 -1
  17. package/dist/chromium/screenshots/url.screenshot.js.map +1 -1
  18. package/dist/gotenberg.d.ts +1 -1
  19. package/dist/gotenberg.js +4 -2
  20. package/dist/gotenberg.js.map +1 -1
  21. package/dist/libre-office/libre-office.js +2 -2
  22. package/dist/libre-office/libre-office.js.map +1 -1
  23. package/dist/main.config.d.ts +30 -3
  24. package/dist/main.config.js +42 -3
  25. package/dist/main.config.js.map +1 -1
  26. package/dist/main.d.ts +1 -0
  27. package/dist/main.js +3 -1
  28. package/dist/main.js.map +1 -1
  29. package/dist/pdf-engines/pdf-engines.js +8 -8
  30. package/dist/pdf-engines/pdf-engines.js.map +1 -1
  31. package/dist/pdf-engines/utils/pdf-engines.utils.js +5 -5
  32. package/dist/pdf-engines/utils/pdf-engines.utils.js.map +1 -1
  33. package/package.json +16 -11
  34. package/src/.prettierrc.yml +0 -4
  35. package/src/chromium/converters/converter.ts +0 -22
  36. package/src/chromium/converters/html.converter.ts +0 -134
  37. package/src/chromium/converters/markdown.converter.ts +0 -129
  38. package/src/chromium/converters/tests/html.converter.test.ts +0 -190
  39. package/src/chromium/converters/tests/markdown.converter.test.ts +0 -187
  40. package/src/chromium/converters/tests/url.converter.test.ts +0 -164
  41. package/src/chromium/converters/url.converter.ts +0 -125
  42. package/src/chromium/index.ts +0 -6
  43. package/src/chromium/interfaces/common.types.ts +0 -15
  44. package/src/chromium/interfaces/converter.types.ts +0 -45
  45. package/src/chromium/interfaces/screenshot.types.ts +0 -15
  46. package/src/chromium/screenshots/html.screenshot.ts +0 -105
  47. package/src/chromium/screenshots/markdown.screenshot.ts +0 -100
  48. package/src/chromium/screenshots/screenshot.ts +0 -22
  49. package/src/chromium/screenshots/tests/html.screenshot.test.ts +0 -192
  50. package/src/chromium/screenshots/tests/markdown.screenshot.test.ts +0 -176
  51. package/src/chromium/screenshots/tests/url.screenshot.test.ts +0 -166
  52. package/src/chromium/screenshots/url.screenshot.ts +0 -96
  53. package/src/chromium/utils/converter.utils.ts +0 -187
  54. package/src/chromium/utils/screenshot.utils.ts +0 -127
  55. package/src/chromium/utils/tests/converter.utils.test.ts +0 -496
  56. package/src/chromium/utils/tests/screenshot.utils.test.ts +0 -338
  57. package/src/common/constants.ts +0 -9
  58. package/src/common/gotenberg.utils.ts +0 -86
  59. package/src/common/index.ts +0 -3
  60. package/src/common/tests/gotenberg.utils.test.ts +0 -141
  61. package/src/common/types.ts +0 -7
  62. package/src/gotenberg.ts +0 -54
  63. package/src/libre-office/index.ts +0 -1
  64. package/src/libre-office/interfaces/libre-office.types.ts +0 -156
  65. package/src/libre-office/libre-office.ts +0 -61
  66. package/src/libre-office/tests/libre-office.test.ts +0 -56
  67. package/src/libre-office/utils/constants.ts +0 -132
  68. package/src/libre-office/utils/libre-office.utils.ts +0 -128
  69. package/src/libre-office/utils/tests/libre-office.utils.test.ts +0 -156
  70. package/src/main.config.ts +0 -106
  71. package/src/main.ts +0 -11
  72. package/src/pdf-engines/index.ts +0 -1
  73. package/src/pdf-engines/interfaces/pdf-engines.types.ts +0 -10
  74. package/src/pdf-engines/pdf-engines.ts +0 -156
  75. package/src/pdf-engines/tests/pdf.engine.test.ts +0 -163
  76. package/src/pdf-engines/utils/pdf-engines.utils.ts +0 -68
  77. package/src/pdf-engines/utils/tests/pdf-engines.utils.test.ts +0 -71
@@ -1,164 +0,0 @@
1
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
2
- import { createReadStream } from 'fs';
3
- import FormData from 'form-data';
4
- import fetch from 'node-fetch';
5
-
6
- import { PdfFormat } from '../../../common';
7
- import { UrlConverter } from '../url.converter';
8
-
9
- const { Response } = jest.requireActual('node-fetch');
10
- jest.mock('node-fetch', () => jest.fn());
11
-
12
- describe('HtmlConverter', () => {
13
- const converter = new UrlConverter();
14
-
15
- describe('endpoint', () => {
16
- it('should route to Chromium HTML route', () => {
17
- expect(converter.endpoint).toEqual(
18
- 'http://localhost:3000/forms/chromium/convert/url'
19
- );
20
- });
21
- });
22
-
23
- describe('convert', () => {
24
- const mockFetch = fetch as jest.MockedFunction<typeof fetch>;
25
- const mockFormDataAppend = jest.spyOn(FormData.prototype, 'append');
26
-
27
- beforeEach(() => {
28
- (createReadStream as jest.Mock) = jest.fn();
29
- });
30
-
31
- afterEach(() => {
32
- jest.resetAllMocks();
33
- });
34
-
35
- describe('when URL is valid', () => {
36
- it('should return a buffer', async () => {
37
- mockFetch.mockResolvedValueOnce(new Response('content'));
38
- const buffer = await converter.convert({
39
- url: 'http://www.example.com/'
40
- });
41
- expect(buffer).toEqual(Buffer.from('content'));
42
- });
43
- });
44
-
45
- describe('when header parameter is passed', () => {
46
- it('should return a buffer', async () => {
47
- mockFetch.mockResolvedValueOnce(new Response('content'));
48
- const buffer = await converter.convert({
49
- url: 'http://www.example.com/',
50
- header: Buffer.from('header')
51
- });
52
- expect(mockFormDataAppend).toHaveBeenCalledTimes(2);
53
- expect(buffer).toEqual(Buffer.from('content'));
54
- });
55
- });
56
-
57
- describe('when footer parameter is passed', () => {
58
- it('should return a buffer', async () => {
59
- mockFetch.mockResolvedValueOnce(new Response('content'));
60
- const buffer = await converter.convert({
61
- url: 'http://www.example.com/',
62
- footer: Buffer.from('footer')
63
- });
64
- expect(mockFormDataAppend).toHaveBeenCalledTimes(2);
65
- expect(buffer).toEqual(Buffer.from('content'));
66
- });
67
- });
68
-
69
- describe('when pdf format parameter is passed', () => {
70
- it('should return a buffer', async () => {
71
- mockFetch.mockResolvedValueOnce(new Response('content'));
72
- const buffer = await converter.convert({
73
- url: 'http://www.example.com/',
74
- pdfFormat: PdfFormat.A_3b
75
- });
76
- expect(mockFormDataAppend).toHaveBeenCalledTimes(2);
77
- expect(buffer).toEqual(Buffer.from('content'));
78
- });
79
- });
80
-
81
- describe('when page properties parameter is passed', () => {
82
- it('should return a buffer', async () => {
83
- mockFetch.mockResolvedValueOnce(new Response('content'));
84
- const buffer = await converter.convert({
85
- url: 'http://www.example.com/',
86
- properties: { size: { width: 8.3, height: 11.7 } }
87
- });
88
- expect(mockFormDataAppend).toHaveBeenCalledTimes(3);
89
- expect(buffer).toEqual(Buffer.from('content'));
90
- });
91
- });
92
-
93
- describe('when emulatedMediaType parameter is passed', () => {
94
- it('should return a buffer', async () => {
95
- mockFetch.mockResolvedValue(new Response('content'));
96
- const buffer = await converter.convert({
97
- url: 'http://www.example.com/',
98
- emulatedMediaType: 'screen'
99
- });
100
- expect(mockFormDataAppend).toHaveBeenCalledTimes(2);
101
- expect(buffer).toEqual(Buffer.from('content'));
102
- });
103
- });
104
-
105
- describe('when failOnHttpStatusCodes parameter is passed', () => {
106
- it('should return a buffer', async () => {
107
- mockFetch.mockResolvedValue(new Response('content'));
108
- const buffer = await converter.convert({
109
- url: 'http://www.example.com/',
110
- failOnHttpStatusCodes: [499, 599]
111
- });
112
- expect(mockFormDataAppend).toHaveBeenCalledTimes(2);
113
- expect(buffer).toEqual(Buffer.from('content'));
114
- });
115
- });
116
-
117
- describe('when skipNetworkIdleEvent parameter is passed', () => {
118
- it('should return a buffer', async () => {
119
- mockFetch.mockResolvedValue(new Response('content'));
120
- const buffer = await converter.convert({
121
- url: 'http://www.example.com/',
122
- skipNetworkIdleEvent: true
123
- });
124
- expect(mockFormDataAppend).toHaveBeenCalledTimes(2);
125
- expect(buffer).toEqual(Buffer.from('content'));
126
- });
127
- });
128
-
129
- describe('when all parameters are passed', () => {
130
- it('should return a buffer', async () => {
131
- mockFetch.mockResolvedValue(new Response('content'));
132
- const buffer = await converter.convert({
133
- url: 'http://www.example.com/',
134
- header: Buffer.from('header'),
135
- footer: Buffer.from('footer'),
136
- pdfFormat: PdfFormat.A_1a,
137
- emulatedMediaType: 'screen',
138
- properties: { size: { width: 8.3, height: 11.7 } }
139
- });
140
- expect(mockFormDataAppend).toHaveBeenCalledTimes(7);
141
- expect(buffer).toEqual(Buffer.from('content'));
142
- });
143
- });
144
-
145
- describe('when URL is invalid', () => {
146
- it('should throw an error', async () => {
147
- await expect(() =>
148
- converter.convert({ url: 'invalid url' })
149
- ).rejects.toThrow('Invalid URL');
150
- });
151
- });
152
-
153
- describe('when fetch request fails', () => {
154
- it('should throw an error', async () => {
155
- const errorMessage =
156
- 'FetchError: request to http://localhost:3000/forms/chromium/convert/html failed';
157
- mockFetch.mockRejectedValueOnce(new Error(errorMessage));
158
- await expect(() =>
159
- converter.convert({ url: 'http://www.example.com/' })
160
- ).rejects.toThrow(errorMessage);
161
- });
162
- });
163
- });
164
- });
@@ -1,125 +0,0 @@
1
- import { URL } from 'url';
2
- import FormData from 'form-data';
3
- import {
4
- GotenbergUtils,
5
- PdfFormat,
6
- PathLikeOrReadStream,
7
- Metadata
8
- } from '../../common';
9
- import { Cookie, PageProperties } from '../interfaces/converter.types';
10
- import { ConverterUtils } from '../utils/converter.utils';
11
- import { Converter } from './converter';
12
- import { ChromiumRoute, Chromiumly } from '../../main.config';
13
- import { EmulatedMediaType } from '../interfaces/common.types';
14
-
15
- /**
16
- * Class representing a URL converter that extends the base Converter class.
17
- * This class is used to convert content from a URL to PDF using Gotenberg service.
18
- *
19
- * @extends Converter
20
- */
21
- export class UrlConverter extends Converter {
22
- /**
23
- * Creates an instance of UrlConverter.
24
- * Initializes the converter with the URL conversion route.
25
- */
26
- constructor() {
27
- super(ChromiumRoute.URL);
28
- }
29
-
30
- /**
31
- * Converts content from a URL to PDF.
32
- *
33
- * @param {Object} options - Conversion options.
34
- * @param {string} options.url - The URL of the content to be converted to PDF.
35
- * @param {PathLikeOrReadStream} [options.header] - PathLike or ReadStream of the header HTML content.
36
- * @param {PathLikeOrReadStream} [options.footer] - PathLike or ReadStream of the footer HTML content.
37
- * @param {PageProperties} [options.properties] - Page properties for the conversion.
38
- * @param {PdfFormat} [options.pdfFormat] - PDF format options.
39
- * @param {boolean} [options.pdfUA] - Indicates whether to generate PDF/UA compliant output.
40
- * @param {EmulatedMediaType} [options.emulatedMediaType] - Emulated media type for the conversion.
41
- * @param {string} [options.waitDelay] - Delay before the conversion process starts.
42
- * @param {string} [options.waitForExpression] - JavaScript expression to wait for before completing the conversion.
43
- * @param {string} [options.userAgent] - User agent string to use during the conversion.
44
- * @param {Record<string, string>} [options.extraHttpHeaders] - Additional HTTP headers for the conversion.
45
- * @param {number[]} [options.failOnHttpStatusCodes] - Whether to fail on HTTP status code.
46
- * @param {boolean} [options.failOnConsoleExceptions] - Whether to fail on console exceptions during conversion.
47
- * @param {boolean} [options.skipNetworkIdleEvent] - Whether to skip network idle event.
48
- * @param {Metadata} options.metadata - Metadata to be written.
49
- * @param {Cookie[]} options.cookies - Cookies to be written.
50
- * @returns {Promise<Buffer>} A Promise resolving to the converted PDF content as a Buffer.
51
- */
52
- async convert({
53
- url,
54
- header,
55
- footer,
56
- properties,
57
- pdfFormat,
58
- pdfUA,
59
- emulatedMediaType,
60
- waitDelay,
61
- waitForExpression,
62
- userAgent,
63
- extraHttpHeaders,
64
- failOnHttpStatusCodes,
65
- failOnConsoleExceptions,
66
- skipNetworkIdleEvent,
67
- metadata,
68
- cookies
69
- }: {
70
- url: string;
71
- header?: PathLikeOrReadStream;
72
- footer?: PathLikeOrReadStream;
73
- properties?: PageProperties;
74
- /**
75
- * @deprecated Starting from Gotenberg version 8.0.0, Chromium no longer provides support for pdfFormat.
76
- * @see {@link https://github.com/gotenberg/gotenberg/releases/tag/v8.0.0}
77
- */
78
- pdfFormat?: PdfFormat;
79
- pdfUA?: boolean;
80
- emulatedMediaType?: EmulatedMediaType;
81
- waitDelay?: string;
82
- waitForExpression?: string;
83
- /**
84
- * @deprecated Starting from Gotenberg version 8.0.0, Chromium no longer provides support for userAgent.
85
- * @see {@link https://github.com/gotenberg/gotenberg/releases/tag/v8.0.0}
86
- */
87
- userAgent?: string;
88
- extraHttpHeaders?: Record<string, string>;
89
- failOnHttpStatusCodes?: number[];
90
- failOnConsoleExceptions?: boolean;
91
- skipNetworkIdleEvent?: boolean;
92
- metadata?: Metadata;
93
- cookies?: Cookie[];
94
- }): Promise<Buffer> {
95
- const _url = new URL(url);
96
- const data = new FormData();
97
-
98
- data.append('url', _url.href);
99
-
100
- await ConverterUtils.customize(data, {
101
- header,
102
- footer,
103
- properties,
104
- pdfFormat,
105
- pdfUA,
106
- emulatedMediaType,
107
- waitDelay,
108
- waitForExpression,
109
- userAgent,
110
- extraHttpHeaders,
111
- failOnHttpStatusCodes,
112
- failOnConsoleExceptions,
113
- skipNetworkIdleEvent,
114
- metadata,
115
- cookies
116
- });
117
-
118
- return GotenbergUtils.fetch(
119
- this.endpoint,
120
- data,
121
- Chromiumly.GOTENBERG_API_BASIC_AUTH_USERNAME,
122
- Chromiumly.GOTENBERG_API_BASIC_AUTH_PASSWORD
123
- );
124
- }
125
- }
@@ -1,6 +0,0 @@
1
- export { UrlScreenshot } from './screenshots/url.screenshot';
2
- export { MarkdownScreenshot } from './screenshots/markdown.screenshot';
3
- export { HtmlScreenshot } from './screenshots/html.screenshot';
4
- export { HtmlConverter } from './converters/html.converter';
5
- export { MarkdownConverter } from './converters/markdown.converter';
6
- export { UrlConverter } from './converters/url.converter';
@@ -1,15 +0,0 @@
1
- import { PathLikeOrReadStream } from '../../common';
2
-
3
- export type EmulatedMediaType = 'screen' | 'print';
4
-
5
- export type ChromiumOptions = {
6
- header?: PathLikeOrReadStream;
7
- footer?: PathLikeOrReadStream;
8
- emulatedMediaType?: EmulatedMediaType;
9
- waitDelay?: string; // Duration (e.g, '5s') to wait when loading an HTML document before conversion.
10
- waitForExpression?: string; // JavaScript's expression to wait before converting an HTML document into PDF until it returns true.
11
- extraHttpHeaders?: Record<string, string>;
12
- failOnHttpStatusCodes?: number[]; // Return a 409 Conflict response if the HTTP status code is in the list (default [499,599])
13
- failOnConsoleExceptions?: boolean; // Return a 409 Conflict response if there are exceptions in the Chromium console (default false)
14
- skipNetworkIdleEvent?: boolean; // Do not wait for Chromium network to be idle (default false)
15
- };
@@ -1,45 +0,0 @@
1
- import { Metadata, PdfFormat } from '../../common';
2
- import { ChromiumOptions } from './common.types';
3
-
4
- type PageSize = {
5
- width: number; // Paper width, in inches (default 8.5)
6
- height: number; //Paper height, in inches (default 11)
7
- };
8
-
9
- type PageMargins = {
10
- top: number; // Top margin, in inches (default 0.39)
11
- bottom: number; // Bottom margin, in inches (default 0.39)
12
- left: number; // Left margin, in inches (default 0.39)
13
- right: number; // Right margin, in inches (default 0.39)
14
- };
15
-
16
- export type PageProperties = {
17
- singlePage?: boolean; // Print the entire content in one single page (default false)
18
- size?: PageSize;
19
- margins?: PageMargins;
20
- preferCssPageSize?: boolean; // Define whether to prefer page size as defined by CSS (default false)
21
- printBackground?: boolean; // Print the background graphics (default false)
22
- omitBackground?: boolean; // Hide the default white background and allow generating PDFs with transparency (default false)
23
- landscape?: boolean; // Set the paper orientation to landscape (default false)
24
- scale?: number; // The scale of the page rendering (default 1.0)
25
- nativePageRanges?: { from: number; to: number }; // Page ranges to print
26
- };
27
-
28
- export type Cookie = {
29
- name: string;
30
- value: string;
31
- domain: string;
32
- path?: string;
33
- secure?: boolean;
34
- httpOnly?: boolean;
35
- sameSite?: 'Strict' | 'Lax' | 'None';
36
- };
37
-
38
- export type ConversionOptions = ChromiumOptions & {
39
- properties?: PageProperties;
40
- pdfFormat?: PdfFormat;
41
- pdfUA?: boolean; // Enable PDF for Universal Access for optimal accessibility (default false)
42
- userAgent?: string;
43
- metadata?: Metadata;
44
- cookies?: Cookie[];
45
- };
@@ -1,15 +0,0 @@
1
- import { ChromiumOptions } from './common.types';
2
-
3
- export type ImageProperties = {
4
- format: 'png' | 'jpeg' | 'webp'; //The image compression format, either "png", "jpeg" or "webp".
5
- quality?: number; // The compression quality from range 0 to 100 (jpeg only).
6
- omitBackground?: boolean; // Hide the default white background and allow generating screenshots with transparency.
7
- width?: number; // The device screen width in pixels (default 800).
8
- height?: number; // The device screen height in pixels (default 600).
9
- clip?: boolean; // Define whether to clip the screenshot according to the device dimensions (default false).
10
- };
11
-
12
- export type ScreenshotOptions = ChromiumOptions & {
13
- properties?: ImageProperties;
14
- optimizeForSpeed?: boolean; // Define whether to optimize image encoding for speed, not for resulting size.
15
- };
@@ -1,105 +0,0 @@
1
- import FormData from 'form-data';
2
-
3
- import { GotenbergUtils, PathLikeOrReadStream } from '../../common';
4
- import { ChromiumRoute, Chromiumly } from '../../main.config';
5
- import { EmulatedMediaType } from '../interfaces/common.types';
6
- import { ScreenshotUtils } from '../utils/screenshot.utils';
7
- import { Screenshot } from './screenshot';
8
- import { ImageProperties } from '../interfaces/screenshot.types';
9
-
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
- export class HtmlScreenshot extends Screenshot {
17
- /**
18
- * Creates an instance of HtmlScreenshot.
19
- * Initializes the Screenshot with the HTML screenshot route.
20
- */
21
- constructor() {
22
- super(ChromiumRoute.HTML);
23
- }
24
-
25
- /**
26
- * Screenshots HTML content.
27
- *
28
- * @param {Object} options - Screenshot options.
29
- * @param {PathLikeOrReadStream} options.html - PathLike or ReadStream of the HTML 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
- async capture({
44
- html,
45
- assets,
46
- header,
47
- footer,
48
- properties,
49
- emulatedMediaType,
50
- waitDelay,
51
- waitForExpression,
52
- extraHttpHeaders,
53
- failOnConsoleExceptions,
54
- failOnHttpStatusCodes,
55
- skipNetworkIdleEvent,
56
- optimizeForSpeed
57
- }: {
58
- html: PathLikeOrReadStream;
59
- assets?: { file: PathLikeOrReadStream; name: string }[];
60
- header?: PathLikeOrReadStream;
61
- footer?: PathLikeOrReadStream;
62
- properties?: ImageProperties;
63
- emulatedMediaType?: EmulatedMediaType;
64
- waitDelay?: string;
65
- waitForExpression?: string;
66
- extraHttpHeaders?: Record<string, string>;
67
- failOnConsoleExceptions?: boolean;
68
- failOnHttpStatusCodes?: number[];
69
- skipNetworkIdleEvent?: boolean;
70
- optimizeForSpeed?: boolean;
71
- }): Promise<Buffer> {
72
- const data = new FormData();
73
-
74
- await GotenbergUtils.addFile(data, html, 'index.html');
75
-
76
- if (assets?.length) {
77
- await Promise.all(
78
- assets.map(({ file, name }) =>
79
- GotenbergUtils.addFile(data, file, name)
80
- )
81
- );
82
- }
83
-
84
- await ScreenshotUtils.customize(data, {
85
- header,
86
- footer,
87
- properties,
88
- emulatedMediaType,
89
- waitDelay,
90
- waitForExpression,
91
- extraHttpHeaders,
92
- failOnHttpStatusCodes,
93
- failOnConsoleExceptions,
94
- skipNetworkIdleEvent,
95
- optimizeForSpeed
96
- });
97
-
98
- return GotenbergUtils.fetch(
99
- this.endpoint,
100
- data,
101
- Chromiumly.GOTENBERG_API_BASIC_AUTH_USERNAME,
102
- Chromiumly.GOTENBERG_API_BASIC_AUTH_PASSWORD
103
- );
104
- }
105
- }
@@ -1,100 +0,0 @@
1
- import FormData from 'form-data';
2
-
3
- import { GotenbergUtils, PathLikeOrReadStream } from '../../common';
4
- import { ImageProperties } from '../interfaces/screenshot.types';
5
- import { ScreenshotUtils } from '../utils/screenshot.utils';
6
- import { Screenshot } from './screenshot';
7
- import { ChromiumRoute, Chromiumly } from '../../main.config';
8
- import { EmulatedMediaType } from '../interfaces/common.types';
9
-
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
- export class MarkdownScreenshot extends Screenshot {
17
- /**
18
- * Creates an instance of MarkdownScreenshot.
19
- * Initializes the Screenshot with the Markdown screenshot route.
20
- */
21
- constructor() {
22
- super(ChromiumRoute.MARKDOWN);
23
- }
24
-
25
- /**
26
- * Screenshots HTML with markdown.
27
- *
28
- * @param {Object} options - Screenshot options.
29
- * @param {PathLikeOrReadStream} options.html - PathLike or ReadStream of the HTML content to be screenshoted.
30
- * @param {PathLikeOrReadStream} options.markdown - PathLike or ReadStream of the Markdown content to be screenshoted.
31
- * @param {PathLikeOrReadStream} [options.header] - PathLike or ReadStream of the header HTML content.
32
- * @param {PathLikeOrReadStream} [options.footer] - PathLike or ReadStream of the footer HTML content.
33
- * @param {ImageProperties} [options.properties] - Image properties for the screenshot.
34
- * @param {EmulatedMediaType} [options.emulatedMediaType] - Emulated media type for the screenshot.
35
- * @param {string} [options.waitDelay] - Delay before the screenshot process starts.
36
- * @param {string} [options.waitForExpression] - JavaScript expression to wait for before completing the screenshot.
37
- * @param {Record<string, string>} [options.extraHttpHeaders] - Additional HTTP headers for the screenshot.
38
- * @param {number []} [options.failOnHttpStatusCodes] - Whether to fail on HTTP status code.
39
- * @param {boolean} [options.failOnConsoleExceptions] - Whether to fail on console exceptions during screenshot.
40
- * @param {boolean} [options.skipNetworkIdleEvent] - Whether to skip network idle event.
41
- * @param {boolean} [options.optimizeForSpeed] - Whether to optimize for speed.
42
- * @returns {Promise<Buffer>} A Promise resolving to the image buffer.
43
- */
44
- async capture({
45
- html,
46
- markdown,
47
- header,
48
- footer,
49
- properties,
50
- emulatedMediaType,
51
- waitDelay,
52
- waitForExpression,
53
- extraHttpHeaders,
54
- failOnHttpStatusCodes,
55
- failOnConsoleExceptions,
56
- skipNetworkIdleEvent,
57
- optimizeForSpeed
58
- }: {
59
- html: PathLikeOrReadStream;
60
- markdown: PathLikeOrReadStream;
61
- header?: PathLikeOrReadStream;
62
- footer?: PathLikeOrReadStream;
63
- properties?: ImageProperties;
64
- emulatedMediaType?: EmulatedMediaType;
65
- waitDelay?: string;
66
- waitForExpression?: string;
67
- extraHttpHeaders?: Record<string, string>;
68
- failOnHttpStatusCodes?: number[];
69
- failOnConsoleExceptions?: boolean;
70
- skipNetworkIdleEvent?: boolean;
71
- optimizeForSpeed?: boolean;
72
- }): Promise<Buffer> {
73
- const data = new FormData();
74
-
75
- await GotenbergUtils.addFile(data, html, 'index.html');
76
-
77
- await GotenbergUtils.addFile(data, markdown, 'file.md');
78
-
79
- await ScreenshotUtils.customize(data, {
80
- header,
81
- footer,
82
- properties,
83
- emulatedMediaType,
84
- waitDelay,
85
- waitForExpression,
86
- extraHttpHeaders,
87
- failOnHttpStatusCodes,
88
- failOnConsoleExceptions,
89
- skipNetworkIdleEvent,
90
- optimizeForSpeed
91
- });
92
-
93
- return GotenbergUtils.fetch(
94
- this.endpoint,
95
- data,
96
- Chromiumly.GOTENBERG_API_BASIC_AUTH_USERNAME,
97
- Chromiumly.GOTENBERG_API_BASIC_AUTH_PASSWORD
98
- );
99
- }
100
- }
@@ -1,22 +0,0 @@
1
- import { Chromiumly, ChromiumRoute } from '../../main.config';
2
-
3
- /**
4
- * Abstract class representing a generic screenshot.
5
- * Concrete screenshot classes should extend this class and implement specific screenshot logic.
6
- */
7
- export abstract class Screenshot {
8
- /**
9
- * The endpoint URL for the screenshot.
10
- */
11
- readonly endpoint: string;
12
-
13
- /**
14
- * Creates an instance of the screenshot class.
15
- * Initializes the endpoint URL based on the provided ChromiumRoute.
16
- *
17
- * @param {ChromiumRoute} route - The ChromiumRoute enum value representing the screenshot route.
18
- */
19
- constructor(route: ChromiumRoute) {
20
- this.endpoint = `${Chromiumly.GOTENBERG_ENDPOINT}/${Chromiumly.CHROMIUM_SCREENSHOT_PATH}/${Chromiumly.CHROMIUM_ROUTES[route]}`;
21
- }
22
- }