'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/update', '');
  var folderName = filepath.split('/');
  var postName = folderName.pop();
  folderName = folderName.join('/');

  var p = _cli.cmsOperations.duplicate(req.body.oldFilePath, req.body.selectTemplate, folderName, postName, req, true);

  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));
  }).catch(function (e) {
    console.error(e);
  });
};

exports.default = route;