chromiumly 1.0.3 → 2.0.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 +64 -20
- 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 +24 -0
- package/dist/pdf-engines/utils/engine.utils.js.map +1 -0
- package/package.json +3 -2
- 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/{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/common/constants.ts +5 -0
- package/src/common/gotenberg.utils.ts +25 -0
- package/src/common/index.ts +2 -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/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/utils/engine.utils.ts +18 -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/.DS_Store +0 -0
- 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
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
export const LIBRE_OFFICE_EXTENSIONS = [
|
|
2
|
+
".bib",
|
|
3
|
+
".doc",
|
|
4
|
+
".xml",
|
|
5
|
+
".docx",
|
|
6
|
+
".fodt",
|
|
7
|
+
".html",
|
|
8
|
+
".ltx",
|
|
9
|
+
".txt",
|
|
10
|
+
".odt",
|
|
11
|
+
".ott",
|
|
12
|
+
".pdb",
|
|
13
|
+
".pdf",
|
|
14
|
+
".psw",
|
|
15
|
+
".rtf",
|
|
16
|
+
".sdw",
|
|
17
|
+
".stw",
|
|
18
|
+
".sxw",
|
|
19
|
+
".uot",
|
|
20
|
+
".vor",
|
|
21
|
+
".wps",
|
|
22
|
+
".epub",
|
|
23
|
+
".png",
|
|
24
|
+
".bmp",
|
|
25
|
+
".emf",
|
|
26
|
+
".eps",
|
|
27
|
+
".fodg",
|
|
28
|
+
".gif",
|
|
29
|
+
".jpg",
|
|
30
|
+
".met",
|
|
31
|
+
".odd",
|
|
32
|
+
".otg",
|
|
33
|
+
".pbm",
|
|
34
|
+
".pct",
|
|
35
|
+
".pgm",
|
|
36
|
+
".ppm",
|
|
37
|
+
".ras",
|
|
38
|
+
".std",
|
|
39
|
+
".svg",
|
|
40
|
+
".svm",
|
|
41
|
+
".swf",
|
|
42
|
+
".sxd",
|
|
43
|
+
".sxw",
|
|
44
|
+
".tiff",
|
|
45
|
+
".xhtml",
|
|
46
|
+
".xpm",
|
|
47
|
+
".fodp",
|
|
48
|
+
".potm",
|
|
49
|
+
".pot",
|
|
50
|
+
".pptx",
|
|
51
|
+
".pps",
|
|
52
|
+
".ppt",
|
|
53
|
+
".pwp",
|
|
54
|
+
".sda",
|
|
55
|
+
".sdd",
|
|
56
|
+
".sti",
|
|
57
|
+
".sxi",
|
|
58
|
+
".uop",
|
|
59
|
+
".wmf",
|
|
60
|
+
".csv",
|
|
61
|
+
".dbf",
|
|
62
|
+
".dif",
|
|
63
|
+
".fods",
|
|
64
|
+
".ods",
|
|
65
|
+
".ots",
|
|
66
|
+
".pxl",
|
|
67
|
+
".sdc",
|
|
68
|
+
".slk",
|
|
69
|
+
".stc",
|
|
70
|
+
".sxc",
|
|
71
|
+
".uos",
|
|
72
|
+
".xls",
|
|
73
|
+
".xlt",
|
|
74
|
+
".xlsx",
|
|
75
|
+
".tif",
|
|
76
|
+
".jpeg",
|
|
77
|
+
".odp",
|
|
78
|
+
];
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { constants, createReadStream, PathLike, promises } from "fs";
|
|
2
|
+
import path from "path";
|
|
3
|
+
|
|
4
|
+
import FormData from "form-data";
|
|
5
|
+
|
|
6
|
+
import { GotenbergUtils } from "../../common";
|
|
7
|
+
import { LIBRE_OFFICE_EXTENSIONS } from "./constants";
|
|
8
|
+
import { PageProperties } from "../interfaces/libre-office.types";
|
|
9
|
+
|
|
10
|
+
export class LibreOfficeUtils {
|
|
11
|
+
public static async injectFiles(files: PathLike[], data: FormData) {
|
|
12
|
+
for (const file of files) {
|
|
13
|
+
try {
|
|
14
|
+
await promises.access(file, constants.R_OK);
|
|
15
|
+
const filename = path.basename(file.toString());
|
|
16
|
+
const extension = path.extname(filename);
|
|
17
|
+
if (LIBRE_OFFICE_EXTENSIONS.includes(extension)) {
|
|
18
|
+
data.append(filename, createReadStream(file));
|
|
19
|
+
} else {
|
|
20
|
+
throw new Error(`${extension} is not supported`);
|
|
21
|
+
}
|
|
22
|
+
} catch (error) {
|
|
23
|
+
throw error;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
public static injectPageProperties(
|
|
29
|
+
data: FormData,
|
|
30
|
+
pageProperties: PageProperties
|
|
31
|
+
): void {
|
|
32
|
+
if (pageProperties.landscape) {
|
|
33
|
+
data.append("landscape", String(pageProperties.landscape));
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
if (pageProperties.nativePageRanges) {
|
|
37
|
+
GotenbergUtils.assert(
|
|
38
|
+
pageProperties.nativePageRanges.from > 0 &&
|
|
39
|
+
pageProperties.nativePageRanges.to > 0 &&
|
|
40
|
+
pageProperties.nativePageRanges.to >=
|
|
41
|
+
pageProperties.nativePageRanges.from,
|
|
42
|
+
"page ranges syntax error"
|
|
43
|
+
);
|
|
44
|
+
|
|
45
|
+
data.append(
|
|
46
|
+
"nativePageRanges",
|
|
47
|
+
`${pageProperties.nativePageRanges.from}-${pageProperties.nativePageRanges.to}`
|
|
48
|
+
);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
}
|
package/src/main.config.ts
CHANGED
|
@@ -1,23 +1,36 @@
|
|
|
1
1
|
import { Gotenberg } from "./gotenberg";
|
|
2
2
|
|
|
3
|
-
export enum
|
|
3
|
+
export enum ChromiumRoute {
|
|
4
4
|
URL = "url",
|
|
5
5
|
HTML = "html",
|
|
6
6
|
MARKDOWN = "markdown",
|
|
7
7
|
}
|
|
8
8
|
|
|
9
|
+
enum PdfEngineRoute {
|
|
10
|
+
MERGE = "merge",
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
enum LibreOfficeRoute {
|
|
14
|
+
CONVERT = "convert",
|
|
15
|
+
}
|
|
9
16
|
export class Chromiumly {
|
|
10
|
-
|
|
17
|
+
public static readonly GOTENBERG_ENDPOINT = Gotenberg.endpoint;
|
|
11
18
|
|
|
12
|
-
|
|
19
|
+
public static readonly CHROMIUM_PATH = "forms/chromium/convert";
|
|
20
|
+
public static readonly PDF_ENGINES_PATH = "forms/pdfengines";
|
|
21
|
+
public static readonly LIBRE_OFFICE_PATH = "forms/libreoffice";
|
|
13
22
|
|
|
14
|
-
|
|
15
|
-
url:
|
|
16
|
-
html:
|
|
17
|
-
markdown:
|
|
23
|
+
public static readonly CHROMIUM_ROUTES = {
|
|
24
|
+
url: ChromiumRoute.URL,
|
|
25
|
+
html: ChromiumRoute.HTML,
|
|
26
|
+
markdown: ChromiumRoute.MARKDOWN,
|
|
18
27
|
};
|
|
19
28
|
|
|
20
|
-
public static readonly
|
|
21
|
-
|
|
22
|
-
|
|
29
|
+
public static readonly PDF_ENGINE_ROUTES = {
|
|
30
|
+
merge: PdfEngineRoute.MERGE,
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
public static readonly LIBRE_OFFICE_ROUTES = {
|
|
34
|
+
convert: LibreOfficeRoute.CONVERT,
|
|
35
|
+
};
|
|
23
36
|
}
|
package/src/main.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export {
|
|
2
|
-
export { MarkdownConverter } from "./
|
|
3
|
-
export {
|
|
1
|
+
export { PdfFormat } from "./common/constants";
|
|
2
|
+
export { HtmlConverter, MarkdownConverter, UrlConverter } from "./chromium";
|
|
3
|
+
export { PDFEngine } from "./pdf-engines";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { PDFEngine } from "./pdf.engine";
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { PathLike, promises } from "fs";
|
|
2
|
+
import path from "path";
|
|
3
|
+
|
|
4
|
+
import FormData from "form-data";
|
|
5
|
+
|
|
6
|
+
import { Chromiumly } from "../main.config";
|
|
7
|
+
import { GotenbergUtils, PdfFormat } from "../common";
|
|
8
|
+
import { LibreOfficeUtils, PageProperties } from "../libre-office";
|
|
9
|
+
import { PDFEngineUtils } from "./utils/engine.utils";
|
|
10
|
+
|
|
11
|
+
export class PDFEngine {
|
|
12
|
+
public static async merge({ files }: { files: PathLike[] }): Promise<Buffer> {
|
|
13
|
+
const data = new FormData();
|
|
14
|
+
await PDFEngineUtils.injectFiles(files, data);
|
|
15
|
+
const endpoint = `${Chromiumly.GOTENBERG_ENDPOINT}/${Chromiumly.PDF_ENGINES_PATH}/${Chromiumly.PDF_ENGINE_ROUTES.merge}`;
|
|
16
|
+
return GotenbergUtils.fetch(endpoint, data);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
public static async convert({
|
|
20
|
+
files,
|
|
21
|
+
properties,
|
|
22
|
+
pdfFormat,
|
|
23
|
+
merge,
|
|
24
|
+
}: {
|
|
25
|
+
files: PathLike[];
|
|
26
|
+
properties?: PageProperties;
|
|
27
|
+
pdfFormat?: PdfFormat;
|
|
28
|
+
merge?: boolean;
|
|
29
|
+
}): Promise<Buffer> {
|
|
30
|
+
const data = new FormData();
|
|
31
|
+
if (pdfFormat) {
|
|
32
|
+
data.append("pdfFormat", pdfFormat);
|
|
33
|
+
}
|
|
34
|
+
if (merge) {
|
|
35
|
+
data.append("merge", String(merge));
|
|
36
|
+
}
|
|
37
|
+
if (properties) {
|
|
38
|
+
LibreOfficeUtils.injectPageProperties(data, properties);
|
|
39
|
+
}
|
|
40
|
+
await LibreOfficeUtils.injectFiles(files, data);
|
|
41
|
+
const endpoint = `${Chromiumly.GOTENBERG_ENDPOINT}/${Chromiumly.LIBRE_OFFICE_PATH}/${Chromiumly.LIBRE_OFFICE_ROUTES.convert}`;
|
|
42
|
+
return GotenbergUtils.fetch(endpoint, data);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
public static async generate(
|
|
46
|
+
filename: string,
|
|
47
|
+
buffer: Buffer
|
|
48
|
+
): Promise<void> {
|
|
49
|
+
const __generated__ = path.resolve(process.cwd(), "__generated__");
|
|
50
|
+
await promises.mkdir(path.resolve(__generated__), { recursive: true });
|
|
51
|
+
await promises.writeFile(path.resolve(__generated__, filename), buffer);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { constants, createReadStream, PathLike, promises } from "fs";
|
|
2
|
+
import path from "path";
|
|
3
|
+
|
|
4
|
+
import FormData from "form-data";
|
|
5
|
+
|
|
6
|
+
export class PDFEngineUtils {
|
|
7
|
+
public static async injectFiles(files: PathLike[], data: FormData) {
|
|
8
|
+
for (const file of files) {
|
|
9
|
+
try {
|
|
10
|
+
await promises.access(file, constants.R_OK);
|
|
11
|
+
const filename = path.basename(file.toString());
|
|
12
|
+
data.append(filename, createReadStream(file));
|
|
13
|
+
} catch (error) {
|
|
14
|
+
throw error;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"converter.interface.js","sourceRoot":"","sources":["../../src/common/converter.interface.ts"],"names":[],"mappings":""}
|
package/dist/common/converter.js
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.Converter = void 0;
|
|
4
|
-
const tslib_1 = require("tslib");
|
|
5
|
-
const fs_1 = require("fs");
|
|
6
|
-
const path_1 = tslib_1.__importDefault(require("path"));
|
|
7
|
-
const main_config_1 = require("../main.config");
|
|
8
|
-
class Converter {
|
|
9
|
-
constructor(route) {
|
|
10
|
-
this.endpoint = `${main_config_1.Chromiumly.endpoint}/${main_config_1.Chromiumly.path}/${main_config_1.Chromiumly.routes[route]}`;
|
|
11
|
-
}
|
|
12
|
-
generate(filename, buffer) {
|
|
13
|
-
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
14
|
-
const __generated__ = path_1.default.resolve(process.cwd(), "__generated__");
|
|
15
|
-
yield fs_1.promises.mkdir(path_1.default.resolve(__generated__), { recursive: true });
|
|
16
|
-
yield fs_1.promises.writeFile(path_1.default.resolve(__generated__, filename), buffer);
|
|
17
|
-
});
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
exports.Converter = Converter;
|
|
21
|
-
//# sourceMappingURL=converter.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"converter.js","sourceRoot":"","sources":["../../src/common/converter.ts"],"names":[],"mappings":";;;;AAAA,2BAA8B;AAC9B,wDAAwB;AAExB,gDAAmD;AAEnD,MAAsB,SAAS;IAG7B,YAAY,KAAY;QACtB,IAAI,CAAC,QAAQ,GAAG,GAAG,wBAAU,CAAC,QAAQ,IAAI,wBAAU,CAAC,IAAI,IAAI,wBAAU,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC;IAC1F,CAAC;IAEK,QAAQ,CAAC,QAAgB,EAAE,MAAc;;YAC7C,MAAM,aAAa,GAAG,cAAI,CAAC,OAAO,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,eAAe,CAAC,CAAC;YACnE,MAAM,aAAQ,CAAC,KAAK,CAAC,cAAI,CAAC,OAAO,CAAC,aAAa,CAAC,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;YACvE,MAAM,aAAQ,CAAC,SAAS,CAAC,cAAI,CAAC,OAAO,CAAC,aAAa,EAAE,QAAQ,CAAC,EAAE,MAAM,CAAC,CAAC;QAC1E,CAAC;KAAA;CACF;AAZD,8BAYC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"converter.types.js","sourceRoot":"","sources":["../../src/common/converter.types.ts"],"names":[],"mappings":""}
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
/// <reference types="node" />
|
|
2
|
-
import FormData from "form-data";
|
|
3
|
-
import { PageProperties } from "./converter.types";
|
|
4
|
-
export declare class ConverterUtils {
|
|
5
|
-
private static assert;
|
|
6
|
-
static injectPageProperties(data: FormData, pageProperties: PageProperties): void;
|
|
7
|
-
static fetch(endpoint: string, data: FormData): Promise<Buffer>;
|
|
8
|
-
}
|
|
@@ -1,66 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ConverterUtils = void 0;
|
|
4
|
-
const tslib_1 = require("tslib");
|
|
5
|
-
const node_fetch_1 = tslib_1.__importDefault(require("node-fetch"));
|
|
6
|
-
class ConverterUtils {
|
|
7
|
-
static assert(condition, message) {
|
|
8
|
-
if (!condition) {
|
|
9
|
-
throw new Error(message);
|
|
10
|
-
}
|
|
11
|
-
}
|
|
12
|
-
static injectPageProperties(data, pageProperties) {
|
|
13
|
-
if (pageProperties) {
|
|
14
|
-
if (pageProperties.size) {
|
|
15
|
-
ConverterUtils.assert(pageProperties.size.width >= 1.0 && pageProperties.size.height >= 1.5, "size is smaller than the minimum printing requirements (i.e. 1.0 x 1.5 in)");
|
|
16
|
-
data.append("paperWidth", pageProperties.size.width);
|
|
17
|
-
data.append("paperHeight", pageProperties.size.height);
|
|
18
|
-
}
|
|
19
|
-
if (pageProperties.margins) {
|
|
20
|
-
ConverterUtils.assert(pageProperties.margins.top >= 0 &&
|
|
21
|
-
pageProperties.margins.bottom >= 0 &&
|
|
22
|
-
pageProperties.margins.left >= 0 &&
|
|
23
|
-
pageProperties.margins.left >= 0, "negative margins are not allowed");
|
|
24
|
-
data.append("marginTop", pageProperties.margins.top);
|
|
25
|
-
data.append("marginBottom", pageProperties.margins.bottom);
|
|
26
|
-
data.append("marginLeft", pageProperties.margins.left);
|
|
27
|
-
data.append("marginRight", pageProperties.margins.right);
|
|
28
|
-
}
|
|
29
|
-
if (pageProperties.preferCssPageSize) {
|
|
30
|
-
data.append("preferCssPageSize", String(pageProperties.preferCssPageSize));
|
|
31
|
-
}
|
|
32
|
-
if (pageProperties.printBackground) {
|
|
33
|
-
data.append("printBackground", String(pageProperties.printBackground));
|
|
34
|
-
}
|
|
35
|
-
if (pageProperties.landscape) {
|
|
36
|
-
data.append("landscape", String(pageProperties.landscape));
|
|
37
|
-
}
|
|
38
|
-
if (pageProperties.scale) {
|
|
39
|
-
ConverterUtils.assert(pageProperties.scale >= 0.1 && pageProperties.scale <= 2.0, "scale is outside of [0.1 - 2] range");
|
|
40
|
-
data.append("scale", pageProperties.scale);
|
|
41
|
-
}
|
|
42
|
-
if (pageProperties.nativePageRanges) {
|
|
43
|
-
ConverterUtils.assert(pageProperties.nativePageRanges.from > 0 &&
|
|
44
|
-
pageProperties.nativePageRanges.to > 0 &&
|
|
45
|
-
pageProperties.nativePageRanges.to >=
|
|
46
|
-
pageProperties.nativePageRanges.from, "page ranges syntax error");
|
|
47
|
-
data.append("nativePageRanges", `${pageProperties.nativePageRanges.from}-${pageProperties.nativePageRanges.to}`);
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
static fetch(endpoint, data) {
|
|
52
|
-
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
53
|
-
const response = yield (0, node_fetch_1.default)(endpoint, {
|
|
54
|
-
method: "post",
|
|
55
|
-
body: data,
|
|
56
|
-
headers: Object.assign({}, data.getHeaders()),
|
|
57
|
-
});
|
|
58
|
-
if (!response.ok) {
|
|
59
|
-
throw new Error(`${response.status} ${response.statusText}`);
|
|
60
|
-
}
|
|
61
|
-
return response.buffer();
|
|
62
|
-
});
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
exports.ConverterUtils = ConverterUtils;
|
|
66
|
-
//# sourceMappingURL=converter.utils.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"converter.utils.js","sourceRoot":"","sources":["../../src/common/converter.utils.ts"],"names":[],"mappings":"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"}
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
/// <reference types="node" />
|
|
2
|
-
import { PathLike } from "fs";
|
|
3
|
-
import { IConverter } from "../common/converter.interface";
|
|
4
|
-
import { PageProperties } from "../common/converter.types";
|
|
5
|
-
import { Converter } from "../common/converter";
|
|
6
|
-
export declare class HtmlConverter extends Converter implements IConverter {
|
|
7
|
-
constructor();
|
|
8
|
-
convert({ html, properties, }: {
|
|
9
|
-
html: PathLike;
|
|
10
|
-
properties?: PageProperties;
|
|
11
|
-
}): Promise<Buffer>;
|
|
12
|
-
}
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.HtmlConverter = void 0;
|
|
4
|
-
const tslib_1 = require("tslib");
|
|
5
|
-
const fs_1 = require("fs");
|
|
6
|
-
const form_data_1 = tslib_1.__importDefault(require("form-data"));
|
|
7
|
-
const converter_utils_1 = require("../common/converter.utils");
|
|
8
|
-
const converter_1 = require("../common/converter");
|
|
9
|
-
const main_config_1 = require("../main.config");
|
|
10
|
-
class HtmlConverter extends converter_1.Converter {
|
|
11
|
-
constructor() {
|
|
12
|
-
super(main_config_1.Route.HTML);
|
|
13
|
-
}
|
|
14
|
-
convert({ html, properties, }) {
|
|
15
|
-
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
16
|
-
const data = new form_data_1.default();
|
|
17
|
-
data.append("index.html", (0, fs_1.createReadStream)(html));
|
|
18
|
-
if (properties) {
|
|
19
|
-
converter_utils_1.ConverterUtils.injectPageProperties(data, properties);
|
|
20
|
-
}
|
|
21
|
-
return converter_utils_1.ConverterUtils.fetch(this.endpoint, data);
|
|
22
|
-
});
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
exports.HtmlConverter = HtmlConverter;
|
|
26
|
-
//# sourceMappingURL=html.converter.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"html.converter.js","sourceRoot":"","sources":["../../src/converters/html.converter.ts"],"names":[],"mappings":";;;;AAAA,2BAAgD;AAEhD,kEAAiC;AAIjC,+DAA2D;AAC3D,mDAAgD;AAChD,gDAAuC;AAEvC,MAAa,aAAc,SAAQ,qBAAS;IAC1C;QACE,KAAK,CAAC,mBAAK,CAAC,IAAI,CAAC,CAAC;IACpB,CAAC;IAEK,OAAO,CAAC,EACZ,IAAI,EACJ,UAAU,GAIX;;YACC,MAAM,IAAI,GAAG,IAAI,mBAAQ,EAAE,CAAC;YAC5B,IAAI,CAAC,MAAM,CAAC,YAAY,EAAE,IAAA,qBAAgB,EAAC,IAAI,CAAC,CAAC,CAAC;YAClD,IAAI,UAAU,EAAE;gBACd,gCAAc,CAAC,oBAAoB,CAAC,IAAI,EAAE,UAAU,CAAC,CAAC;aACvD;YACD,OAAO,gCAAc,CAAC,KAAK,CAAC,IAAI,CAAC,QAAQ,EAAE,IAAI,CAAC,CAAC;QACnD,CAAC;KAAA;CACF;AAnBD,sCAmBC"}
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
/// <reference types="node" />
|
|
2
|
-
import { PathLike } from "fs";
|
|
3
|
-
import { IConverter } from "../common/converter.interface";
|
|
4
|
-
import { PageProperties } from "../common/converter.types";
|
|
5
|
-
import { Converter } from "../common/converter";
|
|
6
|
-
export declare class MarkdownConverter extends Converter implements IConverter {
|
|
7
|
-
constructor();
|
|
8
|
-
convert({ html, markdown, properties, }: {
|
|
9
|
-
html: PathLike;
|
|
10
|
-
markdown: PathLike;
|
|
11
|
-
properties?: PageProperties;
|
|
12
|
-
}): Promise<Buffer>;
|
|
13
|
-
}
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.MarkdownConverter = void 0;
|
|
4
|
-
const tslib_1 = require("tslib");
|
|
5
|
-
const fs_1 = require("fs");
|
|
6
|
-
const form_data_1 = tslib_1.__importDefault(require("form-data"));
|
|
7
|
-
const converter_utils_1 = require("../common/converter.utils");
|
|
8
|
-
const converter_1 = require("../common/converter");
|
|
9
|
-
const main_config_1 = require("../main.config");
|
|
10
|
-
class MarkdownConverter extends converter_1.Converter {
|
|
11
|
-
constructor() {
|
|
12
|
-
super(main_config_1.Route.MARKDOWN);
|
|
13
|
-
}
|
|
14
|
-
convert({ html, markdown, properties, }) {
|
|
15
|
-
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
16
|
-
const data = new form_data_1.default();
|
|
17
|
-
data.append("index.html", (0, fs_1.createReadStream)(html));
|
|
18
|
-
data.append("file.md", (0, fs_1.createReadStream)(markdown));
|
|
19
|
-
if (properties) {
|
|
20
|
-
converter_utils_1.ConverterUtils.injectPageProperties(data, properties);
|
|
21
|
-
}
|
|
22
|
-
return converter_utils_1.ConverterUtils.fetch(this.endpoint, data);
|
|
23
|
-
});
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
exports.MarkdownConverter = MarkdownConverter;
|
|
27
|
-
//# sourceMappingURL=markdown.converter.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"markdown.converter.js","sourceRoot":"","sources":["../../src/converters/markdown.converter.ts"],"names":[],"mappings":";;;;AAAA,2BAAgD;AAEhD,kEAAiC;AAIjC,+DAA2D;AAC3D,mDAAgD;AAChD,gDAAuC;AAEvC,MAAa,iBAAkB,SAAQ,qBAAS;IAC9C;QACE,KAAK,CAAC,mBAAK,CAAC,QAAQ,CAAC,CAAC;IACxB,CAAC;IAEK,OAAO,CAAC,EACZ,IAAI,EACJ,QAAQ,EACR,UAAU,GAKX;;YACC,MAAM,IAAI,GAAG,IAAI,mBAAQ,EAAE,CAAC;YAC5B,IAAI,CAAC,MAAM,CAAC,YAAY,EAAE,IAAA,qBAAgB,EAAC,IAAI,CAAC,CAAC,CAAC;YAClD,IAAI,CAAC,MAAM,CAAC,SAAS,EAAE,IAAA,qBAAgB,EAAC,QAAQ,CAAC,CAAC,CAAC;YACnD,IAAI,UAAU,EAAE;gBACd,gCAAc,CAAC,oBAAoB,CAAC,IAAI,EAAE,UAAU,CAAC,CAAC;aACvD;YACD,OAAO,gCAAc,CAAC,KAAK,CAAC,IAAI,CAAC,QAAQ,EAAE,IAAI,CAAC,CAAC;QACnD,CAAC;KAAA;CACF;AAtBD,8CAsBC"}
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
/// <reference types="node" />
|
|
2
|
-
import { IConverter } from "../common/converter.interface";
|
|
3
|
-
import { PageProperties } from "../common/converter.types";
|
|
4
|
-
import { Converter } from "../common/converter";
|
|
5
|
-
export declare class UrlConverter extends Converter implements IConverter {
|
|
6
|
-
constructor();
|
|
7
|
-
convert({ url, properties, }: {
|
|
8
|
-
url: string;
|
|
9
|
-
properties?: PageProperties;
|
|
10
|
-
}): Promise<Buffer>;
|
|
11
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"url.converter.js","sourceRoot":"","sources":["../../src/converters/url.converter.ts"],"names":[],"mappings":";;;;AAAA,6BAA0B;AAE1B,kEAAiC;AAIjC,+DAA2D;AAC3D,mDAAgD;AAChD,gDAAuC;AAEvC,MAAa,YAAa,SAAQ,qBAAS;IACzC;QACE,KAAK,CAAC,mBAAK,CAAC,GAAG,CAAC,CAAC;IACnB,CAAC;IAEK,OAAO,CAAC,EACZ,GAAG,EACH,UAAU,GAIX;;YACC,IAAI;gBACF,MAAM,IAAI,GAAG,IAAI,SAAG,CAAC,GAAG,CAAC,CAAC;gBAC1B,MAAM,IAAI,GAAG,IAAI,mBAAQ,EAAE,CAAC;gBAC5B,IAAI,CAAC,MAAM,CAAC,KAAK,EAAE,IAAI,CAAC,IAAI,CAAC,CAAC;gBAC9B,IAAI,UAAU,EAAE;oBACd,gCAAc,CAAC,oBAAoB,CAAC,IAAI,EAAE,UAAU,CAAC,CAAC;iBACvD;gBACD,OAAO,gCAAc,CAAC,KAAK,CAAC,IAAI,CAAC,QAAQ,EAAE,IAAI,CAAC,CAAC;aAClD;YAAC,OAAO,KAAK,EAAE;gBACd,MAAM,KAAK,CAAC;aACb;QACH,CAAC;KAAA;CACF;AAxBD,oCAwBC"}
|
package/src/.DS_Store
DELETED
|
Binary file
|
package/src/common/converter.ts
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import { promises } from "fs";
|
|
2
|
-
import path from "path";
|
|
3
|
-
|
|
4
|
-
import { Chromiumly, Route } from "../main.config";
|
|
5
|
-
|
|
6
|
-
export abstract class Converter {
|
|
7
|
-
readonly endpoint: string;
|
|
8
|
-
|
|
9
|
-
constructor(route: Route) {
|
|
10
|
-
this.endpoint = `${Chromiumly.endpoint}/${Chromiumly.path}/${Chromiumly.routes[route]}`;
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
async generate(filename: string, buffer: Buffer): Promise<void> {
|
|
14
|
-
const __generated__ = path.resolve(process.cwd(), "__generated__");
|
|
15
|
-
await promises.mkdir(path.resolve(__generated__), { recursive: true });
|
|
16
|
-
await promises.writeFile(path.resolve(__generated__, filename), buffer);
|
|
17
|
-
}
|
|
18
|
-
}
|
|
@@ -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
|
-
}
|