소스 검색

refactor orgId appId params

Futa Arai 10 달 전
부모
커밋
ed5495493b

+ 4 - 7
apps/app/src/features/page-bulk-export/server/service/page-bulk-export-job-cron/index.ts

@@ -104,21 +104,18 @@ class PageBulkExportJobCronService extends CronService implements IPageBulkExpor
    */
   getTmpOutputDir(pageBulkExportJob: PageBulkExportJobDocument, isHtmlPath = false): string {
     const isGrowiCloud = configManager.getConfig('app:growiCloudUri') != null;
-    const appId = configManager.getConfig('app:growiAppIdForCloud');
-    const orgId = configManager.getConfig('app:growiOrgIdForCloud');
+    const appId = configManager.getConfig('app:growiAppIdForCloud')?.toString();
+    const orgId = configManager.getConfig('app:growiOrgIdForCloud')?.toString();
     const jobId = pageBulkExportJob._id.toString();
 
     if (isGrowiCloud) {
       if (appId == null || orgId == null) {
         throw new Error('appId and orgId is required for bulk export on GROWI.cloud');
       }
-      const basePath = isHtmlPath ? path.join(this.tmpOutputRootDir, 'html') : this.tmpOutputRootDir;
-      return path.join(basePath, jobId, orgId.toString(), appId.toString());
     }
 
-    return isHtmlPath
-      ? path.join(this.tmpOutputRootDir, 'html', jobId)
-      : path.join(this.tmpOutputRootDir, jobId);
+    const basePath = isHtmlPath ? path.join(this.tmpOutputRootDir, 'html') : this.tmpOutputRootDir;
+    return path.join(basePath, orgId ?? '', appId ?? '', jobId);
   }
 
   /**

+ 2 - 2
apps/pdf-converter/src/controllers/pdf.ts

@@ -28,11 +28,11 @@ class PdfCtrl {
     Return resulting status of job to GROWI.
   `)
   async syncJobStatus(
-    @BodyParams('orgId') orgId: string | undefined,
-    @BodyParams('appId') appId: string | undefined,
     @Required() @BodyParams('jobId') jobId: string,
     @Required() @BodyParams('expirationDate') expirationDateStr: string,
     @Required() @BodyParams('status') @Enum(Object.values(JobStatusSharedWithGrowi)) growiJobStatus: JobStatusSharedWithGrowi,
+    @BodyParams('orgId') orgId?: string,
+    @BodyParams('appId') appId?: string,
   ): Promise<{ status: JobStatus } | undefined> {
     const expirationDate = new Date(expirationDateStr);
     try {

+ 13 - 9
apps/pdf-converter/src/service/pdf-convert.ts

@@ -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;