chromiumly 1.0.4 → 2.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/README.md +62 -18
- package/dist/chromium/converters/converter.d.ts +5 -0
- package/dist/chromium/converters/converter.js +11 -0
- package/dist/chromium/converters/converter.js.map +1 -0
- package/dist/chromium/converters/html.converter.d.ts +14 -0
- package/dist/chromium/converters/html.converter.js +36 -0
- package/dist/chromium/converters/html.converter.js.map +1 -0
- package/dist/chromium/converters/markdown.converter.d.ts +15 -0
- package/dist/chromium/converters/markdown.converter.js +38 -0
- package/dist/chromium/converters/markdown.converter.js.map +1 -0
- package/dist/chromium/converters/url.converter.d.ts +13 -0
- package/dist/{converters → chromium/converters}/url.converter.js +10 -6
- package/dist/chromium/converters/url.converter.js.map +1 -0
- package/dist/chromium/index.d.ts +3 -0
- package/dist/chromium/index.js +10 -0
- package/dist/chromium/index.js.map +1 -0
- package/dist/{common → chromium/interfaces}/converter.interface.d.ts +2 -1
- package/dist/{common → chromium/interfaces}/converter.interface.js +0 -0
- package/dist/chromium/interfaces/converter.interface.js.map +1 -0
- package/dist/{common → chromium/interfaces}/converter.types.d.ts +0 -0
- package/dist/{common → chromium/interfaces}/converter.types.js +0 -0
- package/dist/chromium/interfaces/converter.types.js.map +1 -0
- package/dist/chromium/utils/converter.utils.d.ts +5 -0
- package/dist/chromium/utils/converter.utils.js +45 -0
- package/dist/chromium/utils/converter.utils.js.map +1 -0
- package/dist/common/constants.d.ts +5 -0
- package/dist/common/constants.js +10 -0
- package/dist/common/constants.js.map +1 -0
- package/dist/common/gotenberg.utils.d.ts +6 -0
- package/dist/common/gotenberg.utils.js +27 -0
- package/dist/common/gotenberg.utils.js.map +1 -0
- package/dist/common/index.d.ts +2 -0
- package/dist/common/index.js +8 -0
- package/dist/common/index.js.map +1 -0
- package/dist/libre-office/index.d.ts +2 -0
- package/dist/libre-office/index.js +6 -0
- package/dist/libre-office/index.js.map +1 -0
- package/dist/libre-office/interfaces/libre-office.types.d.ts +7 -0
- package/dist/libre-office/interfaces/libre-office.types.js +3 -0
- package/dist/libre-office/interfaces/libre-office.types.js.map +1 -0
- package/dist/libre-office/utils/constants.d.ts +1 -0
- package/dist/libre-office/utils/constants.js +82 -0
- package/dist/libre-office/utils/constants.js.map +1 -0
- package/dist/libre-office/utils/libre-office.utils.d.ts +8 -0
- package/dist/libre-office/utils/libre-office.utils.js +44 -0
- package/dist/libre-office/utils/libre-office.utils.js.map +1 -0
- package/dist/main.config.d.ts +22 -10
- package/dist/main.config.js +28 -15
- package/dist/main.config.js.map +1 -1
- package/dist/main.d.ts +3 -3
- package/dist/main.js +9 -7
- package/dist/main.js.map +1 -1
- package/dist/pdf-engines/index.d.ts +1 -0
- package/dist/pdf-engines/index.js +6 -0
- package/dist/pdf-engines/index.js.map +1 -0
- package/dist/pdf-engines/pdf.engine.d.ts +16 -0
- package/dist/pdf-engines/pdf.engine.js +47 -0
- package/dist/pdf-engines/pdf.engine.js.map +1 -0
- package/dist/pdf-engines/utils/engine.utils.d.ts +6 -0
- package/dist/pdf-engines/utils/engine.utils.js +30 -0
- package/dist/pdf-engines/utils/engine.utils.js.map +1 -0
- package/package.json +10 -3
- package/src/chromium/converters/converter.ts +9 -0
- package/src/chromium/converters/html.converter.ts +41 -0
- package/src/chromium/converters/markdown.converter.ts +45 -0
- package/src/chromium/converters/tests/html.converter.test.ts +95 -0
- package/src/chromium/converters/tests/markdown.converter.test.ts +105 -0
- package/src/chromium/converters/tests/url.converter.test.ts +82 -0
- package/src/{converters → chromium/converters}/url.converter.ts +13 -7
- package/src/chromium/index.ts +3 -0
- package/src/{common → chromium/interfaces}/converter.interface.ts +2 -1
- package/src/{common → chromium/interfaces}/converter.types.ts +0 -0
- package/src/chromium/utils/converter.utils.ts +75 -0
- package/src/chromium/utils/tests/converter.utils.test.ts +101 -0
- package/src/common/constants.ts +5 -0
- package/src/common/gotenberg.utils.ts +25 -0
- package/src/common/index.ts +2 -0
- package/src/common/tests/gotenberg.utils.test.ts +71 -0
- package/src/libre-office/index.ts +2 -0
- package/src/libre-office/interfaces/libre-office.types.ts +4 -0
- package/src/libre-office/utils/constants.ts +78 -0
- package/src/libre-office/utils/libre-office.utils.ts +51 -0
- package/src/libre-office/utils/test/libre-office.utils.test.ts +85 -0
- package/src/main.config.ts +23 -10
- package/src/main.ts +3 -3
- package/src/pdf-engines/index.ts +1 -0
- package/src/pdf-engines/pdf.engine.ts +53 -0
- package/src/pdf-engines/tests/pdf.engine.test.ts +84 -0
- package/src/pdf-engines/utils/engine.utils.ts +23 -0
- package/src/pdf-engines/utils/tests/engine.utils.test.ts +59 -0
- package/dist/common/converter.d.ts +0 -7
- package/dist/common/converter.interface.js.map +0 -1
- package/dist/common/converter.js +0 -21
- package/dist/common/converter.js.map +0 -1
- package/dist/common/converter.types.js.map +0 -1
- package/dist/common/converter.utils.d.ts +0 -8
- package/dist/common/converter.utils.js +0 -66
- package/dist/common/converter.utils.js.map +0 -1
- package/dist/converters/html.converter.d.ts +0 -12
- package/dist/converters/html.converter.js +0 -26
- package/dist/converters/html.converter.js.map +0 -1
- package/dist/converters/markdown.converter.d.ts +0 -13
- package/dist/converters/markdown.converter.js +0 -27
- package/dist/converters/markdown.converter.js.map +0 -1
- package/dist/converters/url.converter.d.ts +0 -11
- package/dist/converters/url.converter.js.map +0 -1
- package/src/common/converter.ts +0 -18
- package/src/common/converter.utils.ts +0 -101
- package/src/converters/html.converter.ts +0 -30
- package/src/converters/markdown.converter.ts +0 -33
|
@@ -1,101 +0,0 @@
|
|
|
1
|
-
import FormData from "form-data";
|
|
2
|
-
import fetch from "node-fetch";
|
|
3
|
-
|
|
4
|
-
import { PageProperties } from "./converter.types";
|
|
5
|
-
|
|
6
|
-
export class ConverterUtils {
|
|
7
|
-
private static assert(
|
|
8
|
-
condition: boolean,
|
|
9
|
-
message: string
|
|
10
|
-
): asserts condition {
|
|
11
|
-
if (!condition) {
|
|
12
|
-
throw new Error(message);
|
|
13
|
-
}
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
public static injectPageProperties(
|
|
17
|
-
data: FormData,
|
|
18
|
-
pageProperties: PageProperties
|
|
19
|
-
): void {
|
|
20
|
-
if (pageProperties) {
|
|
21
|
-
if (pageProperties.size) {
|
|
22
|
-
ConverterUtils.assert(
|
|
23
|
-
pageProperties.size.width >= 1.0 && pageProperties.size.height >= 1.5,
|
|
24
|
-
"size is smaller than the minimum printing requirements (i.e. 1.0 x 1.5 in)"
|
|
25
|
-
);
|
|
26
|
-
|
|
27
|
-
data.append("paperWidth", pageProperties.size.width);
|
|
28
|
-
data.append("paperHeight", pageProperties.size.height);
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
if (pageProperties.margins) {
|
|
32
|
-
ConverterUtils.assert(
|
|
33
|
-
pageProperties.margins.top >= 0 &&
|
|
34
|
-
pageProperties.margins.bottom >= 0 &&
|
|
35
|
-
pageProperties.margins.left >= 0 &&
|
|
36
|
-
pageProperties.margins.left >= 0,
|
|
37
|
-
"negative margins are not allowed"
|
|
38
|
-
);
|
|
39
|
-
|
|
40
|
-
data.append("marginTop", pageProperties.margins.top);
|
|
41
|
-
data.append("marginBottom", pageProperties.margins.bottom);
|
|
42
|
-
data.append("marginLeft", pageProperties.margins.left);
|
|
43
|
-
data.append("marginRight", pageProperties.margins.right);
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
if (pageProperties.preferCssPageSize) {
|
|
47
|
-
data.append(
|
|
48
|
-
"preferCssPageSize",
|
|
49
|
-
String(pageProperties.preferCssPageSize)
|
|
50
|
-
);
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
if (pageProperties.printBackground) {
|
|
54
|
-
data.append("printBackground", String(pageProperties.printBackground));
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
if (pageProperties.landscape) {
|
|
58
|
-
data.append("landscape", String(pageProperties.landscape));
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
if (pageProperties.scale) {
|
|
62
|
-
ConverterUtils.assert(
|
|
63
|
-
pageProperties.scale >= 0.1 && pageProperties.scale <= 2.0,
|
|
64
|
-
"scale is outside of [0.1 - 2] range"
|
|
65
|
-
);
|
|
66
|
-
|
|
67
|
-
data.append("scale", pageProperties.scale);
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
if (pageProperties.nativePageRanges) {
|
|
71
|
-
ConverterUtils.assert(
|
|
72
|
-
pageProperties.nativePageRanges.from > 0 &&
|
|
73
|
-
pageProperties.nativePageRanges.to > 0 &&
|
|
74
|
-
pageProperties.nativePageRanges.to >=
|
|
75
|
-
pageProperties.nativePageRanges.from,
|
|
76
|
-
"page ranges syntax error"
|
|
77
|
-
);
|
|
78
|
-
|
|
79
|
-
data.append(
|
|
80
|
-
"nativePageRanges",
|
|
81
|
-
`${pageProperties.nativePageRanges.from}-${pageProperties.nativePageRanges.to}`
|
|
82
|
-
);
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
static async fetch(endpoint: string, data: FormData): Promise<Buffer> {
|
|
88
|
-
const response = await fetch(endpoint, {
|
|
89
|
-
method: "post",
|
|
90
|
-
body: data,
|
|
91
|
-
headers: {
|
|
92
|
-
...data.getHeaders(),
|
|
93
|
-
},
|
|
94
|
-
});
|
|
95
|
-
|
|
96
|
-
if (!response.ok) {
|
|
97
|
-
throw new Error(`${response.status} ${response.statusText}`);
|
|
98
|
-
}
|
|
99
|
-
return response.buffer();
|
|
100
|
-
}
|
|
101
|
-
}
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
import { createReadStream, PathLike } from "fs";
|
|
2
|
-
|
|
3
|
-
import FormData from "form-data";
|
|
4
|
-
|
|
5
|
-
import { IConverter } from "../common/converter.interface";
|
|
6
|
-
import { PageProperties } from "../common/converter.types";
|
|
7
|
-
import { ConverterUtils } from "../common/converter.utils";
|
|
8
|
-
import { Converter } from "../common/converter";
|
|
9
|
-
import { Route } from "../main.config";
|
|
10
|
-
|
|
11
|
-
export class HtmlConverter extends Converter implements IConverter {
|
|
12
|
-
constructor() {
|
|
13
|
-
super(Route.HTML);
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
async convert({
|
|
17
|
-
html,
|
|
18
|
-
properties,
|
|
19
|
-
}: {
|
|
20
|
-
html: PathLike;
|
|
21
|
-
properties?: PageProperties;
|
|
22
|
-
}): Promise<Buffer> {
|
|
23
|
-
const data = new FormData();
|
|
24
|
-
data.append("index.html", createReadStream(html));
|
|
25
|
-
if (properties) {
|
|
26
|
-
ConverterUtils.injectPageProperties(data, properties);
|
|
27
|
-
}
|
|
28
|
-
return ConverterUtils.fetch(this.endpoint, data);
|
|
29
|
-
}
|
|
30
|
-
}
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
import { createReadStream, PathLike } from "fs";
|
|
2
|
-
|
|
3
|
-
import FormData from "form-data";
|
|
4
|
-
|
|
5
|
-
import { IConverter } from "../common/converter.interface";
|
|
6
|
-
import { PageProperties } from "../common/converter.types";
|
|
7
|
-
import { ConverterUtils } from "../common/converter.utils";
|
|
8
|
-
import { Converter } from "../common/converter";
|
|
9
|
-
import { Route } from "../main.config";
|
|
10
|
-
|
|
11
|
-
export class MarkdownConverter extends Converter implements IConverter {
|
|
12
|
-
constructor() {
|
|
13
|
-
super(Route.MARKDOWN);
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
async convert({
|
|
17
|
-
html,
|
|
18
|
-
markdown,
|
|
19
|
-
properties,
|
|
20
|
-
}: {
|
|
21
|
-
html: PathLike;
|
|
22
|
-
markdown: PathLike;
|
|
23
|
-
properties?: PageProperties;
|
|
24
|
-
}): Promise<Buffer> {
|
|
25
|
-
const data = new FormData();
|
|
26
|
-
data.append("index.html", createReadStream(html));
|
|
27
|
-
data.append("file.md", createReadStream(markdown));
|
|
28
|
-
if (properties) {
|
|
29
|
-
ConverterUtils.injectPageProperties(data, properties);
|
|
30
|
-
}
|
|
31
|
-
return ConverterUtils.fetch(this.endpoint, data);
|
|
32
|
-
}
|
|
33
|
-
}
|