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
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import { LibreOfficeUtils } from "../libre-office.utils";
|
|
2
|
+
import { promises, createReadStream } from "fs";
|
|
3
|
+
|
|
4
|
+
import FormData from "form-data";
|
|
5
|
+
|
|
6
|
+
describe("LibreOfficeUtils", () => {
|
|
7
|
+
const mockPromisesAccess = jest.spyOn(promises, "access");
|
|
8
|
+
const mockFormDataAppend = jest.spyOn(FormData.prototype, "append");
|
|
9
|
+
const data = new FormData();
|
|
10
|
+
|
|
11
|
+
beforeEach(() => {
|
|
12
|
+
(createReadStream as jest.Mock) = jest
|
|
13
|
+
.fn()
|
|
14
|
+
.mockImplementation((file) => file);
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
afterEach(() => {
|
|
18
|
+
jest.resetAllMocks();
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
describe("injectFiles", () => {
|
|
22
|
+
describe("when files exist", () => {
|
|
23
|
+
it("should append each file to data", async () => {
|
|
24
|
+
mockPromisesAccess.mockResolvedValue();
|
|
25
|
+
await LibreOfficeUtils.injectFiles(
|
|
26
|
+
["path/to/file.docx", "path/to/file.bib"],
|
|
27
|
+
data
|
|
28
|
+
);
|
|
29
|
+
expect(mockFormDataAppend).toBeCalledTimes(2);
|
|
30
|
+
});
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
describe("when one of the files has unsupported format", () => {
|
|
34
|
+
it("should throw an error", async () => {
|
|
35
|
+
mockPromisesAccess.mockResolvedValue();
|
|
36
|
+
await expect(() =>
|
|
37
|
+
LibreOfficeUtils.injectFiles(
|
|
38
|
+
["path/to/file.rar", "path/to/file.pdf"],
|
|
39
|
+
data
|
|
40
|
+
)
|
|
41
|
+
).rejects.toThrow(".rar is not supported");
|
|
42
|
+
});
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
describe("when one of the files does not exist", () => {
|
|
46
|
+
it("should throw an error", async () => {
|
|
47
|
+
const errorMessage =
|
|
48
|
+
"ENOENT: no such file or directory, access 'path/to/index.html'";
|
|
49
|
+
mockPromisesAccess.mockRejectedValue(new Error(errorMessage));
|
|
50
|
+
await expect(() =>
|
|
51
|
+
LibreOfficeUtils.injectFiles(
|
|
52
|
+
["path/to/file.pdf", "path/to/another-file.pdf"],
|
|
53
|
+
data
|
|
54
|
+
)
|
|
55
|
+
).rejects.toThrow(errorMessage);
|
|
56
|
+
});
|
|
57
|
+
});
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
describe("injectPageProperties", () => {
|
|
61
|
+
describe("Page landscape", () => {
|
|
62
|
+
describe("when landscape parameter is set", () => {
|
|
63
|
+
it("should append landscape to data", () => {
|
|
64
|
+
LibreOfficeUtils.injectPageProperties(data, {
|
|
65
|
+
landscape: true,
|
|
66
|
+
});
|
|
67
|
+
expect(mockFormDataAppend).toBeCalledTimes(1);
|
|
68
|
+
expect(data.append).toHaveBeenCalledWith("landscape", "true");
|
|
69
|
+
});
|
|
70
|
+
});
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
describe("Page ranges", () => {
|
|
74
|
+
describe("when nativePageRanges is valid", () => {
|
|
75
|
+
it("should append nativePageRanges to data", () => {
|
|
76
|
+
LibreOfficeUtils.injectPageProperties(data, {
|
|
77
|
+
nativePageRanges: { from: 1, to: 6 },
|
|
78
|
+
});
|
|
79
|
+
expect(mockFormDataAppend).toBeCalledTimes(1);
|
|
80
|
+
expect(data.append).toHaveBeenCalledWith("nativePageRanges", "1-6");
|
|
81
|
+
});
|
|
82
|
+
});
|
|
83
|
+
});
|
|
84
|
+
});
|
|
85
|
+
});
|
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,84 @@
|
|
|
1
|
+
import path from "path";
|
|
2
|
+
|
|
3
|
+
import { PDFEngine } from "./../pdf.engine";
|
|
4
|
+
import { PdfFormat } from "../../common";
|
|
5
|
+
|
|
6
|
+
import { promises, createReadStream } from "fs";
|
|
7
|
+
|
|
8
|
+
import fetch from "node-fetch";
|
|
9
|
+
import FormData from "form-data";
|
|
10
|
+
|
|
11
|
+
const { Response } = jest.requireActual("node-fetch");
|
|
12
|
+
jest.mock("node-fetch", () => jest.fn());
|
|
13
|
+
|
|
14
|
+
describe("PDFEngine", () => {
|
|
15
|
+
const mockProcessCwd = jest.spyOn(process, "cwd");
|
|
16
|
+
const mockPromisesAccess = jest.spyOn(promises, "access");
|
|
17
|
+
const mockPromisesMkDir = jest.spyOn(promises, "mkdir");
|
|
18
|
+
const mockPromisesWriteFile = jest.spyOn(promises, "writeFile");
|
|
19
|
+
const mockFetch = fetch as jest.MockedFunction<typeof fetch>;
|
|
20
|
+
const mockFormDataAppend = jest.spyOn(FormData.prototype, "append");
|
|
21
|
+
|
|
22
|
+
beforeEach(() => {
|
|
23
|
+
(createReadStream as jest.Mock) = jest
|
|
24
|
+
.fn()
|
|
25
|
+
.mockImplementation((file) => file);
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
afterEach(() => {
|
|
29
|
+
jest.resetAllMocks();
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
describe("convert", () => {
|
|
33
|
+
describe("when no properties are passed", () => {
|
|
34
|
+
it("should return a buffer", async () => {
|
|
35
|
+
mockPromisesAccess.mockResolvedValue();
|
|
36
|
+
mockFetch.mockResolvedValue(new Response("content"));
|
|
37
|
+
const buffer = await PDFEngine.convert({
|
|
38
|
+
files: ["path/to/file.docx", "path/to/file.bib"],
|
|
39
|
+
});
|
|
40
|
+
expect(buffer).toEqual(Buffer.from("content"));
|
|
41
|
+
expect(mockFormDataAppend).toBeCalledTimes(2);
|
|
42
|
+
});
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
describe("when properties are passed", () => {
|
|
46
|
+
it("should return a buffer", async () => {
|
|
47
|
+
mockPromisesAccess.mockResolvedValue();
|
|
48
|
+
mockFetch.mockResolvedValue(new Response("content"));
|
|
49
|
+
const buffer = await PDFEngine.convert({
|
|
50
|
+
files: ["path/to/file.docx", "path/to/file.bib"],
|
|
51
|
+
properties: { landscape: true },
|
|
52
|
+
pdfFormat: PdfFormat.A_1a,
|
|
53
|
+
merge: true,
|
|
54
|
+
});
|
|
55
|
+
expect(buffer).toEqual(Buffer.from("content"));
|
|
56
|
+
expect(mockFormDataAppend).toBeCalledTimes(5);
|
|
57
|
+
});
|
|
58
|
+
});
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
describe("merge", () => {
|
|
62
|
+
it("should return a buffer", async () => {
|
|
63
|
+
mockPromisesAccess.mockResolvedValue();
|
|
64
|
+
mockFetch.mockResolvedValue(new Response("content"));
|
|
65
|
+
const buffer = await PDFEngine.merge({
|
|
66
|
+
files: ["path/to/file.pdf", "path/to/another-file.pdf"],
|
|
67
|
+
});
|
|
68
|
+
expect(buffer).toEqual(Buffer.from("content"));
|
|
69
|
+
expect(mockFormDataAppend).toBeCalledTimes(2);
|
|
70
|
+
});
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
describe("generate", () => {
|
|
74
|
+
it("should generate a PDF file", async () => {
|
|
75
|
+
mockProcessCwd.mockReturnValue("path/to/");
|
|
76
|
+
mockPromisesMkDir.mockResolvedValue("__generated__");
|
|
77
|
+
await PDFEngine.generate("file.pdf", Buffer.from("content"));
|
|
78
|
+
expect(mockPromisesWriteFile).toBeCalledWith(
|
|
79
|
+
path.resolve("path/to/__generated__/file.pdf"),
|
|
80
|
+
Buffer.from("content")
|
|
81
|
+
);
|
|
82
|
+
});
|
|
83
|
+
});
|
|
84
|
+
});
|
|
@@ -0,0 +1,23 @@
|
|
|
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
|
+
const extension = path.extname(filename);
|
|
13
|
+
if (extension === ".pdf") {
|
|
14
|
+
data.append(filename, createReadStream(file));
|
|
15
|
+
} else {
|
|
16
|
+
throw new Error(`${extension} is not supported`);
|
|
17
|
+
}
|
|
18
|
+
} catch (error) {
|
|
19
|
+
throw error;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { PDFEngineUtils } from "./../engine.utils";
|
|
2
|
+
import { promises, createReadStream } from "fs";
|
|
3
|
+
|
|
4
|
+
import FormData from "form-data";
|
|
5
|
+
|
|
6
|
+
describe("PDFEngineUtils", () => {
|
|
7
|
+
const mockPromisesAccess = jest.spyOn(promises, "access");
|
|
8
|
+
const mockFormDataAppend = jest.spyOn(FormData.prototype, "append");
|
|
9
|
+
const data = new FormData();
|
|
10
|
+
|
|
11
|
+
beforeEach(() => {
|
|
12
|
+
(createReadStream as jest.Mock) = jest
|
|
13
|
+
.fn()
|
|
14
|
+
.mockImplementation((file) => file);
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
afterEach(() => {
|
|
18
|
+
jest.resetAllMocks();
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
describe("injectFiles", () => {
|
|
22
|
+
describe("when files exist", () => {
|
|
23
|
+
it("should append each file to data", async () => {
|
|
24
|
+
mockPromisesAccess.mockResolvedValue();
|
|
25
|
+
await PDFEngineUtils.injectFiles(
|
|
26
|
+
["path/to/file.pdf", "path/to/another-file.pdf"],
|
|
27
|
+
data
|
|
28
|
+
);
|
|
29
|
+
expect(mockFormDataAppend).toBeCalledTimes(2);
|
|
30
|
+
});
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
describe("when one of the files is not PDF", () => {
|
|
34
|
+
it("should throw an error", async () => {
|
|
35
|
+
mockPromisesAccess.mockResolvedValue();
|
|
36
|
+
await expect(() =>
|
|
37
|
+
PDFEngineUtils.injectFiles(
|
|
38
|
+
["path/to/file.docx", "path/to/file.pdf"],
|
|
39
|
+
data
|
|
40
|
+
)
|
|
41
|
+
).rejects.toThrow(".docx is not supported");
|
|
42
|
+
});
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
describe("when one of the files does not exist", () => {
|
|
46
|
+
it("should throw an error", async () => {
|
|
47
|
+
const errorMessage =
|
|
48
|
+
"ENOENT: no such file or directory, access 'path/to/index.html'";
|
|
49
|
+
mockPromisesAccess.mockRejectedValue(new Error(errorMessage));
|
|
50
|
+
await expect(() =>
|
|
51
|
+
PDFEngineUtils.injectFiles(
|
|
52
|
+
["path/to/file.pdf", "path/to/another-file.pdf"],
|
|
53
|
+
data
|
|
54
|
+
)
|
|
55
|
+
).rejects.toThrow(errorMessage);
|
|
56
|
+
});
|
|
57
|
+
});
|
|
58
|
+
});
|
|
59
|
+
});
|
|
@@ -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/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
|
-
}
|