chromiumly 2.5.0 → 2.5.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.
- package/README.md +57 -40
- package/dist/chromium/converters/converter.d.ts +13 -0
- package/dist/chromium/converters/converter.js +10 -0
- package/dist/chromium/converters/converter.js.map +1 -1
- package/dist/chromium/converters/html.converter.d.ts +28 -0
- package/dist/chromium/converters/html.converter.js +28 -1
- package/dist/chromium/converters/html.converter.js.map +1 -1
- package/dist/chromium/converters/markdown.converter.d.ts +29 -0
- package/dist/chromium/converters/markdown.converter.js +29 -0
- package/dist/chromium/converters/markdown.converter.js.map +1 -1
- package/dist/chromium/converters/url.converter.d.ts +28 -0
- package/dist/chromium/converters/url.converter.js +28 -0
- package/dist/chromium/converters/url.converter.js.map +1 -1
- package/dist/chromium/utils/converter.utils.d.ts +24 -0
- package/dist/chromium/utils/converter.utils.js +24 -0
- package/dist/chromium/utils/converter.utils.js.map +1 -1
- package/dist/common/gotenberg.utils.d.ts +18 -0
- package/dist/common/gotenberg.utils.js +18 -0
- package/dist/common/gotenberg.utils.js.map +1 -1
- package/dist/gotenberg.d.ts +8 -0
- package/dist/gotenberg.js +8 -0
- package/dist/gotenberg.js.map +1 -1
- package/dist/libre-office/utils/constants.js +76 -76
- package/dist/libre-office/utils/constants.js.map +1 -1
- package/dist/libre-office/utils/libre-office.utils.d.ts +16 -0
- package/dist/libre-office/utils/libre-office.utils.js +38 -15
- package/dist/libre-office/utils/libre-office.utils.js.map +1 -1
- package/dist/main.config.d.ts +43 -0
- package/dist/main.config.js +43 -0
- package/dist/main.config.js.map +1 -1
- package/dist/pdf-engines/pdf.engine.d.ts +31 -5
- package/dist/pdf-engines/pdf.engine.js +28 -0
- package/dist/pdf-engines/pdf.engine.js.map +1 -1
- package/dist/pdf-engines/utils/engine.utils.d.ts +10 -0
- package/dist/pdf-engines/utils/engine.utils.js +11 -1
- package/dist/pdf-engines/utils/engine.utils.js.map +1 -1
- package/package.json +2 -1
- package/src/chromium/converters/converter.ts +13 -0
- package/src/chromium/converters/html.converter.ts +30 -3
- package/src/chromium/converters/markdown.converter.ts +30 -1
- package/src/chromium/converters/url.converter.ts +29 -3
- package/src/chromium/utils/converter.utils.ts +24 -0
- package/src/chromium/utils/tests/converter.utils.test.ts +2 -2
- package/src/common/gotenberg.utils.ts +20 -1
- package/src/gotenberg.ts +9 -0
- package/src/libre-office/utils/constants.ts +76 -76
- package/src/libre-office/utils/libre-office.utils.ts +42 -14
- package/src/libre-office/utils/tests/libre-office.utils.test.ts +24 -4
- package/src/main.config.ts +46 -1
- package/src/pdf-engines/pdf.engine.ts +32 -4
- package/src/pdf-engines/utils/engine.utils.ts +11 -1
package/src/main.config.ts
CHANGED
|
@@ -1,37 +1,82 @@
|
|
|
1
1
|
import {Gotenberg} from "./gotenberg";
|
|
2
2
|
|
|
3
|
+
/**
|
|
4
|
+
* Enum representing the available Chromium routes for conversion.
|
|
5
|
+
* @enum {string}
|
|
6
|
+
*/
|
|
3
7
|
export enum ChromiumRoute {
|
|
4
8
|
URL = "url",
|
|
5
9
|
HTML = "html",
|
|
6
10
|
MARKDOWN = "markdown",
|
|
7
11
|
}
|
|
8
12
|
|
|
13
|
+
/**
|
|
14
|
+
* Enum representing the available routes for the PDF engine.
|
|
15
|
+
* @enum {string}
|
|
16
|
+
*/
|
|
9
17
|
enum PdfEngineRoute {
|
|
10
18
|
MERGE = "merge",
|
|
11
19
|
}
|
|
12
20
|
|
|
21
|
+
/**
|
|
22
|
+
* Enum representing the available routes for LibreOffice.
|
|
23
|
+
* @enum {string}
|
|
24
|
+
*/
|
|
13
25
|
enum LibreOfficeRoute {
|
|
14
26
|
CONVERT = "convert",
|
|
15
27
|
}
|
|
16
28
|
|
|
29
|
+
/**
|
|
30
|
+
* Class providing constants and routes for interacting with the Gotenberg service and related engines.
|
|
31
|
+
*/
|
|
17
32
|
export class Chromiumly {
|
|
33
|
+
/**
|
|
34
|
+
* The Gotenberg service endpoint.
|
|
35
|
+
* @type {string}
|
|
36
|
+
*/
|
|
18
37
|
public static readonly GOTENBERG_ENDPOINT = Gotenberg.endpoint;
|
|
19
38
|
|
|
39
|
+
/**
|
|
40
|
+
* The path for Chromium-related conversions.
|
|
41
|
+
* @type {string}
|
|
42
|
+
*/
|
|
20
43
|
public static readonly CHROMIUM_PATH = "forms/chromium/convert";
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* The path for PDF engine-related operations.
|
|
47
|
+
* @type {string}
|
|
48
|
+
*/
|
|
21
49
|
public static readonly PDF_ENGINES_PATH = "forms/pdfengines";
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* The path for LibreOffice-related conversions.
|
|
53
|
+
* @type {string}
|
|
54
|
+
*/
|
|
22
55
|
public static readonly LIBRE_OFFICE_PATH = "forms/libreoffice";
|
|
23
56
|
|
|
57
|
+
/**
|
|
58
|
+
* Routes for Chromium conversions.
|
|
59
|
+
* @type {Object}
|
|
60
|
+
*/
|
|
24
61
|
public static readonly CHROMIUM_ROUTES = {
|
|
25
62
|
url: ChromiumRoute.URL,
|
|
26
63
|
html: ChromiumRoute.HTML,
|
|
27
64
|
markdown: ChromiumRoute.MARKDOWN,
|
|
28
65
|
};
|
|
29
66
|
|
|
67
|
+
/**
|
|
68
|
+
* Routes for PDF engine operations.
|
|
69
|
+
* @type {Object}
|
|
70
|
+
*/
|
|
30
71
|
public static readonly PDF_ENGINE_ROUTES = {
|
|
31
72
|
merge: PdfEngineRoute.MERGE,
|
|
32
73
|
};
|
|
33
74
|
|
|
75
|
+
/**
|
|
76
|
+
* Routes for LibreOffice conversions.
|
|
77
|
+
* @type {Object}
|
|
78
|
+
*/
|
|
34
79
|
public static readonly LIBRE_OFFICE_ROUTES = {
|
|
35
80
|
convert: LibreOfficeRoute.CONVERT,
|
|
36
81
|
};
|
|
37
|
-
}
|
|
82
|
+
}
|
|
@@ -1,21 +1,42 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {promises} from "fs";
|
|
2
2
|
import path from "path";
|
|
3
3
|
|
|
4
4
|
import FormData from "form-data";
|
|
5
5
|
|
|
6
6
|
import {Chromiumly} from "../main.config";
|
|
7
|
-
import {GotenbergUtils, PdfFormat} from "../common";
|
|
7
|
+
import {GotenbergUtils, PathLikeOrReadStream, PdfFormat} from "../common";
|
|
8
8
|
import {LibreOfficeUtils, PageProperties} from "../libre-office";
|
|
9
9
|
import {PDFEngineUtils} from "./utils/engine.utils";
|
|
10
10
|
|
|
11
|
+
/**
|
|
12
|
+
* Class representing a PDF engine for various operations such as merging and conversion.
|
|
13
|
+
*/
|
|
11
14
|
export class PDFEngine {
|
|
12
|
-
|
|
15
|
+
/**
|
|
16
|
+
* Merges multiple PDF files into a single PDF document.
|
|
17
|
+
*
|
|
18
|
+
* @param {Object} options - Options for the merge operation.
|
|
19
|
+
* @param {PathLikeOrReadStream[]} options.files - An array of PathLikes or ReadStreams to the PDF files to be merged.
|
|
20
|
+
* @returns {Promise<Buffer>} A Promise resolving to the merged PDF content as a Buffer.
|
|
21
|
+
*/
|
|
22
|
+
public static async merge({files}: { files: PathLikeOrReadStream[] }): Promise<Buffer> {
|
|
13
23
|
const data = new FormData();
|
|
14
24
|
await PDFEngineUtils.addFiles(files, data);
|
|
15
25
|
const endpoint = `${Chromiumly.GOTENBERG_ENDPOINT}/${Chromiumly.PDF_ENGINES_PATH}/${Chromiumly.PDF_ENGINE_ROUTES.merge}`;
|
|
16
26
|
return GotenbergUtils.fetch(endpoint, data);
|
|
17
27
|
}
|
|
18
28
|
|
|
29
|
+
/**
|
|
30
|
+
* Converts various document formats to PDF.
|
|
31
|
+
*
|
|
32
|
+
* @param {Object} options - Options for the conversion operation.
|
|
33
|
+
* @param {PathLikeOrReadStream[]} options.files - An array of PathLikes or ReadStreams to the files to be converted to PDF.
|
|
34
|
+
* @param {PageProperties} [options.properties] - Page properties for the conversion.
|
|
35
|
+
* @param {PdfFormat} [options.pdfFormat] - PDF format options.
|
|
36
|
+
* @param {boolean} [options.pdfUA] - Indicates whether to generate PDF/UA compliant output.
|
|
37
|
+
* @param {boolean} [options.merge] - Indicates whether to merge the resulting PDFs.
|
|
38
|
+
* @returns {Promise<Buffer>} A Promise resolving to the converted PDF content as a Buffer.
|
|
39
|
+
*/
|
|
19
40
|
public static async convert({
|
|
20
41
|
files,
|
|
21
42
|
properties,
|
|
@@ -23,7 +44,7 @@ export class PDFEngine {
|
|
|
23
44
|
pdfUA,
|
|
24
45
|
merge,
|
|
25
46
|
}: {
|
|
26
|
-
files:
|
|
47
|
+
files: PathLikeOrReadStream[];
|
|
27
48
|
properties?: PageProperties;
|
|
28
49
|
pdfFormat?: PdfFormat;
|
|
29
50
|
pdfUA?: boolean;
|
|
@@ -54,6 +75,13 @@ export class PDFEngine {
|
|
|
54
75
|
return GotenbergUtils.fetch(endpoint, data);
|
|
55
76
|
}
|
|
56
77
|
|
|
78
|
+
/**
|
|
79
|
+
* Generates a PDF file from a buffer and saves it to the "__generated__" directory.
|
|
80
|
+
*
|
|
81
|
+
* @param {string} filename - The filename for the generated PDF.
|
|
82
|
+
* @param {Buffer} buffer - The PDF content as a Buffer.
|
|
83
|
+
* @returns {Promise<void>} A Promise that resolves once the file is generated and saved.
|
|
84
|
+
*/
|
|
57
85
|
public static async generate(
|
|
58
86
|
filename: string,
|
|
59
87
|
buffer: Buffer
|
|
@@ -4,10 +4,20 @@ import path from "path";
|
|
|
4
4
|
import FormData from "form-data";
|
|
5
5
|
import {PathLikeOrReadStream} from "../../common";
|
|
6
6
|
|
|
7
|
+
/**
|
|
8
|
+
* Utility class for handling common tasks related to PDF engine operations.
|
|
9
|
+
*/
|
|
7
10
|
export class PDFEngineUtils {
|
|
11
|
+
/**
|
|
12
|
+
* Adds PDF files to the FormData object.
|
|
13
|
+
*
|
|
14
|
+
* @param {PathLikeOrReadStream[]} files - An array of PDF files to be added to the FormData.
|
|
15
|
+
* @param {FormData} data - The FormData object to which PDF files will be added.
|
|
16
|
+
* @throws {Error} Throws an error if the file extension is not supported.
|
|
17
|
+
*/
|
|
8
18
|
public static async addFiles(files: PathLikeOrReadStream[], data: FormData) {
|
|
9
19
|
for (const [key, file] of files.entries()) {
|
|
10
|
-
const filename = `file${key}`
|
|
20
|
+
const filename = `file${key}.pdf`
|
|
11
21
|
if (Buffer.isBuffer(file)) {
|
|
12
22
|
data.append("files", file, filename);
|
|
13
23
|
} else if (file instanceof ReadStream) {
|