text: "use strict";var _createClass=function(){function s(e,t){for(var a=0;a<t.length;a++){var s=t[a];s.enumerable=s.enumerable||!1,s.configurable=!0,"value"in s&&(s.writable=!0),Object.defineProperty(e,s.key,s)}}return function(e,t,a){return t&&s(e.prototype,t),a&&s(e,a),e}}(),_os=require("os"),_os2=_interopRequireDefault(_os),_fs=require("fs"),_fs2=_interopRequireDefault(_fs),_mockAwsS=require("mock-aws-s3"),_mockAwsS2=_interopRequireDefault(_mockAwsS),_awsSdk=require("aws-sdk"),_awsSdk2=_interopRequireDefault(_awsSdk),_isBase=require("is-base64"),_isBase2=_interopRequireDefault(_isBase);function _interopRequireDefault(e){return e&&e.__esModule?e:{default:e}}function _classCallCheck(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}var instance={},EasySave=function(){function s(e){var t=1<arguments.length&&void 0!==arguments[1]?arguments[1]:"aws",a=2<arguments.length&&void 0!==arguments[2]?arguments[2]:"";if(_classCallCheck(this,s),void 0===e)throw new Error("First parameter is required");if(this._type=t,this._target=a,"aws"===this._type){if(void 0===e.AWS_S3_ACCESS_KEY||null===e.AWS_S3_ACCESS_KEY||""===e.AWS_S3_ACCESS_KEY||""===e.AWS_S3_SECRET||null===e.AWS_S3_SECRET||void 0===e.AWS_S3_SECRET)throw new Error("AWS Key can not be empty");_awsSdk2.default.config.accessKeyId=e.AWS_S3_ACCESS_KEY,_awsSdk2.default.config.secretAccessKey=e.AWS_S3_SECRET,"test"===process.env.NODE_ENV?this._params=new _mockAwsS2.default.S3({params:{Bucket:this._target.bucket}}):this._params=new _awsSdk2.default.S3}else this._params=e}return _createClass(s,[{key:"save",value:function(e,t){var _=this,l=1<arguments.length&&void 0!==t?t:"base64";return this.file=e,this.type=l,new Promise(function(a,s){if(void 0===_.file)s("File input required");else if((0,_isBase2.default)(_.file)){var e=_.file.split(";base64,"),t=e[0].split(";")[0],r=(t=t.replace("data:","")).split("/")[1];e=e[1];var i=(new Date).getTime();if("aws"===_._type){var n={Bucket:_._target.bucket+"/"+_._target.folder,Key:i+"."+r,Body:e,ACL:"authenticated-read",ContentEncoding:t,ContentType:t};_._params.upload(n,function(e,t){e?s("Error on send file to AWS",e):a(t.Location)})}else if("local"===_._type){var o=_._params?_._params:_os2.default.homedir()+"/uploads",u=o+"/"+_._target;_fs2.default.existsSync(o)||_fs2.default.mkdirSync(o),_fs2.default.existsSync(u)||_fs2.default.mkdirSync(u),_fs2.default.writeFile(u+"/"+i+"."+r,e,{encoding:l},function(e){e?s("Error to write file on disk",e):a(u+"/"+i+"."+r)})}}else s("String not is Base64")})}},{key:"getType",value:function(){return this._type}},{key:"getTarget",value:function(){return this._target}},{key:"getParams",value:function(){return this._params}},{key:"setType",value:function(e){this._type=e}},{key:"setTarget",value:function(e){this.__target=e}},{key:"setParams",value:function(e){this._params=e}}]),s}();module.exports=EasySave;