chromiumly 1.0.4 → 2.0.0
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 +48 -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 +24 -0
- package/dist/pdf-engines/utils/engine.utils.js.map +1 -0
- package/package.json +2 -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/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,44 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.LibreOfficeUtils = 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 common_1 = require("../../common");
|
|
8
|
+
const constants_1 = require("./constants");
|
|
9
|
+
class LibreOfficeUtils {
|
|
10
|
+
static injectFiles(files, data) {
|
|
11
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
12
|
+
for (const file of files) {
|
|
13
|
+
try {
|
|
14
|
+
yield fs_1.promises.access(file, fs_1.constants.R_OK);
|
|
15
|
+
const filename = path_1.default.basename(file.toString());
|
|
16
|
+
const extension = path_1.default.extname(filename);
|
|
17
|
+
if (constants_1.LIBRE_OFFICE_EXTENSIONS.includes(extension)) {
|
|
18
|
+
data.append(filename, (0, fs_1.createReadStream)(file));
|
|
19
|
+
}
|
|
20
|
+
else {
|
|
21
|
+
throw new Error(`${extension} is not supported`);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
catch (error) {
|
|
25
|
+
throw error;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
static injectPageProperties(data, pageProperties) {
|
|
31
|
+
if (pageProperties.landscape) {
|
|
32
|
+
data.append("landscape", String(pageProperties.landscape));
|
|
33
|
+
}
|
|
34
|
+
if (pageProperties.nativePageRanges) {
|
|
35
|
+
common_1.GotenbergUtils.assert(pageProperties.nativePageRanges.from > 0 &&
|
|
36
|
+
pageProperties.nativePageRanges.to > 0 &&
|
|
37
|
+
pageProperties.nativePageRanges.to >=
|
|
38
|
+
pageProperties.nativePageRanges.from, "page ranges syntax error");
|
|
39
|
+
data.append("nativePageRanges", `${pageProperties.nativePageRanges.from}-${pageProperties.nativePageRanges.to}`);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
exports.LibreOfficeUtils = LibreOfficeUtils;
|
|
44
|
+
//# sourceMappingURL=libre-office.utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"libre-office.utils.js","sourceRoot":"","sources":["../../../src/libre-office/utils/libre-office.utils.ts"],"names":[],"mappings":";;;;AAAA,2BAAqE;AACrE,wDAAwB;AAIxB,yCAA8C;AAC9C,2CAAsD;AAGtD,MAAa,gBAAgB;IACpB,MAAM,CAAO,WAAW,CAAC,KAAiB,EAAE,IAAc;;YAC/D,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE;gBACxB,IAAI;oBACF,MAAM,aAAQ,CAAC,MAAM,CAAC,IAAI,EAAE,cAAS,CAAC,IAAI,CAAC,CAAC;oBAC5C,MAAM,QAAQ,GAAG,cAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,QAAQ,EAAE,CAAC,CAAC;oBAChD,MAAM,SAAS,GAAG,cAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC;oBACzC,IAAI,mCAAuB,CAAC,QAAQ,CAAC,SAAS,CAAC,EAAE;wBAC/C,IAAI,CAAC,MAAM,CAAC,QAAQ,EAAE,IAAA,qBAAgB,EAAC,IAAI,CAAC,CAAC,CAAC;qBAC/C;yBAAM;wBACL,MAAM,IAAI,KAAK,CAAC,GAAG,SAAS,mBAAmB,CAAC,CAAC;qBAClD;iBACF;gBAAC,OAAO,KAAK,EAAE;oBACd,MAAM,KAAK,CAAC;iBACb;aACF;QACH,CAAC;KAAA;IAEM,MAAM,CAAC,oBAAoB,CAChC,IAAc,EACd,cAA8B;QAE9B,IAAI,cAAc,CAAC,SAAS,EAAE;YAC5B,IAAI,CAAC,MAAM,CAAC,WAAW,EAAE,MAAM,CAAC,cAAc,CAAC,SAAS,CAAC,CAAC,CAAC;SAC5D;QAED,IAAI,cAAc,CAAC,gBAAgB,EAAE;YACnC,uBAAc,CAAC,MAAM,CACnB,cAAc,CAAC,gBAAgB,CAAC,IAAI,GAAG,CAAC;gBACtC,cAAc,CAAC,gBAAgB,CAAC,EAAE,GAAG,CAAC;gBACtC,cAAc,CAAC,gBAAgB,CAAC,EAAE;oBAChC,cAAc,CAAC,gBAAgB,CAAC,IAAI,EACxC,0BAA0B,CAC3B,CAAC;YAEF,IAAI,CAAC,MAAM,CACT,kBAAkB,EAClB,GAAG,cAAc,CAAC,gBAAgB,CAAC,IAAI,IAAI,cAAc,CAAC,gBAAgB,CAAC,EAAE,EAAE,CAChF,CAAC;SACH;IACH,CAAC;CACF;AAzCD,4CAyCC"}
|
package/dist/main.config.d.ts
CHANGED
|
@@ -1,17 +1,29 @@
|
|
|
1
|
-
export declare enum
|
|
1
|
+
export declare enum ChromiumRoute {
|
|
2
2
|
URL = "url",
|
|
3
3
|
HTML = "html",
|
|
4
4
|
MARKDOWN = "markdown"
|
|
5
5
|
}
|
|
6
|
+
declare enum PdfEngineRoute {
|
|
7
|
+
MERGE = "merge"
|
|
8
|
+
}
|
|
9
|
+
declare enum LibreOfficeRoute {
|
|
10
|
+
CONVERT = "convert"
|
|
11
|
+
}
|
|
6
12
|
export declare class Chromiumly {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
static readonly
|
|
11
|
-
static readonly
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
13
|
+
static readonly GOTENBERG_ENDPOINT: string;
|
|
14
|
+
static readonly CHROMIUM_PATH = "forms/chromium/convert";
|
|
15
|
+
static readonly PDF_ENGINES_PATH = "forms/pdfengines";
|
|
16
|
+
static readonly LIBRE_OFFICE_PATH = "forms/libreoffice";
|
|
17
|
+
static readonly CHROMIUM_ROUTES: {
|
|
18
|
+
url: ChromiumRoute;
|
|
19
|
+
html: ChromiumRoute;
|
|
20
|
+
markdown: ChromiumRoute;
|
|
21
|
+
};
|
|
22
|
+
static readonly PDF_ENGINE_ROUTES: {
|
|
23
|
+
merge: PdfEngineRoute;
|
|
24
|
+
};
|
|
25
|
+
static readonly LIBRE_OFFICE_ROUTES: {
|
|
26
|
+
convert: LibreOfficeRoute;
|
|
16
27
|
};
|
|
17
28
|
}
|
|
29
|
+
export {};
|
package/dist/main.config.js
CHANGED
|
@@ -1,24 +1,37 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.Chromiumly = exports.
|
|
3
|
+
exports.Chromiumly = exports.ChromiumRoute = void 0;
|
|
4
4
|
const gotenberg_1 = require("./gotenberg");
|
|
5
|
-
var
|
|
6
|
-
(function (
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
})(
|
|
5
|
+
var ChromiumRoute;
|
|
6
|
+
(function (ChromiumRoute) {
|
|
7
|
+
ChromiumRoute["URL"] = "url";
|
|
8
|
+
ChromiumRoute["HTML"] = "html";
|
|
9
|
+
ChromiumRoute["MARKDOWN"] = "markdown";
|
|
10
|
+
})(ChromiumRoute = exports.ChromiumRoute || (exports.ChromiumRoute = {}));
|
|
11
|
+
var PdfEngineRoute;
|
|
12
|
+
(function (PdfEngineRoute) {
|
|
13
|
+
PdfEngineRoute["MERGE"] = "merge";
|
|
14
|
+
})(PdfEngineRoute || (PdfEngineRoute = {}));
|
|
15
|
+
var LibreOfficeRoute;
|
|
16
|
+
(function (LibreOfficeRoute) {
|
|
17
|
+
LibreOfficeRoute["CONVERT"] = "convert";
|
|
18
|
+
})(LibreOfficeRoute || (LibreOfficeRoute = {}));
|
|
11
19
|
class Chromiumly {
|
|
12
20
|
}
|
|
13
21
|
exports.Chromiumly = Chromiumly;
|
|
14
22
|
Chromiumly.GOTENBERG_ENDPOINT = gotenberg_1.Gotenberg.endpoint;
|
|
15
|
-
Chromiumly.
|
|
16
|
-
Chromiumly.
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
23
|
+
Chromiumly.CHROMIUM_PATH = "forms/chromium/convert";
|
|
24
|
+
Chromiumly.PDF_ENGINES_PATH = "forms/pdfengines";
|
|
25
|
+
Chromiumly.LIBRE_OFFICE_PATH = "forms/libreoffice";
|
|
26
|
+
Chromiumly.CHROMIUM_ROUTES = {
|
|
27
|
+
url: ChromiumRoute.URL,
|
|
28
|
+
html: ChromiumRoute.HTML,
|
|
29
|
+
markdown: ChromiumRoute.MARKDOWN,
|
|
30
|
+
};
|
|
31
|
+
Chromiumly.PDF_ENGINE_ROUTES = {
|
|
32
|
+
merge: PdfEngineRoute.MERGE,
|
|
33
|
+
};
|
|
34
|
+
Chromiumly.LIBRE_OFFICE_ROUTES = {
|
|
35
|
+
convert: LibreOfficeRoute.CONVERT,
|
|
20
36
|
};
|
|
21
|
-
Chromiumly.endpoint = Chromiumly.GOTENBERG_ENDPOINT;
|
|
22
|
-
Chromiumly.path = Chromiumly.PATH;
|
|
23
|
-
Chromiumly.routes = Chromiumly.ROUTES;
|
|
24
37
|
//# sourceMappingURL=main.config.js.map
|
package/dist/main.config.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"main.config.js","sourceRoot":"","sources":["../src/main.config.ts"],"names":[],"mappings":";;;AAAA,2CAAwC;AAExC,IAAY,
|
|
1
|
+
{"version":3,"file":"main.config.js","sourceRoot":"","sources":["../src/main.config.ts"],"names":[],"mappings":";;;AAAA,2CAAwC;AAExC,IAAY,aAIX;AAJD,WAAY,aAAa;IACvB,4BAAW,CAAA;IACX,8BAAa,CAAA;IACb,sCAAqB,CAAA;AACvB,CAAC,EAJW,aAAa,GAAb,qBAAa,KAAb,qBAAa,QAIxB;AAED,IAAK,cAEJ;AAFD,WAAK,cAAc;IACjB,iCAAe,CAAA;AACjB,CAAC,EAFI,cAAc,KAAd,cAAc,QAElB;AAED,IAAK,gBAEJ;AAFD,WAAK,gBAAgB;IACnB,uCAAmB,CAAA;AACrB,CAAC,EAFI,gBAAgB,KAAhB,gBAAgB,QAEpB;AACD,MAAa,UAAU;;AAAvB,gCAoBC;AAnBwB,6BAAkB,GAAG,qBAAS,CAAC,QAAQ,CAAC;AAExC,wBAAa,GAAG,wBAAwB,CAAC;AACzC,2BAAgB,GAAG,kBAAkB,CAAC;AACtC,4BAAiB,GAAG,mBAAmB,CAAC;AAExC,0BAAe,GAAG;IACvC,GAAG,EAAE,aAAa,CAAC,GAAG;IACtB,IAAI,EAAE,aAAa,CAAC,IAAI;IACxB,QAAQ,EAAE,aAAa,CAAC,QAAQ;CACjC,CAAC;AAEqB,4BAAiB,GAAG;IACzC,KAAK,EAAE,cAAc,CAAC,KAAK;CAC5B,CAAC;AAEqB,8BAAmB,GAAG;IAC3C,OAAO,EAAE,gBAAgB,CAAC,OAAO;CAClC,CAAC"}
|
package/dist/main.d.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";
|
package/dist/main.js
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.UrlConverter = exports.MarkdownConverter = exports.HtmlConverter = void 0;
|
|
4
|
-
var
|
|
5
|
-
Object.defineProperty(exports, "
|
|
6
|
-
var
|
|
7
|
-
Object.defineProperty(exports, "
|
|
8
|
-
|
|
9
|
-
Object.defineProperty(exports, "UrlConverter", { enumerable: true, get: function () { return
|
|
3
|
+
exports.PDFEngine = exports.UrlConverter = exports.MarkdownConverter = exports.HtmlConverter = exports.PdfFormat = void 0;
|
|
4
|
+
var constants_1 = require("./common/constants");
|
|
5
|
+
Object.defineProperty(exports, "PdfFormat", { enumerable: true, get: function () { return constants_1.PdfFormat; } });
|
|
6
|
+
var chromium_1 = require("./chromium");
|
|
7
|
+
Object.defineProperty(exports, "HtmlConverter", { enumerable: true, get: function () { return chromium_1.HtmlConverter; } });
|
|
8
|
+
Object.defineProperty(exports, "MarkdownConverter", { enumerable: true, get: function () { return chromium_1.MarkdownConverter; } });
|
|
9
|
+
Object.defineProperty(exports, "UrlConverter", { enumerable: true, get: function () { return chromium_1.UrlConverter; } });
|
|
10
|
+
var pdf_engines_1 = require("./pdf-engines");
|
|
11
|
+
Object.defineProperty(exports, "PDFEngine", { enumerable: true, get: function () { return pdf_engines_1.PDFEngine; } });
|
|
10
12
|
//# sourceMappingURL=main.js.map
|
package/dist/main.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"main.js","sourceRoot":"","sources":["../src/main.ts"],"names":[],"mappings":";;;AAAA,
|
|
1
|
+
{"version":3,"file":"main.js","sourceRoot":"","sources":["../src/main.ts"],"names":[],"mappings":";;;AAAA,gDAA+C;AAAtC,sGAAA,SAAS,OAAA;AAClB,uCAA4E;AAAnE,yGAAA,aAAa,OAAA;AAAE,6GAAA,iBAAiB,OAAA;AAAE,wGAAA,YAAY,OAAA;AACvD,6CAA0C;AAAjC,wGAAA,SAAS,OAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { PDFEngine } from "./pdf.engine";
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.PDFEngine = void 0;
|
|
4
|
+
var pdf_engine_1 = require("./pdf.engine");
|
|
5
|
+
Object.defineProperty(exports, "PDFEngine", { enumerable: true, get: function () { return pdf_engine_1.PDFEngine; } });
|
|
6
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/pdf-engines/index.ts"],"names":[],"mappings":";;;AAAA,2CAAyC;AAAhC,uGAAA,SAAS,OAAA"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import { PathLike } from "fs";
|
|
3
|
+
import { PdfFormat } from "../common";
|
|
4
|
+
import { PageProperties } from "../libre-office";
|
|
5
|
+
export declare class PDFEngine {
|
|
6
|
+
static merge({ files }: {
|
|
7
|
+
files: PathLike[];
|
|
8
|
+
}): Promise<Buffer>;
|
|
9
|
+
static convert({ files, properties, pdfFormat, merge, }: {
|
|
10
|
+
files: PathLike[];
|
|
11
|
+
properties?: PageProperties;
|
|
12
|
+
pdfFormat?: PdfFormat;
|
|
13
|
+
merge?: boolean;
|
|
14
|
+
}): Promise<Buffer>;
|
|
15
|
+
static generate(filename: string, buffer: Buffer): Promise<void>;
|
|
16
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.PDFEngine = 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 form_data_1 = tslib_1.__importDefault(require("form-data"));
|
|
8
|
+
const main_config_1 = require("../main.config");
|
|
9
|
+
const common_1 = require("../common");
|
|
10
|
+
const libre_office_1 = require("../libre-office");
|
|
11
|
+
const engine_utils_1 = require("./utils/engine.utils");
|
|
12
|
+
class PDFEngine {
|
|
13
|
+
static merge({ files }) {
|
|
14
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
15
|
+
const data = new form_data_1.default();
|
|
16
|
+
yield engine_utils_1.PDFEngineUtils.injectFiles(files, data);
|
|
17
|
+
const endpoint = `${main_config_1.Chromiumly.GOTENBERG_ENDPOINT}/${main_config_1.Chromiumly.PDF_ENGINES_PATH}/${main_config_1.Chromiumly.PDF_ENGINE_ROUTES.merge}`;
|
|
18
|
+
return common_1.GotenbergUtils.fetch(endpoint, data);
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
static convert({ files, properties, pdfFormat, merge, }) {
|
|
22
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
23
|
+
const data = new form_data_1.default();
|
|
24
|
+
if (pdfFormat) {
|
|
25
|
+
data.append("pdfFormat", pdfFormat);
|
|
26
|
+
}
|
|
27
|
+
if (merge) {
|
|
28
|
+
data.append("merge", String(merge));
|
|
29
|
+
}
|
|
30
|
+
if (properties) {
|
|
31
|
+
libre_office_1.LibreOfficeUtils.injectPageProperties(data, properties);
|
|
32
|
+
}
|
|
33
|
+
yield libre_office_1.LibreOfficeUtils.injectFiles(files, data);
|
|
34
|
+
const endpoint = `${main_config_1.Chromiumly.GOTENBERG_ENDPOINT}/${main_config_1.Chromiumly.LIBRE_OFFICE_PATH}/${main_config_1.Chromiumly.LIBRE_OFFICE_ROUTES.convert}`;
|
|
35
|
+
return common_1.GotenbergUtils.fetch(endpoint, data);
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
static generate(filename, buffer) {
|
|
39
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
40
|
+
const __generated__ = path_1.default.resolve(process.cwd(), "__generated__");
|
|
41
|
+
yield fs_1.promises.mkdir(path_1.default.resolve(__generated__), { recursive: true });
|
|
42
|
+
yield fs_1.promises.writeFile(path_1.default.resolve(__generated__, filename), buffer);
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
exports.PDFEngine = PDFEngine;
|
|
47
|
+
//# sourceMappingURL=pdf.engine.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pdf.engine.js","sourceRoot":"","sources":["../../src/pdf-engines/pdf.engine.ts"],"names":[],"mappings":";;;;AAAA,2BAAwC;AACxC,wDAAwB;AAExB,kEAAiC;AAEjC,gDAA4C;AAC5C,sCAAsD;AACtD,kDAAmE;AACnE,uDAAsD;AAEtD,MAAa,SAAS;IACb,MAAM,CAAO,KAAK,CAAC,EAAE,KAAK,EAAyB;;YACxD,MAAM,IAAI,GAAG,IAAI,mBAAQ,EAAE,CAAC;YAC5B,MAAM,6BAAc,CAAC,WAAW,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC;YAC9C,MAAM,QAAQ,GAAG,GAAG,wBAAU,CAAC,kBAAkB,IAAI,wBAAU,CAAC,gBAAgB,IAAI,wBAAU,CAAC,iBAAiB,CAAC,KAAK,EAAE,CAAC;YACzH,OAAO,uBAAc,CAAC,KAAK,CAAC,QAAQ,EAAE,IAAI,CAAC,CAAC;QAC9C,CAAC;KAAA;IAEM,MAAM,CAAO,OAAO,CAAC,EAC1B,KAAK,EACL,UAAU,EACV,SAAS,EACT,KAAK,GAMN;;YACC,MAAM,IAAI,GAAG,IAAI,mBAAQ,EAAE,CAAC;YAC5B,IAAI,SAAS,EAAE;gBACb,IAAI,CAAC,MAAM,CAAC,WAAW,EAAE,SAAS,CAAC,CAAC;aACrC;YACD,IAAI,KAAK,EAAE;gBACT,IAAI,CAAC,MAAM,CAAC,OAAO,EAAE,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC;aACrC;YACD,IAAI,UAAU,EAAE;gBACd,+BAAgB,CAAC,oBAAoB,CAAC,IAAI,EAAE,UAAU,CAAC,CAAC;aACzD;YACD,MAAM,+BAAgB,CAAC,WAAW,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC;YAChD,MAAM,QAAQ,GAAG,GAAG,wBAAU,CAAC,kBAAkB,IAAI,wBAAU,CAAC,iBAAiB,IAAI,wBAAU,CAAC,mBAAmB,CAAC,OAAO,EAAE,CAAC;YAC9H,OAAO,uBAAc,CAAC,KAAK,CAAC,QAAQ,EAAE,IAAI,CAAC,CAAC;QAC9C,CAAC;KAAA;IAEM,MAAM,CAAO,QAAQ,CAC1B,QAAgB,EAChB,MAAc;;YAEd,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;AA1CD,8BA0CC"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.PDFEngineUtils = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const fs_1 = require("fs");
|
|
6
|
+
const path_1 = tslib_1.__importDefault(require("path"));
|
|
7
|
+
class PDFEngineUtils {
|
|
8
|
+
static injectFiles(files, data) {
|
|
9
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
10
|
+
for (const file of files) {
|
|
11
|
+
try {
|
|
12
|
+
yield fs_1.promises.access(file, fs_1.constants.R_OK);
|
|
13
|
+
const filename = path_1.default.basename(file.toString());
|
|
14
|
+
data.append(filename, (0, fs_1.createReadStream)(file));
|
|
15
|
+
}
|
|
16
|
+
catch (error) {
|
|
17
|
+
throw error;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
exports.PDFEngineUtils = PDFEngineUtils;
|
|
24
|
+
//# sourceMappingURL=engine.utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"engine.utils.js","sourceRoot":"","sources":["../../../src/pdf-engines/utils/engine.utils.ts"],"names":[],"mappings":";;;;AAAA,2BAAqE;AACrE,wDAAwB;AAIxB,MAAa,cAAc;IAClB,MAAM,CAAO,WAAW,CAAC,KAAiB,EAAE,IAAc;;YAC/D,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE;gBACxB,IAAI;oBACF,MAAM,aAAQ,CAAC,MAAM,CAAC,IAAI,EAAE,cAAS,CAAC,IAAI,CAAC,CAAC;oBAC5C,MAAM,QAAQ,GAAG,cAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,QAAQ,EAAE,CAAC,CAAC;oBAChD,IAAI,CAAC,MAAM,CAAC,QAAQ,EAAE,IAAA,qBAAgB,EAAC,IAAI,CAAC,CAAC,CAAC;iBAC/C;gBAAC,OAAO,KAAK,EAAE;oBACd,MAAM,KAAK,CAAC;iBACb;aACF;QACH,CAAC;KAAA;CACF;AAZD,wCAYC"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "chromiumly",
|
|
3
|
-
"version": "
|
|
4
|
-
"description": "A lightweight Typescrpit library which interacts with Gotenberg's
|
|
3
|
+
"version": "2.0.0",
|
|
4
|
+
"description": "A lightweight Typescrpit library which interacts with Gotenberg's different modules to convert a variety of document formats to PDF files.",
|
|
5
5
|
"main": "dist/main.js",
|
|
6
6
|
"types": "dist/main.d.ts",
|
|
7
7
|
"files": [
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { Chromiumly, ChromiumRoute } from "../../main.config";
|
|
2
|
+
|
|
3
|
+
export abstract class Converter {
|
|
4
|
+
readonly endpoint: string;
|
|
5
|
+
|
|
6
|
+
constructor(route: ChromiumRoute) {
|
|
7
|
+
this.endpoint = `${Chromiumly.GOTENBERG_ENDPOINT}/${Chromiumly.CHROMIUM_PATH}/${Chromiumly.CHROMIUM_ROUTES[route]}`;
|
|
8
|
+
}
|
|
9
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { constants, createReadStream, PathLike, promises } from "fs";
|
|
2
|
+
|
|
3
|
+
import FormData from "form-data";
|
|
4
|
+
|
|
5
|
+
import { GotenbergUtils, PdfFormat } from "../../common";
|
|
6
|
+
import { IConverter } from "../interfaces/converter.interface";
|
|
7
|
+
import { PageProperties } from "../interfaces/converter.types";
|
|
8
|
+
import { ConverterUtils } from "../utils/converter.utils";
|
|
9
|
+
import { Converter } from "./converter";
|
|
10
|
+
import { ChromiumRoute } from "../../main.config";
|
|
11
|
+
|
|
12
|
+
export class HtmlConverter extends Converter implements IConverter {
|
|
13
|
+
constructor() {
|
|
14
|
+
super(ChromiumRoute.HTML);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
async convert({
|
|
18
|
+
html,
|
|
19
|
+
properties,
|
|
20
|
+
pdfFormat,
|
|
21
|
+
}: {
|
|
22
|
+
html: PathLike;
|
|
23
|
+
properties?: PageProperties;
|
|
24
|
+
pdfFormat?: PdfFormat;
|
|
25
|
+
}): Promise<Buffer> {
|
|
26
|
+
try {
|
|
27
|
+
await promises.access(html, constants.R_OK);
|
|
28
|
+
const data = new FormData();
|
|
29
|
+
if (pdfFormat) {
|
|
30
|
+
data.append("pdfFormat", pdfFormat);
|
|
31
|
+
}
|
|
32
|
+
data.append("index.html", createReadStream(html));
|
|
33
|
+
if (properties) {
|
|
34
|
+
ConverterUtils.injectPageProperties(data, properties);
|
|
35
|
+
}
|
|
36
|
+
return GotenbergUtils.fetch(this.endpoint, data);
|
|
37
|
+
} catch (error) {
|
|
38
|
+
throw error;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { constants, createReadStream, PathLike, promises } from "fs";
|
|
2
|
+
|
|
3
|
+
import FormData from "form-data";
|
|
4
|
+
|
|
5
|
+
import { GotenbergUtils, PdfFormat } from "../../common";
|
|
6
|
+
import { IConverter } from "../interfaces/converter.interface";
|
|
7
|
+
import { PageProperties } from "../interfaces/converter.types";
|
|
8
|
+
import { ConverterUtils } from "../utils/converter.utils";
|
|
9
|
+
import { Converter } from "./converter";
|
|
10
|
+
import { ChromiumRoute } from "../../main.config";
|
|
11
|
+
|
|
12
|
+
export class MarkdownConverter extends Converter implements IConverter {
|
|
13
|
+
constructor() {
|
|
14
|
+
super(ChromiumRoute.MARKDOWN);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
async convert({
|
|
18
|
+
html,
|
|
19
|
+
markdown,
|
|
20
|
+
properties,
|
|
21
|
+
pdfFormat,
|
|
22
|
+
}: {
|
|
23
|
+
html: PathLike;
|
|
24
|
+
markdown: PathLike;
|
|
25
|
+
properties?: PageProperties;
|
|
26
|
+
pdfFormat?: PdfFormat;
|
|
27
|
+
}): Promise<Buffer> {
|
|
28
|
+
try {
|
|
29
|
+
await promises.access(html, constants.R_OK);
|
|
30
|
+
await promises.access(markdown, constants.R_OK);
|
|
31
|
+
const data = new FormData();
|
|
32
|
+
if (pdfFormat) {
|
|
33
|
+
data.append("pdfFormat", pdfFormat);
|
|
34
|
+
}
|
|
35
|
+
data.append("index.html", createReadStream(html));
|
|
36
|
+
data.append("file.md", createReadStream(markdown));
|
|
37
|
+
if (properties) {
|
|
38
|
+
ConverterUtils.injectPageProperties(data, properties);
|
|
39
|
+
}
|
|
40
|
+
return GotenbergUtils.fetch(this.endpoint, data);
|
|
41
|
+
} catch (error) {
|
|
42
|
+
throw error;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
}
|
|
@@ -2,32 +2,38 @@ import { URL } from "url";
|
|
|
2
2
|
|
|
3
3
|
import FormData from "form-data";
|
|
4
4
|
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
5
|
+
import { GotenbergUtils, PdfFormat } from "../../common";
|
|
6
|
+
import { IConverter } from "../interfaces/converter.interface";
|
|
7
|
+
import { PageProperties } from "../interfaces/converter.types";
|
|
8
|
+
import { ConverterUtils } from "../utils/converter.utils";
|
|
9
|
+
import { Converter } from "./converter";
|
|
10
|
+
import { ChromiumRoute } from "../../main.config";
|
|
10
11
|
|
|
11
12
|
export class UrlConverter extends Converter implements IConverter {
|
|
12
13
|
constructor() {
|
|
13
|
-
super(
|
|
14
|
+
super(ChromiumRoute.URL);
|
|
14
15
|
}
|
|
15
16
|
|
|
16
17
|
async convert({
|
|
17
18
|
url,
|
|
18
19
|
properties,
|
|
20
|
+
pdfFormat,
|
|
19
21
|
}: {
|
|
20
22
|
url: string;
|
|
21
23
|
properties?: PageProperties;
|
|
24
|
+
pdfFormat?: PdfFormat;
|
|
22
25
|
}): Promise<Buffer> {
|
|
23
26
|
try {
|
|
24
27
|
const _url = new URL(url);
|
|
25
28
|
const data = new FormData();
|
|
29
|
+
if (pdfFormat) {
|
|
30
|
+
data.append("pdfFormat", pdfFormat);
|
|
31
|
+
}
|
|
26
32
|
data.append("url", _url.href);
|
|
27
33
|
if (properties) {
|
|
28
34
|
ConverterUtils.injectPageProperties(data, properties);
|
|
29
35
|
}
|
|
30
|
-
return
|
|
36
|
+
return GotenbergUtils.fetch(this.endpoint, data);
|
|
31
37
|
} catch (error) {
|
|
32
38
|
throw error;
|
|
33
39
|
}
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import { PathLike } from "fs";
|
|
2
2
|
|
|
3
|
+
import { PdfFormat } from "../../common";
|
|
3
4
|
import { PageProperties } from "./converter.types";
|
|
4
5
|
|
|
5
6
|
export interface IConverter {
|
|
6
7
|
convert({
|
|
7
8
|
...args
|
|
8
9
|
}: {
|
|
9
|
-
[x: string]: string | PathLike | PageProperties;
|
|
10
|
+
[x: string]: string | PathLike | PageProperties | PdfFormat;
|
|
10
11
|
}): Promise<Buffer>;
|
|
11
12
|
}
|
|
File without changes
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import FormData from "form-data";
|
|
2
|
+
|
|
3
|
+
import { GotenbergUtils } from "../../common/gotenberg.utils";
|
|
4
|
+
import { PageProperties } from "../interfaces/converter.types";
|
|
5
|
+
|
|
6
|
+
export class ConverterUtils {
|
|
7
|
+
public static injectPageProperties(
|
|
8
|
+
data: FormData,
|
|
9
|
+
pageProperties: PageProperties
|
|
10
|
+
): void {
|
|
11
|
+
if (pageProperties.size) {
|
|
12
|
+
GotenbergUtils.assert(
|
|
13
|
+
pageProperties.size.width >= 1.0 && pageProperties.size.height >= 1.5,
|
|
14
|
+
"size is smaller than the minimum printing requirements (i.e. 1.0 x 1.5 in)"
|
|
15
|
+
);
|
|
16
|
+
|
|
17
|
+
data.append("paperWidth", pageProperties.size.width);
|
|
18
|
+
data.append("paperHeight", pageProperties.size.height);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
if (pageProperties.margins) {
|
|
22
|
+
GotenbergUtils.assert(
|
|
23
|
+
pageProperties.margins.top >= 0 &&
|
|
24
|
+
pageProperties.margins.bottom >= 0 &&
|
|
25
|
+
pageProperties.margins.left >= 0 &&
|
|
26
|
+
pageProperties.margins.left >= 0,
|
|
27
|
+
"negative margins are not allowed"
|
|
28
|
+
);
|
|
29
|
+
|
|
30
|
+
data.append("marginTop", pageProperties.margins.top);
|
|
31
|
+
data.append("marginBottom", pageProperties.margins.bottom);
|
|
32
|
+
data.append("marginLeft", pageProperties.margins.left);
|
|
33
|
+
data.append("marginRight", pageProperties.margins.right);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
if (pageProperties.preferCssPageSize) {
|
|
37
|
+
data.append(
|
|
38
|
+
"preferCssPageSize",
|
|
39
|
+
String(pageProperties.preferCssPageSize)
|
|
40
|
+
);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
if (pageProperties.printBackground) {
|
|
44
|
+
data.append("printBackground", String(pageProperties.printBackground));
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
if (pageProperties.landscape) {
|
|
48
|
+
data.append("landscape", String(pageProperties.landscape));
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
if (pageProperties.scale) {
|
|
52
|
+
GotenbergUtils.assert(
|
|
53
|
+
pageProperties.scale >= 0.1 && pageProperties.scale <= 2.0,
|
|
54
|
+
"scale is outside of [0.1 - 2] range"
|
|
55
|
+
);
|
|
56
|
+
|
|
57
|
+
data.append("scale", pageProperties.scale);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
if (pageProperties.nativePageRanges) {
|
|
61
|
+
GotenbergUtils.assert(
|
|
62
|
+
pageProperties.nativePageRanges.from > 0 &&
|
|
63
|
+
pageProperties.nativePageRanges.to > 0 &&
|
|
64
|
+
pageProperties.nativePageRanges.to >=
|
|
65
|
+
pageProperties.nativePageRanges.from,
|
|
66
|
+
"page ranges syntax error"
|
|
67
|
+
);
|
|
68
|
+
|
|
69
|
+
data.append(
|
|
70
|
+
"nativePageRanges",
|
|
71
|
+
`${pageProperties.nativePageRanges.from}-${pageProperties.nativePageRanges.to}`
|
|
72
|
+
);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import FormData from "form-data";
|
|
2
|
+
import fetch from "node-fetch";
|
|
3
|
+
|
|
4
|
+
export class GotenbergUtils {
|
|
5
|
+
public static assert(condition: boolean, message: string): asserts condition {
|
|
6
|
+
if (!condition) {
|
|
7
|
+
throw new Error(message);
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
public static async fetch(endpoint: string, data: FormData): Promise<Buffer> {
|
|
12
|
+
const response = await fetch(endpoint, {
|
|
13
|
+
method: "post",
|
|
14
|
+
body: data,
|
|
15
|
+
headers: {
|
|
16
|
+
...data.getHeaders(),
|
|
17
|
+
},
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
if (!response.ok) {
|
|
21
|
+
throw new Error(`${response.status} ${response.statusText}`);
|
|
22
|
+
}
|
|
23
|
+
return response.buffer();
|
|
24
|
+
}
|
|
25
|
+
}
|