'use strict';

Object.defineProperty(exports, "__esModule", {
  value: true
});

var _cli = require('../../cli');

var route = function route(req, res, next) {
  _cli.abeExtend.hooks.instance.trigger('beforeRoute', req, res, next);

  var filepath = req.originalUrl.replace('/abe/create', '');
  var folderName = filepath.split('/');
  var postName = folderName.pop();
  folderName = folderName.join('/');

  var p = _cli.cmsOperations.create(req.body.abe_meta.template, folderName, postName, req, req.body);

  p.then(function (resSave) {
    var result = {
      success: 1,
      json: resSave
    };
    res.set('Content-Type', 'application/json');
    res.send(JSON.stringify(result));
  }, function () {
    var result = {
      success: 0
    };
    res.set('Content-Type', 'application/json');
    res.send(JSON.stringify(result));
  });
};

exports.default = route;