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

Merge pull request #1232 from weseek/imprv/alias-uploadable

refs GW-310: エイリアス対応
Yuki Takei 6 лет назад
Родитель
Сommit
cdbc52399a

+ 11 - 0
src/server/service/file-uploader/aws.js

@@ -49,6 +49,17 @@ module.exports = function(crowi) {
     return filePath;
   }
 
+  lib.getIsUploadable = function() {
+    return this.configManager.getConfig('crowi', 'aws:accessKeyId') != null
+      && this.configManager.getConfig('crowi', 'aws:secretAccessKey') != null
+      && (
+        this.configManager.getConfig('crowi', 'aws:region') != null
+          || this.configManager.getConfig('crowi', 'aws:customEndpoint') != null
+      )
+      && this.configManager.getConfig('crowi', 'aws:bucket') != null;
+  };
+
+
   lib.deleteFile = async function(attachment) {
     const filePath = getFilePathOnStorage(attachment);
     return lib.deleteFileByFilePath(filePath);

+ 4 - 0
src/server/service/file-uploader/gcs.js

@@ -36,6 +36,10 @@ module.exports = function(crowi) {
     return filePath;
   }
 
+  lib.getIsUploadable = function() {
+    return this.configManager.getConfig('crowi', 'gcs:apiKeyJsonPath') != null && this.configManager.getConfig('crowi', 'gcs:bucket') != null;
+  };
+
   lib.deleteFile = async function(attachment) {
     const filePath = getFilePathOnStorage(attachment);
     return lib.deleteFileByFilePath(filePath);

+ 4 - 0
src/server/service/file-uploader/gridfs.js

@@ -22,6 +22,10 @@ module.exports = function(crowi) {
   AttachmentFile.promisifiedWrite = util.promisify(AttachmentFile.write).bind(AttachmentFile);
   AttachmentFile.promisifiedUnlink = util.promisify(AttachmentFile.unlink).bind(AttachmentFile);
 
+  lib.getIsUploadable = function() {
+    return true;
+  };
+
   lib.deleteFile = async function(attachment) {
     let filenameValue = attachment.fileName;
 

+ 4 - 0
src/server/service/file-uploader/local.js

@@ -25,6 +25,10 @@ module.exports = function(crowi) {
     return filePath;
   }
 
+  lib.getIsUploadable = function() {
+    return true;
+  };
+
   lib.deleteFile = async function(attachment) {
     const filePath = getFilePathOnStorage(attachment);
     return lib.deleteFileByFilePath(filePath);

+ 4 - 0
src/server/service/file-uploader/none.js

@@ -5,6 +5,10 @@ module.exports = function(crowi) {
   const Uploader = require('./uploader');
   const lib = new Uploader(crowi.configManager);
 
+  lib.getIsUploadable = function() {
+    return false;
+  };
+
   lib.deleteFile = function(filePath) {
     debug(`File deletion: ${filePath}`);
     throw new Error('not implemented');

+ 1 - 21
src/server/service/file-uploader/uploader.js

@@ -8,27 +8,7 @@ class Uploader {
   }
 
   getIsUploadable() {
-    // TODO Add alias support
-    const method = process.env.FILE_UPLOAD || 'aws';
-
-    if (method === 'aws' && (
-      !this.configManager.getConfig('crowi', 'aws:accessKeyId')
-        || !this.configManager.getConfig('crowi', 'aws:secretAccessKey')
-        || (
-          !this.configManager.getConfig('crowi', 'aws:region')
-            && !this.configManager.getConfig('crowi', 'aws:customEndpoint'))
-        || !this.configManager.getConfig('crowi', 'aws:bucket'))) {
-      return false;
-    }
-    // When method is gcs and gcs:api Key JsonPath or gcs:bucket is set is false
-    if (method === 'gcs' && (
-      !this.configManager.getConfig('crowi', 'gcs:apiKeyJsonPath')
-        || !this.configManager.getConfig('crowi', 'gcs:bucket'))
-    ) {
-      return false;
-    }
-
-    return method !== 'none';
+    throw new Error('Implement this');
   }
 
   getFileUploadEnabled() {