Quellcode durchsuchen

remove unnecessary files

Futa Arai vor 1 Jahr
Ursprung
Commit
f68eba2c86

+ 0 - 1
apps/pdf-converter/dist/bin/index.d.ts

@@ -1 +0,0 @@
-export {};

+ 0 - 8
apps/pdf-converter/dist/bin/index.js

@@ -1,8 +0,0 @@
-import { CliCore } from '@tsed/cli-core';
-import { GenerateSwaggerCmd } from '@tsed/cli-generate-swagger';
-import Server from '../server.js';
-CliCore.bootstrap({
-    server: Server,
-    commands: [GenerateSwaggerCmd],
-});
-//# sourceMappingURL=index.js.map

+ 0 - 1
apps/pdf-converter/dist/bin/index.js.map

@@ -1 +0,0 @@
-{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/bin/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAC;AACzC,OAAO,EAAE,kBAAkB,EAAE,MAAM,4BAA4B,CAAC;AAEhE,OAAO,MAAM,MAAM,cAAc,CAAC;AAElC,OAAO,CAAC,SAAS,CAAC;IAChB,MAAM,EAAE,MAAM;IACd,QAAQ,EAAE,CAAC,kBAAkB,CAAC;CAC/B,CAAC,CAAC"}

+ 0 - 2
apps/pdf-converter/dist/controllers/index.d.ts

@@ -1,2 +0,0 @@
-export { default as PdfCtrl } from './pdf.js';
-export { default as TerminusCtrl } from './terminus.js';

+ 0 - 3
apps/pdf-converter/dist/controllers/index.js

@@ -1,3 +0,0 @@
-export { default as PdfCtrl } from './pdf.js';
-export { default as TerminusCtrl } from './terminus.js';
-//# sourceMappingURL=index.js.map

+ 0 - 1
apps/pdf-converter/dist/controllers/index.js.map

@@ -1 +0,0 @@
-{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/controllers/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,IAAI,OAAO,EAAE,MAAM,UAAU,CAAC;AAC9C,OAAO,EAAE,OAAO,IAAI,YAAY,EAAE,MAAM,eAAe,CAAC"}

+ 0 - 11
apps/pdf-converter/dist/controllers/pdf.d.ts

@@ -1,11 +0,0 @@
-import { Logger } from '@tsed/common';
-import PdfConvertService, { JobStatusSharedWithGrowi, JobStatus } from '../service/pdf-convert.js';
-declare class PdfCtrl {
-    private readonly pdfConvertService;
-    logger: Logger;
-    constructor(pdfConvertService: PdfConvertService);
-    syncJobStatus(jobId: string, expirationDateStr: string, growiJobStatus: JobStatusSharedWithGrowi): Promise<{
-        status: JobStatus;
-    }>;
-}
-export default PdfCtrl;

+ 0 - 59
apps/pdf-converter/dist/controllers/pdf.js

@@ -1,59 +0,0 @@
-import { __decorate, __metadata, __param } from "tslib";
-import { BodyParams, Logger } from '@tsed/common';
-import { Controller, Inject } from '@tsed/di';
-import { InternalServerError } from '@tsed/exceptions';
-import { Post, Returns, Enum, Description, } from '@tsed/schema';
-import PdfConvertService, { JobStatusSharedWithGrowi, JobStatus } from '../service/pdf-convert.js';
-let PdfCtrl = class PdfCtrl {
-    pdfConvertService;
-    logger;
-    constructor(pdfConvertService) {
-        this.pdfConvertService = pdfConvertService;
-    }
-    async syncJobStatus(jobId, expirationDateStr, growiJobStatus) {
-        const expirationDate = new Date(expirationDateStr);
-        try {
-            await this.pdfConvertService.registerOrUpdateJob(jobId, expirationDate, growiJobStatus);
-            const status = this.pdfConvertService.getJobStatus(jobId); // get status before cleanup
-            this.pdfConvertService.cleanUpJobList();
-            return { status };
-        }
-        catch (err) {
-            this.logger.error('Failed to register or update job', err);
-            throw new InternalServerError(err);
-        }
-    }
-};
-__decorate([
-    Inject(),
-    __metadata("design:type", Logger)
-], PdfCtrl.prototype, "logger", void 0);
-__decorate([
-    Post('/sync-job'),
-    (Returns(202).ContentType('application/json').Schema({
-        type: 'object',
-        properties: {
-            status: { type: 'string', enum: Object.values(JobStatus) },
-        },
-        required: ['status'],
-    })),
-    Returns(500),
-    Description(`
-    Sync job pdf convert status with GROWI.
-    Register or update job inside pdf-converter with given jobId, expirationDate, and status.
-    Return resulting status of job to GROWI.
-  `),
-    __param(0, BodyParams('jobId')),
-    __param(1, BodyParams('expirationDate')),
-    __param(2, BodyParams('status')),
-    __param(2, Enum(Object.values(JobStatusSharedWithGrowi))),
-    __metadata("design:type", Function),
-    __metadata("design:paramtypes", [String, String, String]),
-    __metadata("design:returntype", Promise)
-], PdfCtrl.prototype, "syncJobStatus", null);
-PdfCtrl = __decorate([
-    Controller('/pdf'),
-    __metadata("design:paramtypes", [PdfConvertService])
-], PdfCtrl);
-export default PdfCtrl;
-//# sourceMappingURL=pdf.js.map

+ 0 - 1
apps/pdf-converter/dist/controllers/pdf.js.map

@@ -1 +0,0 @@
-{"version":3,"file":"pdf.js","sourceRoot":"","sources":["../../src/controllers/pdf.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AAClD,OAAO,EAAE,UAAU,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAC9C,OAAO,EAAE,mBAAmB,EAAE,MAAM,kBAAkB,CAAC;AACvD,OAAO,EACL,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE,WAAW,GACjC,MAAM,cAAc,CAAC;AAEtB,OAAO,iBAAiB,EAAE,EAAE,wBAAwB,EAAE,SAAS,EAAE,MAAM,2BAA2B,CAAC;AAEnG,IACM,OAAO,GADb,MACM,OAAO;IAKkB;IAF3B,MAAM,CAAS;IAEjB,YAA6B,iBAAoC;QAApC,sBAAiB,GAAjB,iBAAiB,CAAmB;IAAG,CAAC;IAgB/D,AAAN,KAAK,CAAC,aAAa,CACI,KAAa,EACJ,iBAAyB,EACc,cAAwC;QAE7G,MAAM,cAAc,GAAG,IAAI,IAAI,CAAC,iBAAiB,CAAC,CAAC;QACnD,IAAI,CAAC;YACH,MAAM,IAAI,CAAC,iBAAiB,CAAC,mBAAmB,CAAC,KAAK,EAAE,cAAc,EAAE,cAAc,CAAC,CAAC;YACxF,MAAM,MAAM,GAAG,IAAI,CAAC,iBAAiB,CAAC,YAAY,CAAC,KAAK,CAAC,CAAC,CAAC,4BAA4B;YACvF,IAAI,CAAC,iBAAiB,CAAC,cAAc,EAAE,CAAC;YACxC,OAAO,EAAE,MAAM,EAAE,CAAC;QACpB,CAAC;QACD,OAAO,GAAG,EAAE,CAAC;YACX,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,kCAAkC,EAAE,GAAG,CAAC,CAAC;YAC3D,MAAM,IAAI,mBAAmB,CAAC,GAAG,CAAC,CAAC;QACrC,CAAC;IACH,CAAC;CAEF,CAAA;AApCG;IADD,MAAM,EAAE;8BACC,MAAM;uCAAC;AAkBX;IAdL,IAAI,CAAC,WAAW,CAAC;IACjB,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,WAAW,CAAC,kBAAkB,CAAC,CAAC,MAAM,CAAC;QACpD,IAAI,EAAE,QAAQ;QACd,UAAU,EAAE;YACV,MAAM,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,IAAI,EAAE,MAAM,CAAC,MAAM,CAAC,SAAS,CAAC,EAAE;SAC3D;QACD,QAAQ,EAAE,CAAC,QAAQ,CAAC;KACrB,CAAC,CAAC;IACF,OAAO,CAAC,GAAG,CAAC;IACZ,WAAW,CAAC;;;;GAIZ,CAAC;IAEC,WAAA,UAAU,CAAC,OAAO,CAAC,CAAA;IACnB,WAAA,UAAU,CAAC,gBAAgB,CAAC,CAAA;IAC5B,WAAA,UAAU,CAAC,QAAQ,CAAC,CAAA;IAAE,WAAA,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,wBAAwB,CAAC,CAAC,CAAA;;;;4CAarE;AArCG,OAAO;IADZ,UAAU,CAAC,MAAM,CAAC;qCAM+B,iBAAiB;GAL7D,OAAO,CAuCZ;AAED,eAAe,OAAO,CAAC"}

+ 0 - 10
apps/pdf-converter/dist/controllers/terminus.d.ts

@@ -1,10 +0,0 @@
-import { Logger } from '@tsed/common';
-import PdfConvertService from '../service/pdf-convert.js';
-declare class TerminusCtrl {
-    private readonly pdfConvertService;
-    logger: Logger;
-    constructor(pdfConvertService: PdfConvertService);
-    $onSignal(): Promise<void>;
-    $onShutdown(): void;
-}
-export default TerminusCtrl;

+ 0 - 28
apps/pdf-converter/dist/controllers/terminus.js

@@ -1,28 +0,0 @@
-import { __decorate, __metadata } from "tslib";
-import { Logger } from '@tsed/common';
-import { Inject, Injectable } from '@tsed/di';
-import PdfConvertService from '../service/pdf-convert.js';
-let TerminusCtrl = class TerminusCtrl {
-    pdfConvertService;
-    logger;
-    constructor(pdfConvertService) {
-        this.pdfConvertService = pdfConvertService;
-    }
-    async $onSignal() {
-        this.logger.info('Server is starting cleanup');
-        await this.pdfConvertService.closePuppeteerCluster();
-    }
-    $onShutdown() {
-        this.logger.info('Cleanup finished, server is shutting down');
-    }
-};
-__decorate([
-    Inject(),
-    __metadata("design:type", Logger)
-], TerminusCtrl.prototype, "logger", void 0);
-TerminusCtrl = __decorate([
-    Injectable(),
-    __metadata("design:paramtypes", [PdfConvertService])
-], TerminusCtrl);
-export default TerminusCtrl;
-//# sourceMappingURL=terminus.js.map

+ 0 - 1
apps/pdf-converter/dist/controllers/terminus.js.map

@@ -1 +0,0 @@
-{"version":3,"file":"terminus.js","sourceRoot":"","sources":["../../src/controllers/terminus.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AACtC,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AAE9C,OAAO,iBAAiB,MAAM,2BAA2B,CAAC;AAE1D,IACM,YAAY,GADlB,MACM,YAAY;IAKa;IAF3B,MAAM,CAAS;IAEjB,YAA6B,iBAAoC;QAApC,sBAAiB,GAAjB,iBAAiB,CAAmB;IAAG,CAAC;IAErE,KAAK,CAAC,SAAS;QACb,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,4BAA4B,CAAC,CAAC;QAC/C,MAAM,IAAI,CAAC,iBAAiB,CAAC,qBAAqB,EAAE,CAAC;IACvD,CAAC;IAED,WAAW;QACT,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,2CAA2C,CAAC,CAAC;IAChE,CAAC;CAEF,CAAA;AAbG;IADD,MAAM,EAAE;8BACC,MAAM;4CAAC;AAHb,YAAY;IADjB,UAAU,EAAE;qCAMqC,iBAAiB;GAL7D,YAAY,CAgBjB;AAED,eAAe,YAAY,CAAC"}

+ 0 - 1
apps/pdf-converter/dist/index.d.ts

@@ -1 +0,0 @@
-export {};

+ 0 - 23
apps/pdf-converter/dist/index.js

@@ -1,23 +0,0 @@
-import { $log } from '@tsed/common';
-import { PlatformExpress } from '@tsed/platform-express';
-import Server from './server.js';
-function hasProcessFlag(flag) {
-    return process.argv.join('').indexOf(flag) > -1;
-}
-async function bootstrap() {
-    try {
-        $log.debug('Start server...');
-        const platform = await PlatformExpress.bootstrap(Server);
-        await platform.listen();
-        $log.debug('Server initialized');
-        if (hasProcessFlag('ci')) {
-            $log.info('"--ci" flag is detected. Exit process.');
-            process.exit();
-        }
-    }
-    catch (error) {
-        $log.error(error);
-    }
-}
-bootstrap();
-//# sourceMappingURL=index.js.map

+ 0 - 1
apps/pdf-converter/dist/index.js.map

@@ -1 +0,0 @@
-{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,cAAc,CAAC;AACpC,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AAEzD,OAAO,MAAM,MAAM,aAAa,CAAC;AAEjC,SAAS,cAAc,CAAC,IAAY;IAClC,OAAO,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC,OAAO,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC;AAClD,CAAC;AAED,KAAK,UAAU,SAAS;IACtB,IAAI,CAAC;QACH,IAAI,CAAC,KAAK,CAAC,iBAAiB,CAAC,CAAC;QAC9B,MAAM,QAAQ,GAAG,MAAM,eAAe,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC;QAEzD,MAAM,QAAQ,CAAC,MAAM,EAAE,CAAC;QACxB,IAAI,CAAC,KAAK,CAAC,oBAAoB,CAAC,CAAC;QAEjC,IAAI,cAAc,CAAC,IAAI,CAAC,EAAE,CAAC;YACzB,IAAI,CAAC,IAAI,CAAC,wCAAwC,CAAC,CAAC;YACpD,OAAO,CAAC,IAAI,EAAE,CAAC;QACjB,CAAC;IACH,CAAC;IACD,OAAO,KAAK,EAAE,CAAC;QACb,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;IACpB,CAAC;AACH,CAAC;AAED,SAAS,EAAE,CAAC"}

+ 0 - 8
apps/pdf-converter/dist/server.d.ts

@@ -1,8 +0,0 @@
-import { PlatformApplication } from '@tsed/common';
-import '@tsed/swagger';
-import '@tsed/terminus';
-import '@tsed/platform-express';
-declare class Server {
-    app: PlatformApplication;
-}
-export default Server;

+ 0 - 41
apps/pdf-converter/dist/server.js

@@ -1,41 +0,0 @@
-import { __decorate, __metadata } from "tslib";
-import { PlatformApplication } from '@tsed/common';
-import { Configuration, Inject } from '@tsed/di';
-import express from 'express';
-import '@tsed/swagger';
-import '@tsed/terminus';
-import * as Controllers from './controllers/index.js';
-import '@tsed/platform-express';
-const PORT = Number(process.env.PORT || 3010);
-let Server = class Server {
-    app;
-};
-__decorate([
-    Inject(),
-    __metadata("design:type", PlatformApplication)
-], Server.prototype, "app", void 0);
-Server = __decorate([
-    Configuration({
-        port: PORT,
-        acceptMimes: ['application/json'],
-        mount: {
-            '/': [...Object.values(Controllers)],
-        },
-        middlewares: [
-            'json-parser',
-            express.json({ limit: '50mb' }),
-            express.urlencoded({ extended: true, limit: '50mb' }),
-        ],
-        swagger: [
-            {
-                path: '/v3/docs',
-                specVersion: '3.0.1',
-            },
-        ],
-        terminus: {
-            signals: ['SIGINT', 'SIGTERM'],
-        },
-    })
-], Server);
-export default Server;
-//# sourceMappingURL=server.js.map

+ 0 - 1
apps/pdf-converter/dist/server.js.map

@@ -1 +0,0 @@
-{"version":3,"file":"server.js","sourceRoot":"","sources":["../src/server.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,cAAc,CAAC;AACnD,OAAO,EAAE,aAAa,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AACjD,OAAO,OAAO,MAAM,SAAS,CAAC;AAC9B,OAAO,eAAe,CAAC;AACvB,OAAO,gBAAgB,CAAC;AAExB,OAAO,KAAK,WAAW,MAAM,wBAAwB,CAAC;AAEtD,OAAO,wBAAwB,CAAC;AAEhC,MAAM,IAAI,GAAG,MAAM,CAAC,OAAO,CAAC,GAAG,CAAC,IAAI,IAAI,IAAI,CAAC,CAAC;AAuB9C,IAAM,MAAM,GAAZ,MAAM,MAAM;IAGR,GAAG,CAAsB;CAE5B,CAAA;AAFG;IADD,MAAM,EAAE;8BACF,mBAAmB;mCAAC;AAHvB,MAAM;IArBX,aAAa,CAAC;QACb,IAAI,EAAE,IAAI;QACV,WAAW,EAAE,CAAC,kBAAkB,CAAC;QACjC,KAAK,EAAE;YACL,GAAG,EAAE,CAAC,GAAG,MAAM,CAAC,MAAM,CAAC,WAAW,CAAC,CAAC;SACrC;QACD,WAAW,EAAE;YACX,aAAa;YACb,OAAO,CAAC,IAAI,CAAC,EAAE,KAAK,EAAE,MAAM,EAAE,CAAC;YAC/B,OAAO,CAAC,UAAU,CAAC,EAAE,QAAQ,EAAE,IAAI,EAAE,KAAK,EAAE,MAAM,EAAE,CAAC;SACtD;QACD,OAAO,EAAE;YACP;gBACE,IAAI,EAAE,UAAU;gBAChB,WAAW,EAAE,OAAO;aACrB;SACF;QACD,QAAQ,EAAE;YACR,OAAO,EAAE,CAAC,QAAQ,EAAE,SAAS,CAAC;SAC/B;KACF,CAAC;GACI,MAAM,CAKX;AAED,eAAe,MAAM,CAAC"}

+ 0 - 81
apps/pdf-converter/dist/service/pdf-convert.d.ts

@@ -1,81 +0,0 @@
-import { Logger, OnInit } from '@tsed/common';
-export declare const JobStatusSharedWithGrowi: {
-    readonly HTML_EXPORT_IN_PROGRESS: "HTML_EXPORT_IN_PROGRESS";
-    readonly HTML_EXPORT_DONE: "HTML_EXPORT_DONE";
-    readonly FAILED: "FAILED";
-};
-export declare const JobStatus: {
-    readonly PDF_EXPORT_DONE: "PDF_EXPORT_DONE";
-    readonly HTML_EXPORT_IN_PROGRESS: "HTML_EXPORT_IN_PROGRESS";
-    readonly HTML_EXPORT_DONE: "HTML_EXPORT_DONE";
-    readonly FAILED: "FAILED";
-};
-export type JobStatusSharedWithGrowi = typeof JobStatusSharedWithGrowi[keyof typeof JobStatusSharedWithGrowi];
-export type JobStatus = typeof JobStatus[keyof typeof JobStatus];
-declare class PdfConvertService implements OnInit {
-    private puppeteerCluster;
-    private maxConcurrency;
-    private convertRetryLimit;
-    private tmpOutputRootDir;
-    private tmpHtmlDir;
-    private jobList;
-    logger: Logger;
-    $onInit(): Promise<void>;
-    /**
-     * Register or update job inside jobList with given jobId, expirationDate, and status.
-     * If job is new, start reading html files and convert them to pdf.
-     * @param jobId id of PageBulkExportJob
-     * @param expirationDate expiration date of job
-     * @param status status of job
-     */
-    registerOrUpdateJob(jobId: string, expirationDate: Date, status: JobStatusSharedWithGrowi): Promise<void>;
-    /**
-     * Get job status
-     * @param jobId id of PageBulkExportJob
-     * @returns job status
-     */
-    getJobStatus(jobId: string): JobStatus;
-    /**
-     * Clean up job list by removing expired jobs, finished jobs, and failed jobs
-     */
-    cleanUpJobList(): void;
-    /**
-     * Close puppeteer cluster
-     */
-    closePuppeteerCluster(): Promise<void>;
-    private isJobCompleted;
-    /**
-     * Read html files from shared fs path, convert them to pdf, and save them to shared fs path.
-     * Repeat this until all html files are converted to pdf or job fails.
-     * @param jobId id of PageBulkExportJob
-     */
-    private readHtmlAndConvertToPdfUntilFinish;
-    /**
-     * Get readable stream that reads html files from shared fs path
-     * @param jobId id of PageBulkExportJob
-     * @returns readable stream
-     */
-    private getHtmlReadable;
-    /**
-     * Get writable stream that converts html to pdf, and save it to shared fs path
-     * @returns writable stream
-     */
-    private getPdfWritable;
-    /**
-     * Convert html to pdf. Retry up to convertRetryLimit if failed.
-     * @param htmlString html to convert to pdf
-     * @returns converted pdf
-     */
-    private convertHtmlToPdf;
-    /**
-     * Initialize puppeteer cluster
-     */
-    private initPuppeteerCluster;
-    /**
-     * Get parent path from given path
-     * @param path target path
-     * @returns parent path
-     */
-    private getParentPath;
-}
-export default PdfConvertService;

+ 0 - 240
apps/pdf-converter/dist/service/pdf-convert.js

@@ -1,240 +0,0 @@
-import { __decorate, __metadata } from "tslib";
-import fs from 'fs';
-import path from 'path';
-import { Readable, Writable } from 'stream';
-import { pipeline as pipelinePromise } from 'stream/promises';
-import { Logger } from '@tsed/common';
-import { Inject, Service } from '@tsed/di';
-import { Cluster } from 'puppeteer-cluster';
-export const JobStatusSharedWithGrowi = {
-    HTML_EXPORT_IN_PROGRESS: 'HTML_EXPORT_IN_PROGRESS',
-    HTML_EXPORT_DONE: 'HTML_EXPORT_DONE',
-    FAILED: 'FAILED',
-};
-export const JobStatus = {
-    ...JobStatusSharedWithGrowi,
-    PDF_EXPORT_DONE: 'PDF_EXPORT_DONE',
-};
-let PdfConvertService = class PdfConvertService {
-    puppeteerCluster;
-    maxConcurrency = 1;
-    convertRetryLimit = 5;
-    tmpOutputRootDir = '/tmp/page-bulk-export';
-    tmpHtmlDir = `${this.tmpOutputRootDir}/html`;
-    jobList = {};
-    logger;
-    async $onInit() {
-        if (process.env.SWAGGER_GENERATION === 'true')
-            return;
-        await this.initPuppeteerCluster();
-    }
-    /**
-     * Register or update job inside jobList with given jobId, expirationDate, and status.
-     * If job is new, start reading html files and convert them to pdf.
-     * @param jobId id of PageBulkExportJob
-     * @param expirationDate expiration date of job
-     * @param status status of job
-     */
-    async registerOrUpdateJob(jobId, expirationDate, status) {
-        const isJobNew = !(jobId in this.jobList);
-        if (isJobNew) {
-            this.jobList[jobId] = { expirationDate, status };
-        }
-        else {
-            const jobInfo = this.jobList[jobId];
-            jobInfo.expirationDate = expirationDate;
-            if (!this.isJobCompleted(jobId)) {
-                jobInfo.status = status;
-            }
-        }
-        if (status === JobStatus.FAILED) {
-            this.jobList[jobId].currentStream?.destroy(new Error('job failed'));
-        }
-        if (isJobNew && status !== JobStatus.FAILED) {
-            this.readHtmlAndConvertToPdfUntilFinish(jobId);
-        }
-    }
-    /**
-     * Get job status
-     * @param jobId id of PageBulkExportJob
-     * @returns job status
-     */
-    getJobStatus(jobId) {
-        if (!(jobId in this.jobList))
-            return JobStatus.FAILED;
-        return this.jobList[jobId].status;
-    }
-    /**
-     * Clean up job list by removing expired jobs, finished jobs, and failed jobs
-     */
-    cleanUpJobList() {
-        const now = new Date();
-        for (const jobId of Object.keys(this.jobList)) {
-            const job = this.jobList[jobId];
-            if (now > job.expirationDate || this.isJobCompleted(jobId)) {
-                job.currentStream?.destroy(new Error('job expired'));
-                delete this.jobList[jobId];
-            }
-        }
-    }
-    /**
-     * Close puppeteer cluster
-     */
-    async closePuppeteerCluster() {
-        if (this.puppeteerCluster == null) {
-            this.logger.info('No puppeteer cluster running for closure');
-            return;
-        }
-        this.logger.info('Closing puppeteer cluster...');
-        await this.puppeteerCluster.idle();
-        await this.puppeteerCluster.close();
-    }
-    isJobCompleted(jobId) {
-        if (this.jobList[jobId] == null)
-            return true;
-        return this.jobList[jobId].status === JobStatus.PDF_EXPORT_DONE || this.jobList[jobId].status === JobStatus.FAILED;
-    }
-    /**
-     * Read html files from shared fs path, convert them to pdf, and save them to shared fs path.
-     * Repeat this until all html files are converted to pdf or job fails.
-     * @param jobId id of PageBulkExportJob
-     */
-    async readHtmlAndConvertToPdfUntilFinish(jobId) {
-        while (!this.isJobCompleted(jobId)) {
-            // eslint-disable-next-line no-await-in-loop
-            await new Promise(resolve => setTimeout(resolve, 10 * 1000));
-            try {
-                if (new Date() > this.jobList[jobId].expirationDate) {
-                    throw new Error('Job expired');
-                }
-                const htmlReadable = this.getHtmlReadable(jobId);
-                const pdfWritable = this.getPdfWritable();
-                this.jobList[jobId].currentStream = htmlReadable;
-                // eslint-disable-next-line no-await-in-loop
-                await pipelinePromise(htmlReadable, pdfWritable);
-                this.jobList[jobId].currentStream = undefined;
-            }
-            catch (err) {
-                this.logger.error('Failed to convert html to pdf', err);
-                this.jobList[jobId].status = JobStatus.FAILED;
-                this.jobList[jobId].currentStream?.destroy(new Error('Failed to convert html to pdf'));
-                break;
-            }
-        }
-    }
-    /**
-     * Get readable stream that reads html files from shared fs path
-     * @param jobId id of PageBulkExportJob
-     * @returns readable stream
-     */
-    getHtmlReadable(jobId) {
-        const htmlFileEntries = fs.readdirSync(path.join(this.tmpHtmlDir, jobId), { recursive: true, withFileTypes: true }).filter(entry => entry.isFile());
-        let index = 0;
-        const jobList = this.jobList;
-        return new Readable({
-            objectMode: true,
-            async read() {
-                if (index >= htmlFileEntries.length) {
-                    if (jobList[jobId].status === JobStatus.HTML_EXPORT_DONE && htmlFileEntries.length === 0) {
-                        jobList[jobId].status = JobStatus.PDF_EXPORT_DONE;
-                    }
-                    this.push(null);
-                    return;
-                }
-                const entry = htmlFileEntries[index];
-                const htmlFilePath = path.join(entry.parentPath, entry.name);
-                const htmlString = await fs.promises.readFile(htmlFilePath, 'utf-8');
-                this.push({ htmlString, htmlFilePath });
-                index += 1;
-            },
-        });
-    }
-    /**
-     * Get writable stream that converts html to pdf, and save it to shared fs path
-     * @returns writable stream
-     */
-    getPdfWritable() {
-        return new Writable({
-            objectMode: true,
-            write: async (pageInfo, encoding, callback) => {
-                const fileOutputPath = pageInfo.htmlFilePath.replace(new RegExp(`^${this.tmpHtmlDir}`), this.tmpOutputRootDir).replace(/\.html$/, '.pdf');
-                const fileOutputParentPath = this.getParentPath(fileOutputPath);
-                try {
-                    const pdfBody = await this.convertHtmlToPdf(pageInfo.htmlString);
-                    await fs.promises.mkdir(fileOutputParentPath, { recursive: true });
-                    await fs.promises.writeFile(fileOutputPath, pdfBody);
-                    await fs.promises.rm(pageInfo.htmlFilePath, { force: true });
-                }
-                catch (err) {
-                    callback(err);
-                    return;
-                }
-                callback();
-            },
-        });
-    }
-    /**
-     * Convert html to pdf. Retry up to convertRetryLimit if failed.
-     * @param htmlString html to convert to pdf
-     * @returns converted pdf
-     */
-    async convertHtmlToPdf(htmlString) {
-        const executeConvert = async (retries) => {
-            try {
-                return this.puppeteerCluster.execute(htmlString);
-            }
-            catch (err) {
-                if (retries > 0) {
-                    this.logger.error('Failed to convert markdown to pdf. Retrying...', err);
-                    return executeConvert(retries - 1);
-                }
-                throw err;
-            }
-        };
-        const result = await executeConvert(this.convertRetryLimit);
-        return result;
-    }
-    /**
-     * Initialize puppeteer cluster
-     */
-    async initPuppeteerCluster() {
-        this.puppeteerCluster = await Cluster.launch({
-            concurrency: Cluster.CONCURRENCY_PAGE,
-            maxConcurrency: this.maxConcurrency,
-            workerCreationDelay: 10000,
-        });
-        await this.puppeteerCluster.task(async ({ page, data: htmlString }) => {
-            await page.setContent(htmlString, { waitUntil: 'domcontentloaded' });
-            await page.emulateMediaType('screen');
-            const pdfResult = await page.pdf({
-                margin: {
-                    top: '100px', right: '50px', bottom: '100px', left: '50px',
-                },
-                printBackground: true,
-                format: 'A4',
-            });
-            return pdfResult;
-        });
-    }
-    /**
-     * Get parent path from given path
-     * @param path target path
-     * @returns parent path
-     */
-    getParentPath(path) {
-        const parentPath = path.split('/').slice(0, -1).join('/');
-        if (parentPath === '' || parentPath === '/') {
-            return '/';
-        }
-        return parentPath;
-    }
-};
-__decorate([
-    Inject(),
-    __metadata("design:type", Logger)
-], PdfConvertService.prototype, "logger", void 0);
-PdfConvertService = __decorate([
-    Service()
-], PdfConvertService);
-export default PdfConvertService;
-//# sourceMappingURL=pdf-convert.js.map

Datei-Diff unterdrückt, da er zu groß ist
+ 0 - 0
apps/pdf-converter/dist/service/pdf-convert.js.map


+ 0 - 149
apps/pdf-converter/specs/v3/docs/swagger.json

@@ -1,149 +0,0 @@
-{
-  "openapi": "3.0.1",
-  "info": {
-    "title": "Api documentation",
-    "version": "1.0.0"
-  },
-  "paths": {
-    "/pdf/sync-job": {
-      "post": {
-        "responses": {
-          "202": {
-            "content": {
-              "application/json": {
-                "schema": {
-                  "type": "object",
-                  "properties": {
-                    "status": {
-                      "type": "string",
-                      "enum": [
-                        "HTML_EXPORT_IN_PROGRESS",
-                        "HTML_EXPORT_DONE",
-                        "FAILED",
-                        "PDF_EXPORT_DONE"
-                      ]
-                    }
-                  },
-                  "required": [
-                    "status"
-                  ]
-                }
-              }
-            },
-            "description": "Accepted"
-          },
-          "500": {
-            "content": {
-              "application/json": {
-                "schema": {
-                  "$ref": "#/components/schemas/InternalServerError"
-                }
-              }
-            },
-            "description": "Internal Server Error"
-          }
-        },
-        "description": "\n    Sync job pdf convert status with GROWI.\n    Register or update job inside pdf-converter with given jobId, expirationDate, and status.\n    Return resulting status of job to GROWI.\n  ",
-        "parameters": [],
-        "requestBody": {
-          "required": false,
-          "content": {
-            "application/json": {
-              "schema": {
-                "properties": {
-                  "jobId": {
-                    "type": "string"
-                  },
-                  "expirationDate": {
-                    "type": "string"
-                  },
-                  "status": {
-                    "type": "string",
-                    "enum": [
-                      "HTML_EXPORT_IN_PROGRESS",
-                      "HTML_EXPORT_DONE",
-                      "FAILED"
-                    ]
-                  }
-                },
-                "type": "object"
-              }
-            }
-          }
-        },
-        "tags": [
-          "PdfCtrl"
-        ],
-        "operationId": "pdfCtrlSyncJobStatus"
-      }
-    }
-  },
-  "tags": [
-    {
-      "name": "PdfCtrl"
-    }
-  ],
-  "components": {
-    "schemas": {
-      "InternalServerError": {
-        "type": "object",
-        "properties": {
-          "name": {
-            "type": "string",
-            "minLength": 1,
-            "description": "The error name",
-            "example": "INTERNAL_SERVER_ERROR",
-            "default": "INTERNAL_SERVER_ERROR"
-          },
-          "message": {
-            "type": "string",
-            "minLength": 1,
-            "description": "An error message"
-          },
-          "status": {
-            "type": "number",
-            "description": "The status code of the exception",
-            "example": 500,
-            "default": 500
-          },
-          "errors": {
-            "type": "array",
-            "items": {
-              "$ref": "#/components/schemas/GenericError"
-            },
-            "description": "A list of related errors"
-          },
-          "stack": {
-            "type": "string",
-            "description": "The stack trace (only in development mode)"
-          }
-        },
-        "required": [
-          "name",
-          "message",
-          "status"
-        ]
-      },
-      "GenericError": {
-        "type": "object",
-        "properties": {
-          "name": {
-            "type": "string",
-            "minLength": 1,
-            "description": "The error name"
-          },
-          "message": {
-            "type": "string",
-            "minLength": 1,
-            "description": "An error message"
-          }
-        },
-        "additionalProperties": true,
-        "required": [
-          "name",
-          "message"
-        ]
-      }
-    }
-  }
-}

+ 0 - 106
apps/pdf-converter/specs/v3/docs/swagger.yaml

@@ -1,106 +0,0 @@
-openapi: 3.0.1
-info:
-  title: Api documentation
-  version: 1.0.0
-paths:
-  /pdf/sync-job:
-    post:
-      responses:
-        '202':
-          content:
-            application/json:
-              schema:
-                type: object
-                properties:
-                  status:
-                    type: string
-                    enum:
-                      - HTML_EXPORT_IN_PROGRESS
-                      - HTML_EXPORT_DONE
-                      - FAILED
-                      - PDF_EXPORT_DONE
-                required:
-                  - status
-          description: Accepted
-        '500':
-          content:
-            application/json:
-              schema:
-                $ref: '#/components/schemas/InternalServerError'
-          description: Internal Server Error
-      description: |2-
-
-            Sync job pdf convert status with GROWI.
-            Register or update job inside pdf-converter with given jobId, expirationDate, and status.
-            Return resulting status of job to GROWI.
-          
-      parameters: []
-      requestBody:
-        required: false
-        content:
-          application/json:
-            schema:
-              properties:
-                jobId:
-                  type: string
-                expirationDate:
-                  type: string
-                status:
-                  type: string
-                  enum:
-                    - HTML_EXPORT_IN_PROGRESS
-                    - HTML_EXPORT_DONE
-                    - FAILED
-              type: object
-      tags:
-        - PdfCtrl
-      operationId: pdfCtrlSyncJobStatus
-tags:
-  - name: PdfCtrl
-components:
-  schemas:
-    InternalServerError:
-      type: object
-      properties:
-        name:
-          type: string
-          minLength: 1
-          description: The error name
-          example: INTERNAL_SERVER_ERROR
-          default: INTERNAL_SERVER_ERROR
-        message:
-          type: string
-          minLength: 1
-          description: An error message
-        status:
-          type: number
-          description: The status code of the exception
-          example: 500
-          default: 500
-        errors:
-          type: array
-          items:
-            $ref: '#/components/schemas/GenericError'
-          description: A list of related errors
-        stack:
-          type: string
-          description: The stack trace (only in development mode)
-      required:
-        - name
-        - message
-        - status
-    GenericError:
-      type: object
-      properties:
-        name:
-          type: string
-          minLength: 1
-          description: The error name
-        message:
-          type: string
-          minLength: 1
-          description: An error message
-      additionalProperties: true
-      required:
-        - name
-        - message

Einige Dateien werden nicht angezeigt, da zu viele Dateien in diesem Diff geändert wurden.