Просмотр исходного кода

improve the way to instanciate PageOperationService

Yuki Takei 6 месяцев назад
Родитель
Сommit
4b0e02fe42
2 измененных файлов с 18 добавлено и 8 удалено
  1. 3 6
      apps/app/src/server/crowi/index.js
  2. 15 2
      apps/app/src/server/service/page-operation.ts

+ 3 - 6
apps/app/src/server/crowi/index.js

@@ -38,7 +38,7 @@ import { InstallerService } from '../service/installer';
 import { normalizeData } from '../service/normalize-data';
 import { normalizeData } from '../service/normalize-data';
 import PageService from '../service/page';
 import PageService from '../service/page';
 import PageGrantService from '../service/page-grant';
 import PageGrantService from '../service/page-grant';
-import PageOperationService from '../service/page-operation';
+import instanciatePageOperationService from '../service/page-operation';
 import PassportService from '../service/passport';
 import PassportService from '../service/passport';
 import SearchService from '../service/search';
 import SearchService from '../service/search';
 import { SlackIntegrationService } from '../service/slack-integration';
 import { SlackIntegrationService } from '../service/slack-integration';
@@ -91,7 +91,7 @@ class Crowi {
   /** @type {import('../service/page-grant').default} */
   /** @type {import('../service/page-grant').default} */
   pageGrantService;
   pageGrantService;
 
 
-  /** @type {import('../service/page-operation').default} */
+  /** @type {import('../service/page-operation').IPageOperationService} */
   pageOperationService;
   pageOperationService;
 
 
   /** @type {PassportService} */
   /** @type {PassportService} */
@@ -734,10 +734,7 @@ Crowi.prototype.setupPageService = async function() {
     this.pageService = new PageService(this);
     this.pageService = new PageService(this);
     await this.pageService.createTtlIndex();
     await this.pageService.createTtlIndex();
   }
   }
-  if (this.pageOperationService == null) {
-    this.pageOperationService = new PageOperationService(this);
-    await this.pageOperationService.init();
-  }
+  this.pageOperationService = instanciatePageOperationService(this);
 };
 };
 
 
 Crowi.prototype.setupInAppNotificationService = async function() {
 Crowi.prototype.setupInAppNotificationService = async function() {

+ 15 - 2
apps/app/src/server/service/page-operation.ts

@@ -25,7 +25,15 @@ const {
   Duplicate, Delete, DeleteCompletely, Revert, NormalizeParent,
   Duplicate, Delete, DeleteCompletely, Revert, NormalizeParent,
 } = PageActionType;
 } = PageActionType;
 
 
-class PageOperationService {
+export interface IPageOperationService {
+  generateProcessInfo(pageOperations: PageOperationDocument[]): IPageOperationProcessInfo;
+  canOperate(isRecursively: boolean, fromPathToOp: string | null, toPathToOp: string | null): Promise<boolean>;
+  autoUpdateExpiryDate(operationId: ObjectIdLike): NodeJS.Timeout;
+  clearAutoUpdateInterval(timerObj: NodeJS.Timeout): void;
+  getAncestorsPathsByFromAndToPath(fromPath: string, toPath: string): string[];
+}
+
+class PageOperationService implements IPageOperationService {
 
 
   crowi: Crowi;
   crowi: Crowi;
 
 
@@ -201,4 +209,9 @@ class PageOperationService {
 
 
 }
 }
 
 
-export default PageOperationService;
+// eslint-disable-next-line import/no-mutable-exports
+export let pageOperationService: PageOperationService | undefined; // singleton instance
+export default function instanciate(crowi: Crowi): PageOperationService {
+  pageOperationService = new PageOperationService(crowi);
+  return pageOperationService;
+}