|
|
@@ -59,14 +59,18 @@ class PdfConvertService implements OnInit {
|
|
|
/**
|
|
|
* 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 orgId organization ID for GROWI.cloud
|
|
|
- * @param appId application ID for GROWI.cloud
|
|
|
* @param jobId PageBulkExportJob ID
|
|
|
* @param expirationDate expiration date of job
|
|
|
* @param status status of job
|
|
|
+ * @param orgId organization ID for GROWI.cloud
|
|
|
+ * @param appId application ID for GROWI.cloud
|
|
|
*/
|
|
|
async registerOrUpdateJob(
|
|
|
- orgId: string | undefined, appId: string | undefined, jobId: string, expirationDate: Date, status: JobStatusSharedWithGrowi,
|
|
|
+ jobId: string,
|
|
|
+ expirationDate: Date,
|
|
|
+ status: JobStatusSharedWithGrowi,
|
|
|
+ orgId?: string,
|
|
|
+ appId?: string,
|
|
|
): Promise<void> {
|
|
|
const isJobNew = !(jobId in this.jobList);
|
|
|
|
|
|
@@ -87,7 +91,7 @@ class PdfConvertService implements OnInit {
|
|
|
}
|
|
|
|
|
|
if (isJobNew && status !== JobStatus.FAILED) {
|
|
|
- this.readHtmlAndConvertToPdfUntilFinish(orgId, appId, jobId);
|
|
|
+ this.readHtmlAndConvertToPdfUntilFinish(jobId, orgId, appId);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -138,11 +142,11 @@ class PdfConvertService implements OnInit {
|
|
|
/**
|
|
|
* 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 PageBulkExportJob ID
|
|
|
* @param orgId organization ID for GROWI.cloud
|
|
|
* @param appId application ID for GROWI.cloud
|
|
|
- * @param jobId PageBulkExportJob ID
|
|
|
*/
|
|
|
- private async readHtmlAndConvertToPdfUntilFinish(orgId: string | undefined, appId: string | undefined, jobId: string): Promise<void> {
|
|
|
+ private async readHtmlAndConvertToPdfUntilFinish(jobId: string, orgId?: string, appId?: string): Promise<void> {
|
|
|
while (!this.isJobCompleted(jobId)) {
|
|
|
// eslint-disable-next-line no-await-in-loop
|
|
|
await new Promise(resolve => setTimeout(resolve, 10 * 1000));
|
|
|
@@ -152,7 +156,7 @@ class PdfConvertService implements OnInit {
|
|
|
throw new Error('Job expired');
|
|
|
}
|
|
|
|
|
|
- const htmlReadable = this.getHtmlReadable(orgId, appId, jobId);
|
|
|
+ const htmlReadable = this.getHtmlReadable(jobId, orgId, appId);
|
|
|
const pdfWritable = this.getPdfWritable();
|
|
|
this.jobList[jobId].currentStream = htmlReadable;
|
|
|
|
|
|
@@ -171,12 +175,12 @@ class PdfConvertService implements OnInit {
|
|
|
|
|
|
/**
|
|
|
* Get readable stream that reads html files from shared fs path
|
|
|
+ * @param jobId PageBulkExportJob ID
|
|
|
* @param orgId organization ID for GROWI.cloud
|
|
|
* @param appId application ID for GROWI.cloud
|
|
|
- * @param jobId PageBulkExportJob ID
|
|
|
* @returns readable stream
|
|
|
*/
|
|
|
- private getHtmlReadable(orgId: string | undefined, appId: string | undefined, jobId: string): Readable {
|
|
|
+ private getHtmlReadable(jobId: string, orgId?: string, appId?: string): Readable {
|
|
|
const jobHtmlDir = path.join(this.tmpHtmlDir, orgId ?? '', appId ?? '', jobId);
|
|
|
const htmlFileEntries = fs.readdirSync(jobHtmlDir, { recursive: true, withFileTypes: true }).filter(entry => entry.isFile());
|
|
|
let index = 0;
|