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

+ 22 - 3
apps/app/src/server/service/file-uploader/azure.ts

@@ -45,9 +45,16 @@ type AzureConfig = {
 
 
 
 
 function getAzureConfig(): AzureConfig {
 function getAzureConfig(): AzureConfig {
+  const accountName = configManager.getConfig('crowi', 'azure:storageAccountName');
+  const containerName = configManager.getConfig('crowi', 'azure:storageContainerName');
+
+  if (accountName == null || containerName == null) {
+    throw new Error('Azure Blob Storage is not configured.');
+  }
+
   return {
   return {
-    accountName: configManager.getConfig('crowi', 'azure:storageAccountName'),
-    containerName: configManager.getConfig('crowi', 'azure:storageContainerName'),
+    accountName,
+    containerName,
   };
   };
 }
 }
 
 
@@ -55,6 +62,11 @@ function getCredential(): TokenCredential {
   const tenantId = configManager.getConfig('crowi', 'azure:tenantId');
   const tenantId = configManager.getConfig('crowi', 'azure:tenantId');
   const clientId = configManager.getConfig('crowi', 'azure:clientId');
   const clientId = configManager.getConfig('crowi', 'azure:clientId');
   const clientSecret = configManager.getConfig('crowi', 'azure:clientSecret');
   const clientSecret = configManager.getConfig('crowi', 'azure:clientSecret');
+
+  if (tenantId == null || clientId == null || clientSecret == null) {
+    throw new Error(`Azure Blob Storage missing required configuration: tenantId=${tenantId}, clientId=${clientId}, clientSecret=${clientSecret}`);
+  }
+
   return new ClientSecretCredential(tenantId, clientId, clientSecret);
   return new ClientSecretCredential(tenantId, clientId, clientSecret);
 }
 }
 
 
@@ -75,7 +87,14 @@ class AzureFileUploader extends AbstractFileUploader {
    * @inheritdoc
    * @inheritdoc
    */
    */
   override isValidUploadSettings(): boolean {
   override isValidUploadSettings(): boolean {
-    throw new Error('Method not implemented.');
+    try {
+      getAzureConfig();
+      return true;
+    }
+    catch (e) {
+      logger.error(e);
+      return false;
+    }
   }
   }
 
 
   /**
   /**

+ 14 - 3
apps/app/src/server/service/file-uploader/gcs.ts

@@ -18,8 +18,12 @@ import { ContentHeaders } from './utils';
 const logger = loggerFactory('growi:service:fileUploaderGcs');
 const logger = loggerFactory('growi:service:fileUploaderGcs');
 
 
 
 
-function getGcsBucket() {
-  return configManager.getConfig('crowi', 'gcs:bucket');
+function getGcsBucket(): string {
+  const gcsBucket = configManager.getConfig('crowi', 'gcs:bucket');
+  if (gcsBucket == null) {
+    throw new Error('GCS bucket is not configured.');
+  }
+  return gcsBucket;
 }
 }
 
 
 let storage: Storage;
 let storage: Storage;
@@ -62,7 +66,14 @@ class GcsFileUploader extends AbstractFileUploader {
    * @inheritdoc
    * @inheritdoc
    */
    */
   override isValidUploadSettings(): boolean {
   override isValidUploadSettings(): boolean {
-    throw new Error('Method not implemented.');
+    try {
+      getGcsBucket();
+      return true;
+    }
+    catch (err) {
+      logger.error(err);
+      return false;
+    }
   }
   }
 
 
   /**
   /**