فهرست منبع

collectionMap, initCollectionMap, getModelFromCollectionName to GrowiBridgeService

mizozobu 6 سال پیش
والد
کامیت
12ef0af0ba

+ 1 - 1
src/server/routes/apiv3/export.js

@@ -58,7 +58,7 @@ module.exports = (crowi) => {
     try {
       const { collections } = req.body;
       // get model for collection
-      const models = collections.map(collectionName => exportService.getModelFromCollectionName(collectionName));
+      const models = collections.map(collectionName => growiBridgeService.getModelFromCollectionName(collectionName));
 
       const [metaJson, jsonFiles] = await Promise.all([
         exportService.createMetaJson(),

+ 1 - 1
src/server/routes/apiv3/import.js

@@ -112,7 +112,7 @@ module.exports = (crowi) => {
       importService.validate(meta);
 
       await Promise.all(filteredFileStats.map(async({ fileName, collectionName, size }) => {
-        const Model = importService.getModelFromCollectionName(collectionName);
+        const Model = growiBridgeService.getModelFromCollectionName(collectionName);
         const jsonFile = importService.getFile(fileName);
 
         let overwriteParams;

+ 0 - 33
src/server/service/export.js

@@ -17,10 +17,6 @@ class ExportService {
     this.per = 100;
     this.zlibLevel = 9; // 0(min) - 9(max)
 
-    // { pages: Page, users: User, ... }
-    this.collectionMap = {};
-    this.initCollectionMap(crowi.models);
-
     // this.files = {
     //   configs: path.join(this.baseDir, 'configs.json'),
     //   pages: path.join(this.baseDir, 'pages.json'),
@@ -34,18 +30,6 @@ class ExportService {
     });
   }
 
-  /**
-   * initialize collection map
-   *
-   * @memberOf ExportService
-   * @param {object} models from models/index.js
-   */
-  initCollectionMap(models) {
-    for (const model of Object.values(models)) {
-      this.collectionMap[model.collection.collectionName] = model;
-    }
-  }
-
   /**
    * parse all zip files in downloads dir
    *
@@ -239,23 +223,6 @@ class ExportService {
     return jsonFile;
   }
 
-  /**
-   * get a model from collection name
-   *
-   * @memberOf ExportService
-   * @param {string} collectionName collection name
-   * @return {object} instance of mongoose model
-   */
-  getModelFromCollectionName(collectionName) {
-    const Model = this.collectionMap[collectionName];
-
-    if (Model == null) {
-      throw new Error(`cannot find a model for collection name "${collectionName}"`);
-    }
-
-    return Model;
-  }
-
   /**
    * remove zip file from downloads dir
    *

+ 34 - 1
src/server/service/growi-bridge.js

@@ -8,12 +8,45 @@ class GrowiBridgeService {
 
   constructor(crowi) {
     this.metaFileName = 'meta.json';
+
+    // { pages: Page, users: User, ... }
+    this.collectionMap = {};
+    this.initCollectionMap(crowi.models);
+  }
+
+  /**
+   * initialize collection map
+   *
+   * @memberOf GrowiBridgeService
+   * @param {object} models from models/index.js
+   */
+  initCollectionMap(models) {
+    for (const model of Object.values(models)) {
+      this.collectionMap[model.collection.collectionName] = model;
+    }
+  }
+
+  /**
+   * get a model from collection name
+   *
+   * @memberOf GrowiBridgeService
+   * @param {string} collectionName collection name
+   * @return {object} instance of mongoose model
+   */
+  getModelFromCollectionName(collectionName) {
+    const Model = this.collectionMap[collectionName];
+
+    if (Model == null) {
+      throw new Error(`cannot find a model for collection name "${collectionName}"`);
+    }
+
+    return Model;
   }
 
   /**
    * parse a zip file
    *
-   * @memberOf ImportService
+   * @memberOf GrowiBridgeService
    * @param {string} zipFile path to zip file
    * @return {object} meta{object} and files{Array.<object>}
    */

+ 0 - 33
src/server/service/import.js

@@ -16,27 +16,11 @@ class ImportService {
     this.per = 100;
     this.keepOriginal = this.keepOriginal.bind(this);
 
-    // { pages: Page, users: User, ... }
-    this.collectionMap = {};
-    this.initCollectionMap(crowi.models);
-
     // { pages: { _id: ..., path: ..., ...}, users: { _id: ..., username: ..., }, ... }
     this.convertMap = {};
     this.initConvertMap(crowi.models);
   }
 
-  /**
-   * initialize collection map
-   *
-   * @memberOf ImportService
-   * @param {object} models from models/index.js
-   */
-  initCollectionMap(models) {
-    for (const model of Object.values(models)) {
-      this.collectionMap[model.collection.collectionName] = model;
-    }
-  }
-
   /**
    * initialize convert map. set keepOriginal as default
    *
@@ -251,23 +235,6 @@ class ImportService {
     return document;
   }
 
-  /**
-   * get a model from collection name
-   *
-   * @memberOf ImportService
-   * @param {string} collectionName collection name
-   * @return {object} instance of mongoose model
-   */
-  getModelFromCollectionName(collectionName) {
-    const Model = this.collectionMap[collectionName];
-
-    if (Model == null) {
-      throw new Error(`cannot find a model for collection name "${collectionName}"`);
-    }
-
-    return Model;
-  }
-
   /**
    * get the absolute path to a file
    *