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

import configManager statically

Yuki Takei 1 год назад
Родитель
Сommit
5cf6d9bb3e

+ 6 - 11
apps/app/src/server/service/customize.ts

@@ -12,7 +12,7 @@ import type Crowi from '../crowi';
 import S2sMessage from '../models/vo/s2s-message';
 import S2sMessage from '../models/vo/s2s-message';
 
 
 
 
-import type { IConfigManagerForApp } from './config-manager';
+import { configManager } from './config-manager';
 import type { S2sMessageHandlable } from './s2s-messaging/handlable';
 import type { S2sMessageHandlable } from './s2s-messaging/handlable';
 
 
 
 
@@ -24,8 +24,6 @@ const logger = loggerFactory('growi:service:CustomizeService');
  */
  */
 class CustomizeService implements S2sMessageHandlable {
 class CustomizeService implements S2sMessageHandlable {
 
 
-  configManager: IConfigManagerForApp;
-
   s2sMessagingService: any;
   s2sMessagingService: any;
 
 
   appService: any;
   appService: any;
@@ -43,7 +41,6 @@ class CustomizeService implements S2sMessageHandlable {
   forcedColorScheme?: ColorScheme;
   forcedColorScheme?: ColorScheme;
 
 
   constructor(crowi: Crowi) {
   constructor(crowi: Crowi) {
-    this.configManager = crowi.configManager;
     this.s2sMessagingService = crowi.s2sMessagingService;
     this.s2sMessagingService = crowi.s2sMessagingService;
     this.appService = crowi.appService;
     this.appService = crowi.appService;
   }
   }
@@ -64,8 +61,6 @@ class CustomizeService implements S2sMessageHandlable {
    * @inheritdoc
    * @inheritdoc
    */
    */
   async handleS2sMessage(s2sMessage) {
   async handleS2sMessage(s2sMessage) {
-    const { configManager } = this;
-
     logger.info('Reset customized value by pubsub notification');
     logger.info('Reset customized value by pubsub notification');
     await configManager.loadConfigs();
     await configManager.loadConfigs();
     this.initCustomCss();
     this.initCustomCss();
@@ -92,7 +87,7 @@ class CustomizeService implements S2sMessageHandlable {
    * initialize custom css strings
    * initialize custom css strings
    */
    */
   initCustomCss() {
   initCustomCss() {
-    const rawCss = this.configManager.getConfig('customize:css') || '';
+    const rawCss = configManager.getConfig('customize:css') || '';
 
 
     // uglify and store
     // uglify and store
     this.customCss = uglifycss.processString(rawCss);
     this.customCss = uglifycss.processString(rawCss);
@@ -105,15 +100,15 @@ class CustomizeService implements S2sMessageHandlable {
   }
   }
 
 
   getCustomScript() {
   getCustomScript() {
-    return this.configManager.getConfig('customize:script');
+    return configManager.getConfig('customize:script');
   }
   }
 
 
   getCustomNoscript() {
   getCustomNoscript() {
-    return this.configManager.getConfig('customize:noscript');
+    return configManager.getConfig('customize:noscript');
   }
   }
 
 
   initCustomTitle() {
   initCustomTitle() {
-    let configValue = this.configManager.getConfig('customize:title');
+    let configValue = configManager.getConfig('customize:title');
 
 
     if (configValue == null || configValue.trim().length === 0) {
     if (configValue == null || configValue.trim().length === 0) {
       configValue = '{{pagename}} - {{sitename}}';
       configValue = '{{pagename}} - {{sitename}}';
@@ -125,7 +120,7 @@ class CustomizeService implements S2sMessageHandlable {
   }
   }
 
 
   async initGrowiTheme(): Promise<void> {
   async initGrowiTheme(): Promise<void> {
-    const theme = this.configManager.getConfig('customize:theme');
+    const theme = configManager.getConfig('customize:theme');
 
 
     this.theme = theme;
     this.theme = theme;
 
 

+ 1 - 6
apps/app/src/server/service/file-uploader-switch.ts

@@ -3,7 +3,7 @@ import loggerFactory from '~/utils/logger';
 import type Crowi from '../crowi';
 import type Crowi from '../crowi';
 import S2sMessage from '../models/vo/s2s-message';
 import S2sMessage from '../models/vo/s2s-message';
 
 
-import type { IConfigManagerForApp } from './config-manager';
+import { configManager } from './config-manager';
 import type { S2sMessagingService } from './s2s-messaging/base';
 import type { S2sMessagingService } from './s2s-messaging/base';
 import type { S2sMessageHandlable } from './s2s-messaging/handlable';
 import type { S2sMessageHandlable } from './s2s-messaging/handlable';
 
 
@@ -13,15 +13,12 @@ class FileUploaderSwitch implements S2sMessageHandlable {
 
 
   crowi: Crowi;
   crowi: Crowi;
 
 
-  configManager: IConfigManagerForApp;
-
   s2sMessagingService: S2sMessagingService;
   s2sMessagingService: S2sMessagingService;
 
 
   lastLoadedAt?: Date;
   lastLoadedAt?: Date;
 
 
   constructor(crowi: Crowi) {
   constructor(crowi: Crowi) {
     this.crowi = crowi;
     this.crowi = crowi;
-    this.configManager = crowi.configManager;
     this.s2sMessagingService = crowi.s2sMessagingService;
     this.s2sMessagingService = crowi.s2sMessagingService;
   }
   }
 
 
@@ -41,8 +38,6 @@ class FileUploaderSwitch implements S2sMessageHandlable {
    * @inheritdoc
    * @inheritdoc
    */
    */
   async handleS2sMessage(s2sMessage) {
   async handleS2sMessage(s2sMessage) {
-    const { configManager } = this;
-
     logger.info('Reset fileupload service by pubsub notification');
     logger.info('Reset fileupload service by pubsub notification');
     await configManager.loadConfigs();
     await configManager.loadConfigs();
     await this.crowi.setUpFileUpload(true);
     await this.crowi.setUpFileUpload(true);

+ 10 - 13
apps/app/src/server/service/slack-integration.ts

@@ -19,7 +19,7 @@ import S2sMessage from '../models/vo/s2s-message';
 import { SlackCommandHandlerError } from '../models/vo/slack-command-handler-error';
 import { SlackCommandHandlerError } from '../models/vo/slack-command-handler-error';
 import { slackLegacyUtilFactory } from '../util/slack-legacy';
 import { slackLegacyUtilFactory } from '../util/slack-legacy';
 
 
-import type { IConfigManagerForApp } from './config-manager';
+import { configManager } from './config-manager';
 import type { S2sMessagingService } from './s2s-messaging/base';
 import type { S2sMessagingService } from './s2s-messaging/base';
 import type { S2sMessageHandlable } from './s2s-messaging/handlable';
 import type { S2sMessageHandlable } from './s2s-messaging/handlable';
 import { LinkSharedEventHandler } from './slack-event-handler/link-shared';
 import { LinkSharedEventHandler } from './slack-event-handler/link-shared';
@@ -34,8 +34,6 @@ export class SlackIntegrationService implements S2sMessageHandlable {
 
 
   crowi: Crowi;
   crowi: Crowi;
 
 
-  configManager: IConfigManagerForApp;
-
   s2sMessagingService!: S2sMessagingService;
   s2sMessagingService!: S2sMessagingService;
 
 
   lastLoadedAt?: Date;
   lastLoadedAt?: Date;
@@ -44,7 +42,6 @@ export class SlackIntegrationService implements S2sMessageHandlable {
 
 
   constructor(crowi: Crowi) {
   constructor(crowi: Crowi) {
     this.crowi = crowi;
     this.crowi = crowi;
-    this.configManager = crowi.configManager;
     this.s2sMessagingService = crowi.s2sMessagingService;
     this.s2sMessagingService = crowi.s2sMessagingService;
     this.linkSharedHandler = new LinkSharedEventHandler(crowi);
     this.linkSharedHandler = new LinkSharedEventHandler(crowi);
 
 
@@ -99,20 +96,20 @@ export class SlackIntegrationService implements S2sMessageHandlable {
   }
   }
 
 
   get isSlackbotConfigured(): boolean {
   get isSlackbotConfigured(): boolean {
-    const hasSlackbotType = !!this.configManager.getConfig('slackbot:currentBotType');
+    const hasSlackbotType = !!configManager.getConfig('slackbot:currentBotType');
     return hasSlackbotType;
     return hasSlackbotType;
   }
   }
 
 
   get isSlackLegacyConfigured(): boolean {
   get isSlackLegacyConfigured(): boolean {
     // for legacy util
     // for legacy util
-    const hasSlackToken = !!this.configManager.getConfig('slack:token');
-    const hasSlackIwhUrl = !!this.configManager.getConfig('slack:incomingWebhookUrl');
+    const hasSlackToken = !!configManager.getConfig('slack:token');
+    const hasSlackIwhUrl = !!configManager.getConfig('slack:incomingWebhookUrl');
 
 
     return hasSlackToken || hasSlackIwhUrl;
     return hasSlackToken || hasSlackIwhUrl;
   }
   }
 
 
   private isCheckTypeValid(): boolean {
   private isCheckTypeValid(): boolean {
-    const currentBotType = this.configManager.getConfig('slackbot:currentBotType');
+    const currentBotType = configManager.getConfig('slackbot:currentBotType');
     if (currentBotType == null) {
     if (currentBotType == null) {
       throw new Error('The config \'SLACKBOT_TYPE\'(ns: \'crowi\', key: \'slackbot:currentBotType\') must be set.');
       throw new Error('The config \'SLACKBOT_TYPE\'(ns: \'crowi\', key: \'slackbot:currentBotType\') must be set.');
     }
     }
@@ -121,7 +118,7 @@ export class SlackIntegrationService implements S2sMessageHandlable {
   }
   }
 
 
   get proxyUriForCurrentType(): string | undefined {
   get proxyUriForCurrentType(): string | undefined {
-    const currentBotType = this.configManager.getConfig('slackbot:currentBotType');
+    const currentBotType = configManager.getConfig('slackbot:currentBotType');
 
 
     // TODO assert currentBotType is not null and CUSTOM_WITHOUT_PROXY
     // TODO assert currentBotType is not null and CUSTOM_WITHOUT_PROXY
 
 
@@ -132,7 +129,7 @@ export class SlackIntegrationService implements S2sMessageHandlable {
         proxyUri = OFFICIAL_SLACKBOT_PROXY_URI;
         proxyUri = OFFICIAL_SLACKBOT_PROXY_URI;
         break;
         break;
       default:
       default:
-        proxyUri = this.configManager.getConfig('slackbot:proxyUri');
+        proxyUri = configManager.getConfig('slackbot:proxyUri');
         break;
         break;
     }
     }
 
 
@@ -145,7 +142,7 @@ export class SlackIntegrationService implements S2sMessageHandlable {
   async generateClientForCustomBotWithoutProxy(): Promise<WebClient> {
   async generateClientForCustomBotWithoutProxy(): Promise<WebClient> {
     this.isCheckTypeValid();
     this.isCheckTypeValid();
 
 
-    const token = this.configManager.getConfig('slackbot:withoutProxy:botToken');
+    const token = configManager.getConfig('slackbot:withoutProxy:botToken');
 
 
     if (token == null) {
     if (token == null) {
       throw new Error('The config \'SLACK_BOT_TOKEN\'(ns: \'crowi\', key: \'slackbot:withoutProxy:botToken\') must be set.');
       throw new Error('The config \'SLACK_BOT_TOKEN\'(ns: \'crowi\', key: \'slackbot:withoutProxy:botToken\') must be set.');
@@ -179,7 +176,7 @@ export class SlackIntegrationService implements S2sMessageHandlable {
   async generateClientForPrimaryWorkspace(): Promise<WebClient> {
   async generateClientForPrimaryWorkspace(): Promise<WebClient> {
     this.isCheckTypeValid();
     this.isCheckTypeValid();
 
 
-    const currentBotType = this.configManager.getConfig('slackbot:currentBotType');
+    const currentBotType = configManager.getConfig('slackbot:currentBotType');
 
 
     if (currentBotType === SlackbotType.CUSTOM_WITHOUT_PROXY) {
     if (currentBotType === SlackbotType.CUSTOM_WITHOUT_PROXY) {
       return this.generateClientForCustomBotWithoutProxy();
       return this.generateClientForCustomBotWithoutProxy();
@@ -233,7 +230,7 @@ export class SlackIntegrationService implements S2sMessageHandlable {
   }
   }
 
 
   private async postMessageWithLegacyUtil(messageArgs: ChatPostMessageArguments | IncomingWebhookSendArguments): Promise<void> {
   private async postMessageWithLegacyUtil(messageArgs: ChatPostMessageArguments | IncomingWebhookSendArguments): Promise<void> {
-    const slackLegacyUtil = slackLegacyUtilFactory(this.configManager);
+    const slackLegacyUtil = slackLegacyUtilFactory(configManager);
 
 
     try {
     try {
       await slackLegacyUtil.postMessage(messageArgs);
       await slackLegacyUtil.postMessage(messageArgs);