mizozobu 6 лет назад
Родитель
Сommit
3e7109e4dd
3 измененных файлов с 24 добавлено и 32 удалено
  1. 1 16
      src/server/service/export.js
  2. 21 0
      src/server/service/growi-bridge.js
  3. 2 16
      src/server/service/import.js

+ 1 - 16
src/server/service/export.js

@@ -11,6 +11,7 @@ class ExportService {
     this.crowi = crowi;
     this.appService = crowi.appService;
     this.growiBridgeService = crowi.growiBridgeService;
+    this.getFile = this.growiBridgeService.getFile.bind(this);
     this.baseDir = path.join(crowi.tmpDir, 'downloads');
     this.metaFileName = 'meta.json';
     this.encoding = 'utf-8';
@@ -207,22 +208,6 @@ class ExportService {
     return zipFile;
   }
 
-  /**
-   * get the absolute path to a file
-   *
-   * @memberOf ExportService
-   * @param {string} fileName base name of file
-   * @return {string} absolute path to the file
-   */
-  getFile(fileName) {
-    const jsonFile = path.join(this.baseDir, fileName);
-
-    // throws err if the file does not exist
-    fs.accessSync(jsonFile);
-
-    return jsonFile;
-  }
-
   /**
    * remove zip file from downloads dir
    *

+ 21 - 0
src/server/service/growi-bridge.js

@@ -43,6 +43,27 @@ class GrowiBridgeService {
     return Model;
   }
 
+  /**
+   * get the absolute path to a file
+   * this method must must be bound to the caller (this.baseDir is undefined in this service)
+   *
+   * @memberOf ImportService
+   * @param {string} fileName base name of file
+   * @return {string} absolute path to the file
+   */
+  getFile(fileName) {
+    if (this.baseDir == null) {
+      throw new Error('baseDir is not defined');
+    }
+
+    const jsonFile = path.join(this.baseDir, fileName);
+
+    // throws err if the file does not exist
+    fs.accessSync(jsonFile);
+
+    return jsonFile;
+  }
+
   /**
    * parse a zip file
    *

+ 2 - 16
src/server/service/import.js

@@ -10,6 +10,8 @@ class ImportService {
 
   constructor(crowi) {
     this.crowi = crowi;
+    this.growiBridgeService = crowi.growiBridgeService;
+    this.getFile = this.growiBridgeService.getFile.bind(this);
     this.baseDir = path.join(crowi.tmpDir, 'imports');
     this.metaFileName = 'meta.json';
     this.encoding = 'utf-8';
@@ -235,22 +237,6 @@ class ImportService {
     return document;
   }
 
-  /**
-   * get the absolute path to a file
-   *
-   * @memberOf ImportService
-   * @param {string} fileName base name of file
-   * @return {string} absolute path to the file
-   */
-  getFile(fileName) {
-    const jsonFile = path.join(this.baseDir, fileName);
-
-    // throws err if the file does not exist
-    fs.accessSync(jsonFile);
-
-    return jsonFile;
-  }
-
   /**
    * remove zip file from imports dir
    *