@things-factory/pdf 10.1.123 → 10.1.132
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 +19 -30
- package/dist-client/pages/pdf-template/pdf-template-editor.d.ts +38 -0
- package/dist-client/pages/pdf-template/pdf-template-editor.js +198 -0
- package/dist-client/pages/pdf-template/pdf-template-editor.js.map +1 -0
- package/dist-client/pages/pdf-template/pdf-template-list-page.js +4 -3
- package/dist-client/pages/pdf-template/pdf-template-list-page.js.map +1 -1
- package/dist-client/route.d.ts +1 -1
- package/dist-client/route.js +3 -0
- package/dist-client/route.js.map +1 -1
- package/dist-client/tsconfig.tsbuildinfo +1 -1
- package/dist-server/controller/pdf-document.d.ts +17 -0
- package/dist-server/controller/pdf-document.js +26 -0
- package/dist-server/controller/pdf-document.js.map +1 -0
- package/dist-server/controller/pdf-release-service.d.ts +11 -0
- package/dist-server/controller/pdf-release-service.js +23 -0
- package/dist-server/controller/pdf-release-service.js.map +1 -0
- package/dist-server/controller/pdf-service.d.ts +2 -0
- package/dist-server/controller/pdf-service.js +40 -24
- package/dist-server/controller/pdf-service.js.map +1 -1
- package/dist-server/index.d.ts +3 -1
- package/dist-server/index.js +8 -1
- package/dist-server/index.js.map +1 -1
- package/dist-server/service/index.d.ts +2 -2
- package/dist-server/service/index.js +3 -4
- package/dist-server/service/index.js.map +1 -1
- package/dist-server/service/pdf-generate/index.d.ts +4 -0
- package/dist-server/service/pdf-generate/index.js +8 -0
- package/dist-server/service/pdf-generate/index.js.map +1 -0
- package/dist-server/service/pdf-generate/pdf-generate-resolver.d.ts +3 -2
- package/dist-server/service/pdf-generate/pdf-generate-resolver.js +27 -60
- package/dist-server/service/pdf-generate/pdf-generate-resolver.js.map +1 -1
- package/dist-server/service/pdf-release/pdf-release-mutation.js +6 -0
- package/dist-server/service/pdf-release/pdf-release-mutation.js.map +1 -1
- package/dist-server/service/pdf-release/pdf-release-query.d.ts +2 -0
- package/dist-server/service/pdf-release/pdf-release-query.js +13 -0
- package/dist-server/service/pdf-release/pdf-release-query.js.map +1 -1
- package/dist-server/service/pdf-release/pdf-release.d.ts +0 -2
- package/dist-server/service/pdf-release/pdf-release.js +1 -11
- package/dist-server/service/pdf-release/pdf-release.js.map +1 -1
- package/dist-server/service/pdf-template/pdf-template-mutation.js +6 -0
- package/dist-server/service/pdf-template/pdf-template-mutation.js.map +1 -1
- package/dist-server/service/pdf-template/pdf-template-query.js +2 -0
- package/dist-server/service/pdf-template/pdf-template-query.js.map +1 -1
- package/dist-server/service/pdf-template/pdf-template-type.d.ts +1 -0
- package/dist-server/service/pdf-template/pdf-template-type.js +4 -0
- package/dist-server/service/pdf-template/pdf-template-type.js.map +1 -1
- package/dist-server/tsconfig.tsbuildinfo +1 -1
- package/package.json +7 -9
- package/things-factory.config.js +5 -1
- package/translations/en.json +12 -8
- package/translations/ko.json +11 -7
- package/dist-server/routers/pdf-private-router.d.ts +0 -1
- package/dist-server/routers/pdf-private-router.js +0 -72
- package/dist-server/routers/pdf-private-router.js.map +0 -1
- package/dist-server/routers/pdf-public-router.d.ts +0 -1
- package/dist-server/routers/pdf-public-router.js +0 -66
- package/dist-server/routers/pdf-public-router.js.map +0 -1
- package/dist-server/routers/proxy-router.d.ts +0 -1
- package/dist-server/routers/proxy-router.js +0 -12
- package/dist-server/routers/proxy-router.js.map +0 -1
- package/dist-server/routes.d.ts +0 -1
- package/dist-server/routes.js +0 -21
- package/dist-server/routes.js.map +0 -1
package/package.json
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@things-factory/pdf",
|
|
3
|
-
"version": "10.1.
|
|
3
|
+
"version": "10.1.132",
|
|
4
4
|
"main": "dist-server/index.js",
|
|
5
5
|
"browser": "dist-client/index.js",
|
|
6
6
|
"things-factory": true,
|
|
7
7
|
"author": "heartyoh <heartyoh@hatiolab.com>",
|
|
8
|
-
"description": "Module that
|
|
8
|
+
"description": "Module that generates and serves PDF documents from templates for signed-in users.",
|
|
9
9
|
"license": "MIT",
|
|
10
10
|
"publishConfig": {
|
|
11
11
|
"access": "public",
|
|
@@ -23,15 +23,13 @@
|
|
|
23
23
|
"build:server": "npx tsc --p ./server/tsconfig.json",
|
|
24
24
|
"clean:client": "npx rimraf dist-client",
|
|
25
25
|
"clean:server": "npx rimraf dist-server",
|
|
26
|
-
"clean": "npm run clean:server && npm run clean:client"
|
|
26
|
+
"clean": "npm run clean:server && npm run clean:client",
|
|
27
|
+
"test": "node --test test/*.test.mjs"
|
|
27
28
|
},
|
|
28
29
|
"dependencies": {
|
|
30
|
+
"@things-factory/attachment-base": "^10.1.123",
|
|
29
31
|
"@things-factory/auth-base": "^10.1.123",
|
|
30
|
-
"
|
|
31
|
-
"await-spawn": "^4.0.1",
|
|
32
|
-
"ejs": "^3.1.10",
|
|
33
|
-
"handlebars": "^4.7.8",
|
|
34
|
-
"pdf-lib": "^1.17.1"
|
|
32
|
+
"handlebars": "^4.7.8"
|
|
35
33
|
},
|
|
36
|
-
"gitHead": "
|
|
34
|
+
"gitHead": "cf94714d27427754156fe3d6485158cf62f8d550"
|
|
37
35
|
}
|
package/things-factory.config.js
CHANGED
|
@@ -3,6 +3,10 @@ import bootstrap from './dist-client/bootstrap'
|
|
|
3
3
|
|
|
4
4
|
export default {
|
|
5
5
|
route,
|
|
6
|
-
routes: [
|
|
6
|
+
routes: [
|
|
7
|
+
{ tagname: 'pdf-template-list-page', page: 'pdf-template-list-page' },
|
|
8
|
+
{ tagname: 'pdf-template-editor', page: 'pdf-template-editor' },
|
|
9
|
+
{ tagname: 'pdf-release-list-page', page: 'pdf-release-list' }
|
|
10
|
+
],
|
|
7
11
|
bootstrap
|
|
8
12
|
}
|
package/translations/en.json
CHANGED
|
@@ -1,11 +1,15 @@
|
|
|
1
1
|
{
|
|
2
|
-
"field.content_template": "
|
|
3
|
-
"field.header_template": "
|
|
4
|
-
"field.footer_template": "
|
|
5
|
-
"field.cover_template": "
|
|
6
|
-
"field.last_template": "
|
|
7
|
-
"field.page_size": "
|
|
2
|
+
"field.content_template": "Body (HTML)",
|
|
3
|
+
"field.header_template": "Header (HTML)",
|
|
4
|
+
"field.footer_template": "Footer (HTML)",
|
|
5
|
+
"field.cover_template": "Cover (HTML)",
|
|
6
|
+
"field.last_template": "Last page (HTML)",
|
|
7
|
+
"field.page_size": "Page size",
|
|
8
8
|
"field.state": "state",
|
|
9
|
-
"field.watermark": "
|
|
10
|
-
"title.pdf-template list": "PDF template list"
|
|
9
|
+
"field.watermark": "Watermark",
|
|
10
|
+
"title.pdf-template list": "PDF template list",
|
|
11
|
+
"error.pdf-template-not-found": "The PDF template was not found.",
|
|
12
|
+
"title.pdf-template": "PDF template",
|
|
13
|
+
"field.pdf-sample-data": "Preview data (JSON)",
|
|
14
|
+
"button.pdf-preview": "Preview"
|
|
11
15
|
}
|
package/translations/ko.json
CHANGED
|
@@ -1,11 +1,15 @@
|
|
|
1
1
|
{
|
|
2
|
-
"field.content_template": "본문
|
|
3
|
-
"field.header_template": "
|
|
4
|
-
"field.footer_template": "바닥글
|
|
5
|
-
"field.cover_template": "표지
|
|
6
|
-
"field.last_template": "
|
|
7
|
-
"field.page_size": "크기",
|
|
2
|
+
"field.content_template": "본문 (HTML)",
|
|
3
|
+
"field.header_template": "머리글 (HTML)",
|
|
4
|
+
"field.footer_template": "바닥글 (HTML)",
|
|
5
|
+
"field.cover_template": "표지 (HTML)",
|
|
6
|
+
"field.last_template": "마지막 장 (HTML)",
|
|
7
|
+
"field.page_size": "용지 크기",
|
|
8
8
|
"field.state": "상태",
|
|
9
9
|
"field.watermark": "워터마크",
|
|
10
|
-
"title.pdf-template list": "PDF 템플릿 리스트"
|
|
10
|
+
"title.pdf-template list": "PDF 템플릿 리스트",
|
|
11
|
+
"error.pdf-template-not-found": "PDF 템플릿을 찾을 수 없습니다.",
|
|
12
|
+
"title.pdf-template": "PDF 템플릿",
|
|
13
|
+
"field.pdf-sample-data": "미리보기 데이터 (JSON)",
|
|
14
|
+
"button.pdf-preview": "미리보기"
|
|
11
15
|
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare const pdfPrivateRouter: any;
|
|
@@ -1,72 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.pdfPrivateRouter = void 0;
|
|
4
|
-
const tslib_1 = require("tslib");
|
|
5
|
-
const koa_router_1 = tslib_1.__importDefault(require("koa-router"));
|
|
6
|
-
const fs = tslib_1.__importStar(require("fs"));
|
|
7
|
-
const path = tslib_1.__importStar(require("path"));
|
|
8
|
-
const koa_send_1 = tslib_1.__importDefault(require("koa-send"));
|
|
9
|
-
const pdf_release_1 = require("../service/pdf-release/pdf-release");
|
|
10
|
-
const pdf_template_1 = require("../service/pdf-template/pdf-template");
|
|
11
|
-
const pdf_service_1 = require("../controller/pdf-service");
|
|
12
|
-
const PDF_STORAGE_PATH = '/path/to/pdf/storage'; // 실제 파일 저장 경로
|
|
13
|
-
const PDF_BASE_URL = 'https://yourdomain.com/pdf/'; // 파일 접근 URL의 기본 경로
|
|
14
|
-
const pdfService = new pdf_service_1.PdfService();
|
|
15
|
-
exports.pdfPrivateRouter = new koa_router_1.default();
|
|
16
|
-
function parseQuery(query) {
|
|
17
|
-
for (const key in query) {
|
|
18
|
-
if (query.hasOwnProperty(key)) {
|
|
19
|
-
try {
|
|
20
|
-
query[key] = JSON.parse(query[key]);
|
|
21
|
-
}
|
|
22
|
-
catch (error) {
|
|
23
|
-
// do nothing
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
return query;
|
|
28
|
-
}
|
|
29
|
-
// PDF 생성 및 저장 라우터
|
|
30
|
-
exports.pdfPrivateRouter.post('/generate-pdf', async (ctx) => {
|
|
31
|
-
const { templateId, data } = ctx.request.body;
|
|
32
|
-
const { domain, user, tx } = ctx.state;
|
|
33
|
-
const templateRepository = tx.getRepository(pdf_template_1.PDFTemplate);
|
|
34
|
-
const releaseRepository = tx.getRepository(pdf_release_1.PDFRelease);
|
|
35
|
-
const template = await templateRepository.findOne(templateId);
|
|
36
|
-
if (!template) {
|
|
37
|
-
ctx.throw(404, 'PDF Template not found');
|
|
38
|
-
}
|
|
39
|
-
// EJS 템플릿을 사용하여 PDF 생성
|
|
40
|
-
const pdfBuffer = await pdfService.generatePdf(template, data);
|
|
41
|
-
// 파일 저장 경로 및 URL 생성
|
|
42
|
-
const fileName = `${template.name}-${Date.now()}.pdf`;
|
|
43
|
-
const filePath = path.join(PDF_STORAGE_PATH, fileName);
|
|
44
|
-
const fileUrl = `${PDF_BASE_URL}${fileName}`;
|
|
45
|
-
// 파일 저장
|
|
46
|
-
fs.writeFileSync(filePath, pdfBuffer);
|
|
47
|
-
// 발행 이력 기록
|
|
48
|
-
const release = releaseRepository.create({
|
|
49
|
-
template,
|
|
50
|
-
filePath,
|
|
51
|
-
fileUrl,
|
|
52
|
-
state: 'published',
|
|
53
|
-
releasedBy: user,
|
|
54
|
-
domain
|
|
55
|
-
});
|
|
56
|
-
await releaseRepository.save(release);
|
|
57
|
-
ctx.body = release;
|
|
58
|
-
});
|
|
59
|
-
// PDF 다운로드 라우터
|
|
60
|
-
exports.pdfPrivateRouter.get('/download-pdf/:id', async (ctx) => {
|
|
61
|
-
const { id } = ctx.params;
|
|
62
|
-
const { tx } = ctx.state;
|
|
63
|
-
const releaseRepository = tx.getRepository(pdf_release_1.PDFRelease);
|
|
64
|
-
const pdfRelease = await releaseRepository.findOne(id);
|
|
65
|
-
if (!pdfRelease || !pdfRelease.filePath || !fs.existsSync(pdfRelease.filePath)) {
|
|
66
|
-
ctx.throw(404, 'PDF file not found');
|
|
67
|
-
}
|
|
68
|
-
// PDF 파일을 클라이언트에 전송
|
|
69
|
-
ctx.attachment(path.basename(pdfRelease.filePath));
|
|
70
|
-
await (0, koa_send_1.default)(ctx, pdfRelease.filePath, { root: '/' });
|
|
71
|
-
});
|
|
72
|
-
//# sourceMappingURL=pdf-private-router.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"pdf-private-router.js","sourceRoot":"","sources":["../../server/routers/pdf-private-router.ts"],"names":[],"mappings":";;;;AAAA,oEAA+B;AAC/B,+CAAwB;AACxB,mDAA4B;AAC5B,gEAA2B;AAE3B,oEAA+D;AAC/D,uEAAkE;AAClE,2DAAsD;AAEtD,MAAM,gBAAgB,GAAG,sBAAsB,CAAA,CAAC,cAAc;AAC9D,MAAM,YAAY,GAAG,6BAA6B,CAAA,CAAC,mBAAmB;AAEtE,MAAM,UAAU,GAAG,IAAI,wBAAU,EAAE,CAAA;AAEtB,QAAA,gBAAgB,GAAG,IAAI,oBAAM,EAAE,CAAA;AAE5C,SAAS,UAAU,CAAC,KAAK;IACvB,KAAK,MAAM,GAAG,IAAI,KAAK,EAAE,CAAC;QACxB,IAAI,KAAK,CAAC,cAAc,CAAC,GAAG,CAAC,EAAE,CAAC;YAC9B,IAAI,CAAC;gBACH,KAAK,CAAC,GAAG,CAAC,GAAG,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAA;YACrC,CAAC;YAAC,OAAO,KAAK,EAAE,CAAC;gBACf,aAAa;YACf,CAAC;QACH,CAAC;IACH,CAAC;IAED,OAAO,KAAK,CAAA;AACd,CAAC;AAED,kBAAkB;AAClB,wBAAgB,CAAC,IAAI,CAAC,eAAe,EAAE,KAAK,EAAC,GAAG,EAAC,EAAE;IACjD,MAAM,EAAE,UAAU,EAAE,IAAI,EAAE,GAAG,GAAG,CAAC,OAAO,CAAC,IAAI,CAAA;IAC7C,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,EAAE,EAAE,GAAG,GAAG,CAAC,KAAK,CAAA;IAEtC,MAAM,kBAAkB,GAAG,EAAE,CAAC,aAAa,CAAC,0BAAW,CAAC,CAAA;IACxD,MAAM,iBAAiB,GAAG,EAAE,CAAC,aAAa,CAAC,wBAAU,CAAC,CAAA;IAEtD,MAAM,QA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AAE,CAAC,CAAA;IAEtD,IAAI,CAAC,UAAU,IAAI,CAAC,UAAU,CAAC,QAAQ,IAAI,CAAC,EAAE,CAAC,UAAU,CAAC,UAAU,CAAC,QAAQ,CAAC,EAAE,CAAC;QAC/E,GAAG,CAAC,KAAK,CAAC,GAAG,EAAE,oBAAoB,CAAC,CAAA;IACtC,CAAC;IAED,oBAAoB;IACpB,GAAG,CAAC,UAAU,CAAC,IAAI,CAAC,QAAQ,CAAC,UAAU,CAAC,QAAQ,CAAC,CAAC,CAAA;IAClD,MAAM,IAAA,kBAAI,EAAC,GAAG,EAAE,UAAU,CAAC,QAAQ,EAAE,EAAE,IAAI,EAAE,GAAG,EAAE,CAAC,CAAA;AACrD,CAAC,CAAC,CAAA","sourcesContent":["import Router from 'koa-router'\nimport * as fs from 'fs'\nimport * as path from 'path'\nimport send from 'koa-send'\n\nimport { PDFRelease } from '../service/pdf-release/pdf-release'\nimport { PDFTemplate } from '../service/pdf-template/pdf-template'\nimport { PdfService } from '../controller/pdf-service'\n\nconst PDF_STORAGE_PATH = '/path/to/pdf/storage' // 실제 파일 저장 경로\nconst PDF_BASE_URL = 'https://yourdomain.com/pdf/' // 파일 접근 URL의 기본 경로\n\nconst pdfService = new PdfService()\n\nexport const pdfPrivateRouter = new Router()\n\nfunction parseQuery(query) {\n for (const key in query) {\n if (query.hasOwnProperty(key)) {\n try {\n query[key] = JSON.parse(query[key])\n } catch (error) {\n // do nothing\n }\n }\n }\n\n return query\n}\n\n// PDF 생성 및 저장 라우터\npdfPrivateRouter.post('/generate-pdf', async ctx => {\n const { templateId, data } = ctx.request.body\n const { domain, user, tx } = ctx.state\n\n const templateRepository = tx.getRepository(PDFTemplate)\n const releaseRepository = tx.getRepository(PDFRelease)\n\n const template = await templateRepository.findOne(templateId)\n if (!template) {\n ctx.throw(404, 'PDF Template not found')\n }\n\n // EJS 템플릿을 사용하여 PDF 생성\n const pdfBuffer = await pdfService.generatePdf(template, data)\n\n // 파일 저장 경로 및 URL 생성\n const fileName = `${template.name}-${Date.now()}.pdf`\n const filePath = path.join(PDF_STORAGE_PATH, fileName)\n const fileUrl = `${PDF_BASE_URL}${fileName}`\n\n // 파일 저장\n fs.writeFileSync(filePath, pdfBuffer)\n\n // 발행 이력 기록\n const release = releaseRepository.create({\n template,\n filePath,\n fileUrl,\n state: 'published',\n releasedBy: user,\n domain\n })\n\n await releaseRepository.save(release)\n\n ctx.body = release\n})\n\n// PDF 다운로드 라우터\npdfPrivateRouter.get('/download-pdf/:id', async ctx => {\n const { id } = ctx.params\n const { tx } = ctx.state\n\n const releaseRepository = tx.getRepository(PDFRelease)\n const pdfRelease = await releaseRepository.findOne(id)\n\n if (!pdfRelease || !pdfRelease.filePath || !fs.existsSync(pdfRelease.filePath)) {\n ctx.throw(404, 'PDF file not found')\n }\n\n // PDF 파일을 클라이언트에 전송\n ctx.attachment(path.basename(pdfRelease.filePath))\n await send(ctx, pdfRelease.filePath, { root: '/' })\n})\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare const pdfPublicRouter: any;
|
|
@@ -1,66 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.pdfPublicRouter = void 0;
|
|
4
|
-
const tslib_1 = require("tslib");
|
|
5
|
-
const await_spawn_1 = tslib_1.__importDefault(require("await-spawn"));
|
|
6
|
-
const fs_1 = require("fs");
|
|
7
|
-
const koa_router_1 = tslib_1.__importDefault(require("koa-router"));
|
|
8
|
-
const path_1 = tslib_1.__importDefault(require("path"));
|
|
9
|
-
const utils_1 = require("@things-factory/utils");
|
|
10
|
-
exports.pdfPublicRouter = new koa_router_1.default();
|
|
11
|
-
/* to-png */
|
|
12
|
-
exports.pdfPublicRouter.get('/to-png', async (context, next) => {
|
|
13
|
-
const { url } = context.query;
|
|
14
|
-
const images = await (0, utils_1.withTempDir)(async (tmpDir) => {
|
|
15
|
-
const curl = (0, await_spawn_1.default)('curl', ['-s', url]);
|
|
16
|
-
await (0, await_spawn_1.default)('gs', ['-q', '-sDEVICE=png16m', '-o', `${tmpDir}/%d.png`, '-r300', '-'], {
|
|
17
|
-
stdio: [curl.child.stdout, 'pipe', 'pipe']
|
|
18
|
-
});
|
|
19
|
-
const files = await fs_1.promises.readdir(tmpDir);
|
|
20
|
-
return Promise.all(files
|
|
21
|
-
.sort(new Intl.Collator(undefined, { numeric: true }).compare)
|
|
22
|
-
.map(filename => fs_1.promises.readFile(path_1.default.join(tmpDir, filename))));
|
|
23
|
-
});
|
|
24
|
-
/* TODO make it possible to return multiple images */
|
|
25
|
-
context.type = 'image/png';
|
|
26
|
-
context.body = images[0];
|
|
27
|
-
});
|
|
28
|
-
/* merge-pdf */
|
|
29
|
-
const mergePDFfiles = async (urls) => {
|
|
30
|
-
return await (0, utils_1.withTempDir)(async (tmpdir) => {
|
|
31
|
-
const sources = typeof urls == 'string' ? [urls] : urls;
|
|
32
|
-
const output = path_1.default.join(tmpdir, 'output.pdf');
|
|
33
|
-
const inputs = sources.map((source, idx) => path_1.default.join(tmpdir, `${idx}.pdf`));
|
|
34
|
-
try {
|
|
35
|
-
await Promise.all(sources.map((source, idx) => (0, await_spawn_1.default)('curl', ['-sSL', source, '-o', path_1.default.join(tmpdir, `${idx}.pdf`)])));
|
|
36
|
-
await (0, await_spawn_1.default)('gs', [
|
|
37
|
-
'-q',
|
|
38
|
-
'-sDEVICE=pdfwrite',
|
|
39
|
-
'-dAutoRotatePages=/None',
|
|
40
|
-
'-dNOPAUSE',
|
|
41
|
-
'-dBATCH',
|
|
42
|
-
'-dSAFER',
|
|
43
|
-
`-sOutputFile=${output}`,
|
|
44
|
-
...inputs
|
|
45
|
-
]);
|
|
46
|
-
return await fs_1.promises.readFile(output);
|
|
47
|
-
}
|
|
48
|
-
catch (e) {
|
|
49
|
-
console.error('mergePDFfiles', 'error', e);
|
|
50
|
-
}
|
|
51
|
-
});
|
|
52
|
-
};
|
|
53
|
-
exports.pdfPublicRouter.get('/merge', async (context, next) => {
|
|
54
|
-
const searchParams = new URLSearchParams(context.querystring);
|
|
55
|
-
const urls = searchParams.getAll('urls');
|
|
56
|
-
const pdf = await mergePDFfiles(urls);
|
|
57
|
-
context.type = 'application/pdf';
|
|
58
|
-
context.body = pdf;
|
|
59
|
-
});
|
|
60
|
-
exports.pdfPublicRouter.post('/merge', async (context, next) => {
|
|
61
|
-
const { urls } = context.request.body;
|
|
62
|
-
const pdf = await mergePDFfiles(urls);
|
|
63
|
-
context.type = 'application/pdf';
|
|
64
|
-
context.body = pdf;
|
|
65
|
-
});
|
|
66
|
-
//# sourceMappingURL=pdf-public-router.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"pdf-public-router.js","sourceRoot":"","sources":["../../server/routers/pdf-public-router.ts"],"names":[],"mappings":";;;;AAAA,sEAAqC;AACrC,2BAAmC;AACnC,oEAA+B;AAC/B,wDAAuB;AACvB,iDAAmD;AAEtC,QAAA,eAAe,GAAG,IAAI,oBAAM,EAAE,CAAA;AAE3C,YAAY;AACZ,uBAAe,CAAC,GAAG,CAAC,SAAS,EAAE,KAAK,EAAE,OAAO,EAAE,IAAI,EAAE,EAAE;IACrD,MAAM,EAAE,GAAG,EAAE,GAAG,OAAO,CAAC,KAAK,CAAA;IAE7B,MAAM,MAAM,GAAG,MAAM,IAAA,mBAAW,EAAC,KAAK,EAAC,MAAM,EAAC,EAAE;QAC9C,MAAM,IAAI,GAAG,IAAA,qBAAW,EAAC,MAAM,EAAE,CAAC,IAAI,EAAE,GAAG,CAAC,CAAC,CAAA;QAE7C,MAAM,IAAA,qBAAW,EAAC,IAAI,EAAE,CAAC,IAAI,EAAE,iBAAiB,EAAE,IAAI,EAAE,GAAG,MAAM,SAAS,EAAE,OAAO,EAAE,GAAG,CAAC,EAAE;YACzF,KAAK,EAAE,CAAC,IAAI,CAAC,KAAK,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC;SAC3C,CAAC,CAAA;QAEF,M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 'await-spawn'\nimport { promises as fs } from 'fs'\nimport Router from 'koa-router'\nimport path from 'path'\nimport { withTempDir } from '@things-factory/utils'\n\nexport const pdfPublicRouter = new Router()\n\n/* to-png */\npdfPublicRouter.get('/to-png', async (context, next) => {\n const { url } = context.query\n\n const images = await withTempDir(async tmpDir => {\n const curl = await_spawn('curl', ['-s', url])\n\n await await_spawn('gs', ['-q', '-sDEVICE=png16m', '-o', `${tmpDir}/%d.png`, '-r300', '-'], {\n stdio: [curl.child.stdout, 'pipe', 'pipe']\n })\n\n const files = await fs.readdir(tmpDir)\n return Promise.all(\n files\n .sort(new Intl.Collator(undefined, { numeric: true }).compare)\n .map(filename => fs.readFile(path.join(tmpDir, filename)))\n )\n })\n\n /* TODO make it possible to return multiple images */\n context.type = 'image/png'\n context.body = images[0]\n})\n\n/* merge-pdf */\nconst mergePDFfiles = async urls => {\n return await withTempDir(async tmpdir => {\n const sources = typeof urls == 'string' ? [urls] : urls\n const output = path.join(tmpdir, 'output.pdf')\n const inputs = sources.map((source, idx) => path.join(tmpdir, `${idx}.pdf`))\n\n try {\n await Promise.all(\n sources.map((source, idx) => await_spawn('curl', ['-sSL', source, '-o', path.join(tmpdir, `${idx}.pdf`)]))\n )\n\n await await_spawn('gs', [\n '-q',\n '-sDEVICE=pdfwrite',\n '-dAutoRotatePages=/None',\n '-dNOPAUSE',\n '-dBATCH',\n '-dSAFER',\n `-sOutputFile=${output}`,\n ...inputs\n ])\n\n return await fs.readFile(output)\n } catch (e) {\n console.error('mergePDFfiles', 'error', e)\n }\n })\n}\n\npdfPublicRouter.get('/merge', async (context, next) => {\n const searchParams = new URLSearchParams(context.querystring)\n const urls = searchParams.getAll('urls')\n\n const pdf = await mergePDFfiles(urls)\n\n context.type = 'application/pdf'\n context.body = pdf\n})\n\npdfPublicRouter.post('/merge', async (context, next) => {\n const { urls } = context.request.body\n\n const pdf = await mergePDFfiles(urls)\n\n context.type = 'application/pdf'\n context.body = pdf\n})\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare const proxyRouter: any;
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.proxyRouter = void 0;
|
|
4
|
-
const tslib_1 = require("tslib");
|
|
5
|
-
const koa_router_1 = tslib_1.__importDefault(require("koa-router"));
|
|
6
|
-
const request_1 = tslib_1.__importDefault(require("request"));
|
|
7
|
-
exports.proxyRouter = new koa_router_1.default();
|
|
8
|
-
exports.proxyRouter.get('/', async (context, next) => {
|
|
9
|
-
const { url } = context.query;
|
|
10
|
-
context.body = context.req.pipe((0, request_1.default)(url));
|
|
11
|
-
});
|
|
12
|
-
//# sourceMappingURL=proxy-router.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"proxy-router.js","sourceRoot":"","sources":["../../server/routers/proxy-router.ts"],"names":[],"mappings":";;;;AAAA,oEAA+B;AAC/B,8DAA6B;AAEhB,QAAA,WAAW,GAAG,IAAI,oBAAM,EAAE,CAAA;AAEvC,mBAAW,CAAC,GAAG,CAAC,GAAG,EAAE,KAAK,EAAE,OAAO,EAAE,IAAI,EAAE,EAAE;IAC3C,MAAM,EAAE,GAAG,EAAE,GAAG,OAAO,CAAC,KAAK,CAAA;IAC7B,OAAO,CAAC,IAAI,GAAG,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,IAAA,iBAAO,EAAC,GAAG,CAAC,CAAC,CAAA;AAC/C,CAAC,CAAC,CAAA","sourcesContent":["import Router from 'koa-router'\nimport request from 'request'\n\nexport const proxyRouter = new Router()\n\nproxyRouter.get('/', async (context, next) => {\n const { url } = context.query\n context.body = context.req.pipe(request(url))\n})\n"]}
|
package/dist-server/routes.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
package/dist-server/routes.js
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const env_1 = require("@things-factory/env");
|
|
4
|
-
const shell_1 = require("@things-factory/shell");
|
|
5
|
-
const pdf_public_router_1 = require("./routers/pdf-public-router");
|
|
6
|
-
const pdf_private_router_1 = require("./routers/pdf-private-router");
|
|
7
|
-
const proxy_router_1 = require("./routers/proxy-router");
|
|
8
|
-
const isPathBaseDomain = !env_1.config.get('subdomain');
|
|
9
|
-
process.on('bootstrap-module-global-public-route', (app, globalPublicRouter) => {
|
|
10
|
-
globalPublicRouter.use('/pdf', pdf_public_router_1.pdfPublicRouter.routes(), pdf_public_router_1.pdfPublicRouter.allowedMethods());
|
|
11
|
-
globalPublicRouter.use('/proxy', proxy_router_1.proxyRouter.routes(), proxy_router_1.proxyRouter.allowedMethods());
|
|
12
|
-
});
|
|
13
|
-
process.on('bootstrap-module-domain-private-route', (app, domainPrivateRouter) => {
|
|
14
|
-
if (isPathBaseDomain) {
|
|
15
|
-
domainPrivateRouter.use(`/${(0, shell_1.getRoutePrefixForDomainType)()}/:domain`, pdf_private_router_1.pdfPrivateRouter.routes(), pdf_private_router_1.pdfPrivateRouter.allowedMethods());
|
|
16
|
-
}
|
|
17
|
-
else {
|
|
18
|
-
domainPrivateRouter.use('', pdf_private_router_1.pdfPrivateRouter.routes(), pdf_private_router_1.pdfPrivateRouter.allowedMethods());
|
|
19
|
-
}
|
|
20
|
-
});
|
|
21
|
-
//# sourceMappingURL=routes.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"routes.js","sourceRoot":"","sources":["../server/routes.ts"],"names":[],"mappings":";;AAAA,6CAA4C;AAC5C,iDAAmE;AAEnE,mEAA6D;AAC7D,qEAA+D;AAC/D,yDAAoD;AAEpD,MAAM,gBAAgB,GAAG,CAAC,YAAM,CAAC,GAAG,CAAC,WAAW,CAAC,CAAA;AAEjD,OAAO,CAAC,EAAE,CAAC,sCAA6C,EAAE,CAAC,GAAG,EAAE,kBAAkB,EAAE,EAAE;IACpF,kBAAkB,CAAC,GAAG,CAAC,MAAM,EAAE,mCAAe,CAAC,MAAM,EAAE,EAAE,mCAAe,CAAC,cAAc,EAAE,CAAC,CAAA;IAC1F,kBAAkB,CAAC,GAAG,CAAC,QAAQ,EAAE,0BAAW,CAAC,MAAM,EAAE,EAAE,0BAAW,CAAC,cAAc,EAAE,CAAC,CAAA;AACtF,CAAC,CAAC,CAAA;AAEF,OAAO,CAAC,EAAE,CAAC,uCAA8C,EAAE,CAAC,GAAG,EAAE,mBAAmB,EAAE,EAAE;IACtF,IAAI,gBAAgB,EAAE,CAAC;QACrB,mBAAmB,CAAC,GAAG,CACrB,IAAI,IAAA,mCAA2B,GAAE,UAAU,EAC3C,qCAAgB,CAAC,MAAM,EAAE,EACzB,qCAAgB,CAAC,cAAc,EAAE,CAClC,CAAA;IACH,CAAC;SAAM,CAAC;QACN,mBAAmB,CAAC,GAAG,CAAC,EAAE,EAAE,qCAAgB,CAAC,MAAM,EAAE,EAAE,qCAAgB,CAAC,cAAc,EAAE,CAAC,CAAA;IAC3F,CAAC;AACH,CAAC,CAAC,CAAA","sourcesContent":["import { config } from '@things-factory/env'\nimport { getRoutePrefixForDomainType } from '@things-factory/shell'\n\nimport { pdfPublicRouter } from './routers/pdf-public-router'\nimport { pdfPrivateRouter } from './routers/pdf-private-router'\nimport { proxyRouter } from './routers/proxy-router'\n\nconst isPathBaseDomain = !config.get('subdomain')\n\nprocess.on('bootstrap-module-global-public-route' as any, (app, globalPublicRouter) => {\n globalPublicRouter.use('/pdf', pdfPublicRouter.routes(), pdfPublicRouter.allowedMethods())\n globalPublicRouter.use('/proxy', proxyRouter.routes(), proxyRouter.allowedMethods())\n})\n\nprocess.on('bootstrap-module-domain-private-route' as any, (app, domainPrivateRouter) => {\n if (isPathBaseDomain) {\n domainPrivateRouter.use(\n `/${getRoutePrefixForDomainType()}/:domain`,\n pdfPrivateRouter.routes(),\n pdfPrivateRouter.allowedMethods()\n )\n } else {\n domainPrivateRouter.use('', pdfPrivateRouter.routes(), pdfPrivateRouter.allowedMethods())\n }\n})\n"]}
|