|
@@ -1,11 +1,22 @@
|
|
|
|
|
+const logger = require('@alias/logger')('growi:service:FileUploader');
|
|
|
|
|
+
|
|
|
// file uploader virtual class
|
|
// file uploader virtual class
|
|
|
// 各アップローダーで共通のメソッドはここで定義する
|
|
// 各アップローダーで共通のメソッドはここで定義する
|
|
|
|
|
+const S2sMessage = require('../../models/vo/s2s-message');
|
|
|
|
|
+const S2sMessageHandlable = require('../s2s-messaging/handlable');
|
|
|
|
|
|
|
|
-class Uploader {
|
|
|
|
|
|
|
+class Uploader extends S2sMessageHandlable {
|
|
|
|
|
|
|
|
constructor(crowi) {
|
|
constructor(crowi) {
|
|
|
|
|
+ super();
|
|
|
|
|
+
|
|
|
this.crowi = crowi;
|
|
this.crowi = crowi;
|
|
|
this.configManager = crowi.configManager;
|
|
this.configManager = crowi.configManager;
|
|
|
|
|
+ this.s2sMessagingService = crowi.s2sMessagingService;
|
|
|
|
|
+ this.appService = crowi.appService;
|
|
|
|
|
+ this.xssService = crowi.xssService;
|
|
|
|
|
+
|
|
|
|
|
+ this.lastLoadedAt = null;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
getIsUploadable() {
|
|
getIsUploadable() {
|
|
@@ -24,6 +35,46 @@ class Uploader {
|
|
|
return !!this.configManager.getConfig('crowi', 'app:fileUpload');
|
|
return !!this.configManager.getConfig('crowi', 'app:fileUpload');
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
|
+ * @inheritdoc
|
|
|
|
|
+ */
|
|
|
|
|
+ shouldHandleS2sMessage(s2sMessage) {
|
|
|
|
|
+ const { eventName, updatedAt } = s2sMessage;
|
|
|
|
|
+ if (eventName !== 'fileUploadServiceUpdated' || updatedAt == null) {
|
|
|
|
|
+ return false;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ return this.lastLoadedAt == null || this.lastLoadedAt < new Date(s2sMessage.updatedAt);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * @inheritdoc
|
|
|
|
|
+ */
|
|
|
|
|
+ async handleS2sMessage(s2sMessage) {
|
|
|
|
|
+ const { configManager } = this;
|
|
|
|
|
+
|
|
|
|
|
+ logger.info('Reset fileupload service by pubsub notification');
|
|
|
|
|
+ await configManager.loadConfigs();
|
|
|
|
|
+ this.initCustomCss();
|
|
|
|
|
+ this.initCustomTitle();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ async publishUpdatedMessage() {
|
|
|
|
|
+ const { s2sMessagingService } = this;
|
|
|
|
|
+
|
|
|
|
|
+ if (s2sMessagingService != null) {
|
|
|
|
|
+ const s2sMessage = new S2sMessage('customizeServiceUpdated', { updatedAt: new Date() });
|
|
|
|
|
+
|
|
|
|
|
+ try {
|
|
|
|
|
+ await s2sMessagingService.publish(s2sMessage);
|
|
|
|
|
+ }
|
|
|
|
|
+ catch (e) {
|
|
|
|
|
+ logger.error('Failed to publish update message with S2sMessagingService: ', e.message);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
/**
|
|
/**
|
|
|
* Check files size limits for all uploaders
|
|
* Check files size limits for all uploaders
|
|
|
*
|
|
*
|