Преглед изворни кода

refactor the Config model so that it can be used without crowi instance

Yuki Takei пре 7 година
родитељ
комит
3d9f21466c
1 измењених фајлова са 14 додато и 4 уклоњено
  1. 14 4
      src/server/models/config.js

+ 14 - 4
src/server/models/config.js

@@ -21,6 +21,12 @@ module.exports = function(crowi) {
     value: { type: String, required: true }
     value: { type: String, required: true }
   });
   });
 
 
+  function validateCrowi() {
+    if (crowi == null) {
+      throw new Error('"crowi" is null. Init Config model with "crowi" argument first.');
+    }
+  }
+
   /**
   /**
    * default values when GROWI is cleanly installed
    * default values when GROWI is cleanly installed
    */
    */
@@ -148,8 +154,10 @@ module.exports = function(crowi) {
   };
   };
 
 
   configSchema.statics.updateConfigCache = function(ns, config) {
   configSchema.statics.updateConfigCache = function(ns, config) {
-    var originalConfig = crowi.getConfig();
-    var newNSConfig = originalConfig[ns] || {};
+    validateCrowi();
+
+    const originalConfig = crowi.getConfig();
+    const newNSConfig = originalConfig[ns] || {};
     Object.keys(config).forEach(function(key) {
     Object.keys(config).forEach(function(key) {
       if (config[key] || config[key] === '' || config[key] === false) {
       if (config[key] || config[key] === '' || config[key] === false) {
         newNSConfig[key] = config[key];
         newNSConfig[key] = config[key];
@@ -310,7 +318,7 @@ module.exports = function(crowi) {
   };
   };
 
 
   configSchema.statics.isUploadable = function(config) {
   configSchema.statics.isUploadable = function(config) {
-    var method = crowi.env.FILE_UPLOAD || 'aws';
+    const method = process.env.FILE_UPLOAD || 'aws';
 
 
     if (method == 'aws' && (
     if (method == 'aws' && (
       !config.crowi['aws:accessKeyId'] ||
       !config.crowi['aws:accessKeyId'] ||
@@ -496,6 +504,8 @@ module.exports = function(crowi) {
   };
   };
 
 
   configSchema.statics.customTitle = function(config, page) {
   configSchema.statics.customTitle = function(config, page) {
+    validateCrowi();
+
     const key = 'customize:title';
     const key = 'customize:title';
     let customTitle = getValueForCrowiNS(config, key);
     let customTitle = getValueForCrowiNS(config, key);
 
 
@@ -588,7 +598,7 @@ module.exports = function(crowi) {
 
 
   configSchema.statics.getLocalconfig = function(config) {
   configSchema.statics.getLocalconfig = function(config) {
     const Config = this;
     const Config = this;
-    const env = crowi.getEnv();
+    const env = process.env;
 
 
     const local_config = {
     const local_config = {
       crowi: {
       crowi: {