});
/**
- * 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);
+ });
});
/**
};
/**
- * 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();
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 = {
});
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;