'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);
  if (typeof res._header !== 'undefined' && res._header !== null) return;

  var image = _cli.cmsMedia.image.saveFile(req);

  image.then(function (resp) {
    _cli.Manager.instance.addThumbsToList({
      originalFile: resp.filePath,
      thumbFile: resp.thumbnail
    });
    res.set('Content-Type', 'application/json');
    res.send(JSON.stringify(resp));
  }).catch(function (e) {
    console.error('[ERROR] post-upload', e);
  });
};

exports.default = route;