[TIC-Web] fix the export api format 36/131036/1 develop
authorChangHyun Lee <leechwin.lee@samsung.com>
Thu, 25 May 2017 06:55:47 +0000 (15:55 +0900)
committerChangHyun Lee <leechwin.lee@samsung.com>
Thu, 25 May 2017 06:55:47 +0000 (15:55 +0900)
- fix the export api format

Change-Id: I32d76a3cf71ce4834427a3701a442826ad45482f
Signed-off-by: ChangHyun Lee <leechwin.lee@samsung.com>
controller/router.js
controller/ticcore.js

index c683e68..3f411eb 100644 (file)
@@ -187,23 +187,33 @@ var init = function (serv) {
     });
 
     /**
-     * Get recipe data from tic-core via RESTful API
+     * Post recipe data from tic-core via RESTful API
      * @URI /api/imports
      * @TYPE POST
      */
     router.post('/imports', function (req, res) {
         logger.info('an api called that /api/imports');
-        core.getImports(req, res);
+
+        core.postImports(req, res);
     });
 
     /**
-     * Get ks file path from tic-core via RESTful API
+     * Get ks or recipe file path from tic-core via RESTful API
      * @URI /api/exports
      * @TYPE POST
      */
-    router.post('/exports', function (req, res) {
+    router.post('/exports', function(req, res) {
         logger.info('an api called that /api/exports');
-        core.getExports(req, res);
+
+        var format = req.body.format;
+        var data = {
+            recipes: req.body.recipes,
+            packages: req.body.packages,
+            outdir: config.TIC_WEB.PATH_RECIPE_EXPORT
+        };
+        core.postExports(format, data, function(result) {
+            res.send(result);
+        });
     });
 
     /**
index 490132b..15b4775 100644 (file)
@@ -83,9 +83,9 @@ ticcore.getAnalysis = function getAnalysis (req, res) {
 };
 
 /**
- * Get recipe data from tic-core via RESTful API
+ * Post recipe data from tic-core via RESTful API
  */
-ticcore.getImports = function getImports (req, res) {
+ticcore.postImports = function(req, res) {
     logger.info('getImports');
     var postData = JSON.stringify(req.body);
     var addr = this.server.address();
@@ -124,21 +124,10 @@ ticcore.getImports = function getImports (req, res) {
     ticCoreReq.end();
 };
 
-ticcore.getExports = function getExports(req, res) {
-    logger.info('getExports');
-    var format = req.body.format;
-    var defaultOutdir = AppConfig.TIC_WEB.PATH_RECIPE_EXPORT;
-    // FIXME: outdir setting for ks file when image creation
-    if (req.body.outdir) {
-        defaultOutdir = req.body.outdir;
-    }
-
-    var body = {
-        recipes: req.body.recipes,
-        packages: req.body.packages,
-        outdir: defaultOutdir
-    }
-    var postData = JSON.stringify(body);
+ticcore.postExports = function(format, data, callback) {
+    logger.info('postExports');
+
+    var postData = JSON.stringify(data);
 
     var addr = this.server.address();
     var options = {
@@ -162,20 +151,20 @@ ticcore.getExports = function getExports(req, res) {
         });
         ticCoreRes.on('end', function () {
             data = data.replace(AppConfig.TIC_WEB.PATH, AppConfig.TIC_WEB.PATH_ABSTRACT);
-            res.send(data);
+            callback(data);
         });
     });
 
     ticCoreReq.write(postData);
 
     ticCoreReq.on('error', function (err) {
-        res.send({
+        callback({
             result: 'false',
             message: err.message
-        })
+        });
     });
 
     ticCoreReq.end();
-};
+}
 
 module.exports = ticcore;