@edsdk/file-uploader-microservice
Advanced tools
Comparing version 1.0.4 to 1.0.5
@@ -1,1 +0,1 @@ | ||
!function(e,t){for(var s in t)e[s]=t[s]}(exports,function(e){var t={};function s(i){if(t[i])return t[i].exports;var r=t[i]={i:i,l:!1,exports:{}};return e[i].call(r.exports,r,r.exports,s),r.l=!0,r.exports}return s.m=e,s.c=t,s.d=function(e,t,i){s.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:i})},s.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},s.t=function(e,t){if(1&t&&(e=s(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var i=Object.create(null);if(s.r(i),Object.defineProperty(i,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var r in e)s.d(i,r,function(t){return e[t]}.bind(null,r));return i},s.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return s.d(t,"a",t),t},s.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},s.p="",s(s.s=0)}([function(e,t,s){"use strict";Object.defineProperty(t,"__esModule",{value:!0});const i=s(1),r=s(2);t.startFileUploaderMicroservice=function(e){let t=i();return r.bindFileUploader({app:t,url:e.urlUploader?e.urlUploader:"/",dir:e.dirFiles}),e.dirRoot&&t.use(i.static(e.dirRoot)),t.listen(e.port?e.port:8080,e.host?e.host:"localhost",()=>{console.log("Image Editor SDK microservice started on localhost:8080")}),t}},function(e,t){e.exports=require("express")},function(e,t,s){!function(e,t){for(var s in t)e[s]=t[s]}(t,function(e){var t={};function s(i){if(t[i])return t[i].exports;var r=t[i]={i:i,l:!1,exports:{}};return e[i].call(r.exports,r,r.exports,s),r.l=!0,r.exports}return s.m=e,s.c=t,s.d=function(e,t,i){s.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:i})},s.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},s.t=function(e,t){if(1&t&&(e=s(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var i=Object.create(null);if(s.r(i),Object.defineProperty(i,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var r in e)s.d(i,r,function(t){return e[t]}.bind(null,r));return i},s.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return s.d(t,"a",t),t},s.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},s.p="",s(s.s=11)}([function(e,t,s){"use strict";Object.defineProperty(t,"__esModule",{value:!0});class i{static createMessage(e,t=null,s=null,r=null){let n=new i;return n.code=e,null!=t&&(n.args=[],n.args.push(t),null!=s&&n.args.push(s),null!=r&&n.args.push(r)),n}static createMessageByFiles(e,t){let s=new i;return s.code=e,s.files=t,s}static createMessageByFile(e,t){let s=new i;return s.code=e,s.files=[],s.files.push(t),s}}i.FILE_ERROR_SYNTAX=-1,i.FILE_ERROR_DOES_NOT_EXIST=-2,i.FILE_ERROR_INCORRECT_IMAGE_EXT_CHANGE=-3,i.ACTION_NOT_FOUND=0,i.UNABLE_TO_CREATE_UPLOAD_DIR=1,i.UPLOAD_ID_NOT_SET=2,i.UPLOAD_ID_INCORRECT=3,i.MALFORMED_REQUEST=4,i.NO_FILE_UPLOADED=5,i.FILE_SIZE_EXCEEDS_LIMIT=6,i.INCORRECT_EXTENSION=7,i.WRITING_FILE_ERROR=8,i.UNABLE_TO_DELETE_UPLOAD_DIR=9,i.UNABLE_TO_DELETE_FILE=10,i.DIR_DOES_NOT_EXIST=11,i.FILES_NOT_SET=12,i.FILE_IS_NOT_IMAGE=13,i.DUPLICATE_NAME=14,i.FILE_ALREADY_EXISTS=15,i.FILES_ERRORS=16,i.UNABLE_TO_COPY_FILE=17,i.IMAGE_PROCESS_ERROR=18,i.MAX_RESIZE_WIDTH_EXCEEDED=19,i.MAX_RESIZE_HEIGHT_EXCEEDED=20,i.UNABLE_TO_WRITE_IMAGE_TO_FILE=21,i.INTERNAL_ERROR=22,i.DOWNLOAD_FAIL_CODE=23,i.DOWNLOAD_FAIL_IO=24,i.DOWNLOAD_FAIL_HOST_DENIED=25,i.DOWNLOAD_FAIL_INCORRECT_URL=26,t.Message=i},function(e,t,s){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.MessageException=class extends Error{constructor(e){super(),this.m_message=e}getFailMessage(){return this.m_message}}},function(e,t){e.exports=s(3)},function(e,t,s){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.RespOk=class{constructor(){this.ok=!0}}},function(e,t,s){"use strict";Object.defineProperty(t,"__esModule",{value:!0});const i=s(3);t.RespFail=class extends i.RespOk{constructor(e){super(),this.ok=!1,this.message=e}}},function(e,t,s){"use strict";Object.defineProperty(t,"__esModule",{value:!0});const i=s(7),r=s(1),n=s(0),o=s(2);t.AActionUploadId=class extends i.AAction{validateUploadId(e){if(null==e.uploadId)throw new r.MessageException(n.Message.createMessage(n.Message.UPLOAD_ID_NOT_SET));let t=this.m_config.getTmpDir()+"/"+e.uploadId;if(!o.existsSync(t)||!o.lstatSync(t).isDirectory())throw new r.MessageException(n.Message.createMessage(n.Message.UPLOAD_ID_INCORRECT))}}},function(e,t,s){"use strict";Object.defineProperty(t,"__esModule",{value:!0});const i=s(2);class r{static getNameWithoutExt(e){let t=r.getExt(e);return null==t?e:e.substring(0,e.length-t.length-1)}static getExt(e){let t=e.lastIndexOf(".");return t>-1?e.substring(t+1):null}static getFreeFileName(e,t,s){let n,o,a=s?0:-1;do{let s=e+(o=0==++a?t:r.getNameWithoutExt(t)+"_"+a+(null!=r.getExt(t)?"."+r.getExt(t):""));n=!i.existsSync(s)}while(!n);return o}static fixFileName(e){let t="";for(let s=0;s<e.length;s++){let i=e.substring(s,s+1);r.PROHIBITED_SYMBOLS.indexOf(i)>-1&&(i="_"),t+=i}return t.toString()}static isFileNameSyntaxOk(e){if(0===e.length||"."===e||e.indexOf("..")>-1)return!1;for(let t=0;t<r.PROHIBITED_SYMBOLS.length;t++)if(e.indexOf(r.PROHIBITED_SYMBOLS.charAt(t))>-1)return!1;return!(e.length>260)}static isImage(e){let t=["gif","jpg","jpeg","png","bmp"],s=r.getExt(e);for(let e=0;e<t.length;e++)if(t[e]===s)return!0;return!1}}r.PROHIBITED_SYMBOLS='/\\?%*:|"<>',t.Utils=r},function(e,t,s){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.AAction=class{setConfig(e){this.m_config=e}runWithCallback(e,t){try{this.run(e,t)}catch(e){console.log(e),t(e)}}validateBoolean(e,t){return null==e?t:e}validateInteger(e,t){return null==e?t:e}validateString(e,t){return null==e?t:e}}},function(e,t,s){"use strict";Object.defineProperty(t,"__esModule",{value:!0});const i=s(10),r=s(0),n=s(6),o=s(2),a=s(1),l=s(21),g=s(23);t.FileUploaded=class extends i.AFile{constructor(e,t,s,i){super(e,t,s),this.m_conflictsErrors=[],this.m_customErrors=[],this.m_newName=i}getBaseDir(){return this.m_config.getTmpDir()}getNewName(){return this.m_newName}checkForErrors(e){if(!super.checkForErrors(e))return!1;if(this.m_newName===this.getName()||n.Utils.isFileNameSyntaxOk(this.m_newName)||this.m_commonErrors.push(r.Message.createMessage(r.Message.FILE_ERROR_SYNTAX,this.m_newName)),n.Utils.isImage(this.getName())){let e=this.getExt(),t=n.Utils.getExt(this.m_newName);e!==t&&("jpg"===e&&"jpeg"===t||"jpeg"===e&&"jpg"===t||this.m_commonErrors.push(r.Message.createMessage(r.Message.FILE_ERROR_INCORRECT_IMAGE_EXT_CHANGE,e,t)))}return!0}addCustomError(e){this.m_customErrors.push(e)}getErrors(){let e=super.getErrors();for(const t of this.m_conflictsErrors)e.push(t);for(const t of this.m_customErrors)e.push(t);return e}getCommitedFile(e){return new l.FileCommited(this.m_config,e,this.m_newName)}checkForConflicts(e){this.m_conflictsErrors=[];let t=this.getCommitedFile(e);if(t.exists()&&this.m_conflictsErrors.push(r.Message.createMessage(r.Message.FILE_ALREADY_EXISTS,t.getName())),t.isImage()){let e=t.getFileOriginal();e.exists()&&this.m_conflictsErrors.push(r.Message.createMessage(r.Message.FILE_ALREADY_EXISTS,e.getName()));let s=t.getFilePreview();s.exists()&&this.m_conflictsErrors.push(r.Message.createMessage(r.Message.FILE_ALREADY_EXISTS,s.getName()))}}uploadAndCommit(e){let t=this.getName();this.setFreeFileName();try{let s=this.getFile();o.writeFileSync(s,e)}catch(e){new a.MessageException(r.Message.createMessage(r.Message.WRITING_FILE_ERROR,t))}}rehost(e,t){g.URLDownloader.download(e,this.getBaseDir()+"/"+this.getDir(),e=>{e instanceof g.DownloadedURL&&this.setName(e.fileName),t(e)})}commit(e,t){let s=this.getCommitedFile(e);return t&&s.setFreeFileName(),this.copyTo(s),s}isCommited(){return!1}}},function(e,t,s){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.createReqError=function(e){return{action:"error",message:e}}},function(e,t,s){"use strict";Object.defineProperty(t,"__esModule",{value:!0});const i=s(0),r=s(19),n=s(2),o=s(1),a=s(20),l=s(6);t.AFile=class{constructor(e,t,s){this.m_name=null,this.m_dir=null,this.m_commonErrors=[],this.m_config=e,this.m_dir=t,this.m_name=s}getData(){let e=new r.FileData;if(e.isCommited=this.isCommited(),e.name=this.getName(),e.dir=this.getDir(),e.bytes=this.getSize(),e.errors=this.getErrors(),e.isImage=this.isImage(),e.isImage){try{e.width=this.getImageWidth(),e.height=this.getImageHeight()}catch(t){e.width=null,e.height=null}if(e.isCommited&&(e.sizes={},null==this.m_mainFile)){let t=this.getModifications();for(let s=0;s<t.length;s++)e.sizes[t[s].getModificationName()]=t[s].getData()}}return e}getModifications(){return[]}getModificationName(){return null}getSize(){let e=this.getFile();return n.existsSync(e)?n.lstatSync(e).size:0}getErrors(){let e=[];for(const t of this.m_commonErrors)e.push(t);return e}checkForErrors(e){return this.m_commonErrors=[],l.Utils.isFileNameSyntaxOk(this.getName())?(e&&!this.exists()&&this.m_commonErrors.push(i.Message.createMessage(i.Message.FILE_ERROR_DOES_NOT_EXIST)),!0):(this.m_commonErrors.push(i.Message.createMessage(i.Message.FILE_ERROR_SYNTAX,this.getName())),!1)}setName(e){this.m_name=e}setDir(e){this.m_dir=e}getName(){return this.m_name}getDir(){return 0!==this.m_dir.length&&"/"!==this.m_dir.substr(this.m_dir.length-1)?this.m_dir+"/":this.m_dir}getUrlUploader(){let e=this.getDir()+this.getName();return e.startsWith("/")&&(e=e.substr(1)),e}getFullPath(){return this.getBaseDir()+this.getUrlUploader()}getExt(){return l.Utils.getExt(this.m_name)}getNameWithoutExt(){return l.Utils.getNameWithoutExt(this.m_name)}getFile(){return this.getFullPath()}exists(){try{return n.existsSync(this.getFile())}catch(e){return!1}}delete(){try{n.unlinkSync(this.getFile())}catch(e){throw new o.MessageException(i.Message.createMessage(i.Message.UNABLE_TO_DELETE_FILE,this.getName()))}}isImage(){return l.Utils.isImage(this.getName())}getImageWidth(){try{return a(this.getImage()).width}catch(e){throw console.log(e),new o.MessageException(i.Message.createMessage(i.Message.IMAGE_PROCESS_ERROR))}}getImageHeight(){try{return a(this.getImage()).height}catch(e){throw console.log(e),new o.MessageException(i.Message.createMessage(i.Message.IMAGE_PROCESS_ERROR))}}getImage(){return this.getFile()}setFreeFileName(){let e=l.Utils.getFreeFileName(this.getBaseDir()+this.getDir(),this.getName(),!1);this.setName(e)}copyTo(e){try{n.copySync(this.getFile(),e.getFile())}catch(t){throw console.log(t),new o.MessageException(i.Message.createMessage(i.Message.UNABLE_TO_COPY_FILE,this.getName(),e.getName()))}}}},function(e,t,s){"use strict";Object.defineProperty(t,"__esModule",{value:!0});const i=s(12),r=s(13);class n{constructor(e,t,s){this.app=e,this.url=t,this.config=s,this.servlet=new r.UploaderServlet(s),e.post("/uploader",(e,t)=>{this.upload(e,t)}),e.options("/uploader",(e,t)=>{this.uploadOptions(e,t)})}upload(e,t){let s=new i({headers:e.headers});s.on("file",function(t,s,i,r,n){"file"===t&&(e.postFile={filename:i,data:null},s.on("data",function(t){let s=e.postFile.data,i=null==s?t:Buffer.concat([s,t]);e.postFile.data=i}))}),s.on("field",(t,s,i,r,n,o)=>{"data"===t&&(e.postData=s)}),s.on("finish",()=>{this.servlet.doPost(e,t)}),e.pipe(s)}uploadOptions(e,t){this.servlet.doOptions(e,t),t.sendStatus(200)}}t.bindFileUploader=function(e){e.config.dirFiles=e.dir,new n(e.app,e.url,e.config)}},function(e,t){e.exports=s(4)},function(e,t,s){"use strict";Object.defineProperty(t,"__esModule",{value:!0});const i=s(14),r=s(31),n=s(32),o=s(33),a=s(0),l=s(9),g=s(2);t.UploaderServlet=class{constructor(e={}){this.m_conf=e,this.m_actions=new i.Actions,this.m_json=new r.JsonCodec,this.m_config=new o.ServletConfig(this.m_conf),this.m_uploader=new n.Uploader(this.m_config,this.m_actions)}getReq(e){let t,s,i=e.postData,r=null,n=-1;e.postFile&&(t=e.postFile.data,r=e.postFile.filename,n=t.length);try{s=this.m_json.fromJson(i),this.m_config.isTestAllowed()&&(null!=s.test_serverConfig&&this.m_config.setTestConfig(s.test_serverConfig),null!=s.test_clearAllFiles&&s.test_clearAllFiles&&this.clearAllFiles())}catch(e){return console.log(e),null}return null!=r&&(s.m_fileName=r,s.m_fileSize=n,s.m_file=t),s}clearAllFiles(){g.removeSync(this.m_config.getTmpDir()),g.mkdirsSync(this.m_config.getTmpDir()),g.removeSync(this.m_config.getBaseDir()),g.mkdirsSync(this.m_config.getBaseDir())}addHeaders(e){null!=this.m_config.getCrossDomainUrl()&&this.m_config.getCrossDomainUrl().length>0&&(e.setHeader("Access-Control-Allow-Origin",this.m_config.getCrossDomainUrl()),e.setHeader("Access-Control-Allow-Methods","POST"),e.setHeader("Access-Control-Allow-Headers","accept, content-type"),e.setHeader("Access-Control-Max-Age","1728000"))}doOptions(e,t){this.addHeaders(t)}doPost(e,t){let s;this.addHeaders(t);let i=null;try{i=this.getReq(e)}catch(e){console.log(e)}null==i&&(i=l.createReqError(a.Message.createMessage(a.Message.MALFORMED_REQUEST))),this.m_uploader.run(i,e=>{s=this.m_json.toJson(e);try{t.contentType("application/json; charset=UTF-8"),t.send(s)}catch(e){console.log(e)}})}}},function(e,t,s){"use strict";Object.defineProperty(t,"__esModule",{value:!0});const i=s(15),r=s(16),n=s(18),o=s(26),a=s(28),l=s(30);t.Actions=class{constructor(){this.m_actions=[],this.m_actions.push(new i.ActionError),this.m_actions.push(new r.ActionUploadInit),this.m_actions.push(new o.ActionUploadAddFile),this.m_actions.push(new n.ActionUploadRemoveFile),this.m_actions.push(new a.ActionUploadCommit),this.m_actions.push(new l.ActionUploadCancel)}getActionError(){return this.getAction("error")}getAction(e){for(let t=0;t<this.m_actions.length;t++)if(this.m_actions[t].getName()===e)return this.m_actions[t];return null}}},function(e,t,s){"use strict";Object.defineProperty(t,"__esModule",{value:!0});const i=s(7),r=s(4);t.ActionError=class extends i.AAction{getName(){return"error"}run(e,t){let s=e;t(new r.RespFail(s.message))}}},function(e,t,s){"use strict";Object.defineProperty(t,"__esModule",{value:!0});const i=s(7),r=s(2),n=s(1),o=s(0),a=s(17);t.ActionUploadInit=class extends i.AAction{getName(){return"uploadInit"}run(e,t){let s,i,l="abcdefghijklmnopqrstuvwxyz0123456789";do{i="";for(let e=0;e<6;e++){let e=Math.floor(Math.random()*l.length);i+=l.substring(e,e+1)}s=this.m_config.getTmpDir()+"/"+i}while(r.existsSync(s)&&r.lstatSync(s).isDirectory());try{r.mkdirsSync(s)}catch(e){throw console.log(e),new n.MessageException(o.Message.createMessage(o.Message.UNABLE_TO_CREATE_UPLOAD_DIR))}t(new a.RespUploadInit(i,this.m_config))}}},function(e,t,s){"use strict";Object.defineProperty(t,"__esModule",{value:!0});const i=s(3);t.RespUploadInit=class extends i.RespOk{constructor(e,t){super(),this.uploadId=e,this.settings={maxImageResizeWidth:t.getMaxImageResizeWidth(),maxImageResizeHeight:t.getMaxImageResizeHeight()}}}},function(e,t,s){"use strict";Object.defineProperty(t,"__esModule",{value:!0});const i=s(5),r=s(3),n=s(1),o=s(0),a=s(8);t.ActionUploadRemoveFile=class extends i.AActionUploadId{getName(){return"uploadRemoveFile"}run(e){return new Promise((t,s)=>{let i=e;this.validateUploadId(i);let l=new a.FileUploaded(this.m_config,i.uploadId,i.name,i.name);l.checkForErrors(!0),l.getErrors().length>0?s(new n.MessageException(o.Message.createMessageByFile(o.Message.UNABLE_TO_DELETE_UPLOAD_DIR,l.getData()))):(l.delete(),t(new r.RespOk))})}}},function(e,t,s){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.FileData=class{}},function(e,t){e.exports=s(5)},function(e,t,s){"use strict";Object.defineProperty(t,"__esModule",{value:!0});const i=s(10),r=s(2),n=s(6),o=s(0),a=s(1),l=s(22);class g extends i.AFile{constructor(e,t,s){super(e,t,s)}getBaseDir(){return this.m_config.getBaseDir()}getFileModification(e){if(!this.isImage()||null!=this.m_mainFile)throw new Error("Illegal argument");let t=this.getNameWithoutExt()+"-"+e+"."+this.getExt(),s=new g(this.m_config,this.getDir(),t);return s.m_modificationName=e,s.m_mainFile=this,s}getFileOriginal(){return this.getFileModification("original")}getFilePreview(){return this.getFileModification("preview")}getModificationName(){return this.m_modificationName}getModifications(){let e=[],t=this.getFilePreview();return t.exists()&&e.push(t),(t=this.getFileOriginal()).exists()&&e.push(t),e}applySizes(e,t){try{if(!this.isImage())return void t(null);let s=-1,i=-1,r=this.getFilePreview();r.exists()&&(s=r.getImageWidth(),i=r.getImageHeight());let n=this.getImageWidth(),o=this.getImageHeight(),a=this.getFileOriginal(),l=this;a.exists()&&(l=a);let g=l.getImageWidth(),c=l.getImageHeight();this.applySizePreview(r,l,s,i,g,c,e,s=>{null==s||-1===s?this.applySizeFull(a,n,o,g,c,e,e=>{t(null==e?null:e)}):t(s)})}catch(e){t(e)}}applySizeFull(e,t,s,i,r,n,o){let a=!1,l=n[g.SIZE_FULL];if(g.SIZE_FULL in n&&(l.width===t&&l.height===s||(l.width>0||l.height>0)&&(l.width<i||l.height<r||l.enlarge)&&(a=!0)),a)try{let t=e.exists();t||this.copyTo(e),this.resizeImage(l,function(){let s=e;return e=>{e&&!t&&s.exists()&&s.delete(),o(-1===e?null:e)}}())}catch(e){o(e)}else o(null)}applySizePreview(e,t,s,i,r,n,o,a){let l=!1,c=o[g.SIZE_PREVIEW];if(g.SIZE_PREVIEW in o&&(e.exists()||t.copyTo(e),c.width===s&&c.height===i||(c.width>0||c.height>0)&&(c.width<r||c.height<n||c.enlarge)&&(l=!0)),l)try{e.resizeImage(c,e=>{a(-1===e?null:e)})}catch(e){a(e)}else a(null)}getSizes(){let e=this.getFile(),t=this.getNameWithoutExt(),s=this.getBaseDir()+"/"+this.getDir(),i=r.readdirSync(s),o=[];for(let s=0;s<i.length;s++){let r=i[s],a=n.Utils.getNameWithoutExt(r);e!==r&&0===a.indexOf(t+"-")&&o.push(a.substr(t.length+1))}return o}resizeImage(e,t){if(this.m_config.getMaxImageResizeWidth()>0&&e.width>this.m_config.getMaxImageResizeWidth())return void t(new a.MessageException(o.Message.createMessage(o.Message.MAX_RESIZE_WIDTH_EXCEEDED,e.width.toString(),this.getName(),this.m_config.getMaxImageResizeWidth().toString())));if(this.m_config.getMaxImageResizeHeight()>0&&e.height>this.m_config.getMaxImageResizeHeight())return void t(new a.MessageException(o.Message.createMessage(o.Message.MAX_RESIZE_HEIGHT_EXCEEDED,e.height.toString(),this.getName(),this.m_config.getMaxImageResizeHeight().toString())));let s=this;null!=this.m_mainFile&&(s=this.m_mainFile);let i=s.getFileOriginal();i.exists()&&(s=i);let r=this.getImageWidth(),n=this.getImageHeight();if(0===e.width&&0===e.height)return void t(null);if(0===e.width&&e.height===n)return void t(null);if(0===e.height&&e.width===r)return void t(null);if(e.width>0&&e.height>0&&e.width===r&&e.height===n)return void t(null);let l=-1,c=-1;if(e.width>0&&e.height>0?(l=e.width,c=e.height):e.width>0?(l=e.width,c=Math.floor(l/r*n)):e.height>0&&(c=e.height,l=Math.floor(c/n*r)),(l>r||c>n)&&!e.enlarge&&(l=r,c=n),this.m_config.getMaxImageResizeWidth()>0&&l>this.m_config.getMaxImageResizeWidth()||this.m_config.getMaxImageResizeHeight()>0&&c>this.m_config.getMaxImageResizeHeight()){let e=Math.max(l/this.m_config.getMaxImageResizeWidth(),c/this.m_config.getMaxImageResizeHeight());l=Math.floor(l/e),c=Math.floor(c/e)}let h=-1,u=-1;if(l/r<c/n?(h=l,u=Math.floor(h/r*n)):(u=c,h=Math.floor(u/n*r)),l===r&&h===r&&c===n&&u===n)return void t(-1);let m=g.FIT_EXACT;0===e.width?m=g.FIT_TO_HEIGHT:0===e.height&&(m=g.FIT_TO_WIDTH),(l>h||c>u)&&(h=l,u=c),this.resizeImageNative(this.getImage(),h,u,m).write(this.getImage(),(e,s,i,r)=>{t(e?new a.MessageException(o.Message.createMessage(o.Message.UNABLE_TO_WRITE_IMAGE_TO_FILE,this.getName())):null)})}resizeImageNative(e,t,s,i){let r=t,n=s;i===g.FIT_TO_WIDTH?n=Math.round(r*s/t):i===g.FIT_TO_HEIGHT&&(r=Math.round(n*t/s));let o=l.subClass({imageMagick:!0})(e);return o.resize(r,n).gravity("Center").background("none").extent(r,n),o}isCommited(){return!0}}g.SIZE_PREVIEW="preview",g.SIZE_FULL="full",g.FIT_EXACT=0,g.FIT_TO_WIDTH=1,g.FIT_TO_HEIGHT=2,t.FileCommited=g},function(e,t){e.exports=s(6)},function(e,t,s){"use strict";Object.defineProperty(t,"__esModule",{value:!0});const i=s(1),r=s(0),n=s(24),o=s(6),a=s(25);class l{constructor(){this.fileName=null,this.contentType=null,this.contentLength=-1}}t.DownloadedURL=l,t.URLDownloader=class{static download(e,t,s){a({url:e,headers:{"User-Agent":"Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.11 (KHTML, like Gecko) Chrome/23.0.1271.95 Safari/537.11"},encoding:"binary"},(a,g,c)=>{try{if(200===g.statusCode){let a=g.headers["content-disposition"],h=new l;h.contentType=g.headers["content-type"],h.contentLength=parseInt(g.headers["content-length"]);let u="";if(a){let e=a.indexOf("filename=");e>0&&(u=a.substring(e+10,a.length-1))}if(0===u.trim().length){let t=(u=e.substring(e.lastIndexOf("/")+1,e.length)).indexOf("?");t>-1&&(u=u.substring(0,t))}0===u.trim().length&&(u="url"),u=o.Utils.fixFileName(u),u=o.Utils.getFreeFileName(t,u,!1);let m=t+"/"+u;try{n.writeFileSync(m,c,{encoding:"binary"})}catch(e){return void s(new i.MessageException(r.Message.createMessage(r.Message.WRITING_FILE_ERROR,u)))}h.fileName=u,s(h)}else s(new i.MessageException(r.Message.createMessage(r.Message.DOWNLOAD_FAIL_CODE,g.statusCode.toString())))}catch(e){console.log(e),s(new i.MessageException(r.Message.createMessage(r.Message.INTERNAL_ERROR)))}})}}},function(e,t){e.exports=s(7)},function(e,t){e.exports=s(8)},function(e,t,s){"use strict";Object.defineProperty(t,"__esModule",{value:!0});const i=s(5),r=s(1),n=s(0),o=s(27),a=s(8),l=s(4);t.ActionUploadAddFile=class extends i.AActionUploadId{getName(){return"uploadAddFile"}run(e,t){let s,i=e;if(this.validateUploadId(i),null==i.url){if(null==i.m_fileName||null==i.m_file)throw new r.MessageException(n.Message.createMessage(n.Message.NO_FILE_UPLOADED));if(this.m_config.getMaxUploadFileSize()>0&&i.m_fileSize>this.m_config.getMaxUploadFileSize())throw new r.MessageException(n.Message.createMessage(n.Message.FILE_SIZE_EXCEEDS_LIMIT,i.m_fileName,i.m_fileSize.toString(),this.m_config.getMaxUploadFileSize().toString()));let e=(s=new a.FileUploaded(this.m_config,i.uploadId,i.m_fileName,i.m_fileName)).getExt().toLowerCase(),l=this.m_config.getAllowedExtensions(),g=0===l.length;for(let t=0;t<l.length&&!g;t++)g=l[t]===e;if(!g){let e="";for(let t=0;t<l.length;t++)t>0&&(e+=", "),e+=l[t];throw new r.MessageException(n.Message.createMessage(n.Message.INCORRECT_EXTENSION,i.m_fileName,e.toString()))}s.uploadAndCommit(i.m_file);let c=new o.RespUploadAddFile;c.file=s.getData(),t(c)}else{let g=this.m_config.getRelocateFromHosts(),c=null;try{c=new URL(i.url).hostname}catch(e){if(e instanceof TypeError)throw new r.MessageException(n.Message.createMessage(n.Message.DOWNLOAD_FAIL_INCORRECT_URL,i.url))}let h=!1;for(let e=0;e<g.length&&!h;e++)g[e].toLowerCase()===c&&(h=!0);if(0!==g.length&&!h)throw new r.MessageException(n.Message.createMessage(n.Message.DOWNLOAD_FAIL_HOST_DENIED,c));(s=new a.FileUploaded(this.m_config,i.uploadId,null,null)).rehost(i.url,e=>{if(e instanceof r.MessageException)t(new l.RespFail(e.getFailMessage()));else if(e instanceof Error)console.log(e),t(new l.RespFail(n.Message.createMessage(n.Message.INTERNAL_ERROR)));else{let e=new o.RespUploadAddFile;e.file=s.getData(),t(e)}})}}}},function(e,t,s){"use strict";Object.defineProperty(t,"__esModule",{value:!0});const i=s(3);t.RespUploadAddFile=class extends i.RespOk{}},function(e,t,s){"use strict";Object.defineProperty(t,"__esModule",{value:!0});const i=s(5),r=s(3),n=s(1),o=s(0),a=s(2),l=s(29),g=s(8),c=s(4);t.ActionUploadCommit=class extends i.AActionUploadId{getName(){return"uploadCommit"}validateSize(e,t){e.enlarge=this.validateBoolean(e.enlarge,"preview"===t),e.width=this.validateInteger(e.width,0),e.height=this.validateInteger(e.height,0)}validateSizes(e){if(null==e.sizes)e.sizes={};else{let t=["full","preview"];for(let s=0;s<t.length;s++)t[s]in e.sizes&&this.validateSize(e.sizes[t[s]],t[s])}}normalizeNoEndSeparator(e){return e.indexOf("..")>-1?null:(e.length>0&&"/"===e.substr(0,1)&&(e=e.substr(1)),e)}run(e,t){let s=e;if(this.validateUploadId(s),this.validateSizes(s),s.doCommit=this.validateBoolean(s.doCommit,!0),s.autoRename=this.validateBoolean(s.autoRename,!1),s.dir=this.validateString(s.dir,""),null==this.normalizeNoEndSeparator(s.dir))throw new n.MessageException(o.Message.createMessage(o.Message.DIR_DOES_NOT_EXIST,s.dir));s.dir=this.normalizeNoEndSeparator(s.dir)+"/";let i=this.m_config.getBaseDir()+s.dir;if(!a.existsSync(i))throw new n.MessageException(o.Message.createMessage(o.Message.DIR_DOES_NOT_EXIST,s.dir));if(null==s.files||0===s.files.length)throw new n.MessageException(o.Message.createMessage(o.Message.FILES_NOT_SET));let h=[];for(let e=0;e<s.files.length;e++){let t=s.files[e];if(null==t.name)throw new n.MessageException(o.Message.createMessage(o.Message.MALFORMED_REQUEST));null==t.newName&&(t.newName=t.name);let i=new g.FileUploaded(this.m_config,s.uploadId,t.name,t.newName);h.push(i),i.isImage()||0===Object.keys(s.sizes).length||i.addCustomError(o.Message.createMessage(o.Message.FILE_IS_NOT_IMAGE))}for(let e=0;e<h.length;e++){let t=h[e].getNewName();for(let s=0;s<h.length;s++){let i=h[s].getNewName();if(e!==s&&t===i){h[e].addCustomError(o.Message.createMessage(o.Message.DUPLICATE_NAME));break}}}for(let e=0;e<h.length;e++){let t=h[e];t.checkForErrors(!0),s.autoRename||t.checkForConflicts(s.dir)}let u=[];for(let e=0;e<h.length;e++)h[e].getErrors().length>0&&u.push(h[e].getData());if(u.length>0)throw new n.MessageException(o.Message.createMessageByFiles(o.Message.FILES_ERRORS,u));if(s.doCommit){this.filesCommitedCount=0,this.filesCommited=[];for(let e=0;e<h.length;e++){let t=h[e].commit(s.dir,s.autoRename);this.filesCommited.push(t)}this.applySizes(s.sizes,e=>{if(null!=e)return void(e instanceof n.MessageException?t(new c.RespFail(e.getFailMessage())):t(new c.RespFail(o.Message.createMessage(o.Message.INTERNAL_ERROR))));if(!this.m_config.doKeepUploads())try{a.removeSync(this.m_config.getTmpDir()+"/"+s.uploadId)}catch(e){console.log(e)}let i=[];for(let e=0;e<this.filesCommited.length;e++)i.push(this.filesCommited[e].getData());let r=new l.RespUploadCommit;r.files=i,t(r)})}else t(new r.RespOk)}applySizes(e,t){if(this.filesCommitedCount===this.filesCommited.length)t(null);else try{this.filesCommited[this.filesCommitedCount].applySizes(e,s=>{if(null!=s){for(let e=0;e<this.filesCommited.length;e++)this.filesCommited[e].delete();t(s)}this.filesCommitedCount++,this.applySizes(e,t)})}catch(e){for(let e=0;e<this.filesCommited.length;e++)this.filesCommited[e].delete();t(e)}}}},function(e,t,s){"use strict";Object.defineProperty(t,"__esModule",{value:!0});const i=s(3);t.RespUploadCommit=class extends i.RespOk{}},function(e,t,s){"use strict";Object.defineProperty(t,"__esModule",{value:!0});const i=s(5),r=s(3),n=s(2),o=s(1),a=s(0);t.ActionUploadCancel=class extends i.AActionUploadId{getName(){return"uploadCancel"}run(e,t){let s=e;if(this.validateUploadId(s),!this.m_config.doKeepUploads())try{n.removeSync(this.m_config.getTmpDir()+"/"+s.uploadId)}catch(e){throw console.log(e),new o.MessageException(a.Message.createMessage(a.Message.UNABLE_TO_DELETE_UPLOAD_DIR))}t(new r.RespOk)}}},function(e,t,s){"use strict";Object.defineProperty(t,"__esModule",{value:!0});const i=s(9),r=s(0);t.JsonCodec=class{fromJson(e){try{let t=JSON.parse(e);return"error"===t.action&&(t=i.createReqError(r.Message.createMessage(r.Message.ACTION_NOT_FOUND))),t}catch(e){return i.createReqError(r.Message.createMessage(r.Message.MALFORMED_REQUEST))}}toJson(e){return JSON.stringify(e)}}},function(e,t,s){"use strict";Object.defineProperty(t,"__esModule",{value:!0});const i=s(1),r=s(9),n=s(0),o=s(4);t.Uploader=class{constructor(e,t){this.m_config=e,this.m_actions=t}run(e,t){try{let s=this.m_actions.getAction(e.action);null==s&&(s=this.m_actions.getActionError(),e=r.createReqError(n.Message.createMessage(n.Message.ACTION_NOT_FOUND))),s.setConfig(this.m_config);let a=null;s.runWithCallback(e,e=>{let s=null;s=e instanceof i.MessageException?new o.RespFail(e.getFailMessage()):e instanceof Error?new o.RespFail(n.Message.createMessage(n.Message.INTERNAL_ERROR)):e,t(s)})}catch(e){console.log(e),a=new o.RespFail(n.Message.createMessage(n.Message.INTERNAL_ERROR)),t(a)}}}},function(e,t,s){"use strict";(function(e){Object.defineProperty(t,"__esModule",{value:!0});const i=s(2);t.ServletConfig=class{constructor(e){this.m_testConf={},this.m_conf=e}setTestConfig(e){this.m_testConf=e}getParameter(e,t,s){if(e in this.m_testConf)return this.addTrailingSlash(this.m_testConf[e],s);{let i=this.m_conf[e];return null!=i?this.addTrailingSlash(i,s):t}}addTrailingSlash(e,t){return null==e||!t||0!==e.length&&"/"===e.substring(e.length-1)||(e+="/"),e}getParameterStr(e,t){return this.getParameter(e,t,!1)}getParameterInt(e,t){return this.getParameter(e,t,!1)}getParameterBool(e,t){return this.getParameter(e,t,!1)}getBaseDir(){let t=e;1===t.length&&(t=t.substr(1));let s=this.getParameter("dirFiles",t+"files/",!0);return i.existsSync(s)||i.mkdirsSync(s),s}getTmpDir(){let e=this.getParameter("dirTmp",this.getBaseDir()+"tmp/",!0);return i.existsSync(e)||i.mkdirsSync(e),e}getMaxUploadFileSize(){return this.getParameterInt("maxUploadFileSize",0)}getAllowedExtensions(){let e=this.getParameterStr("allowedExtensions",null);if(null==e)return[];let t=e.split(",");for(let e=0;e<t.length;e++)t[e]=t[e].toLowerCase();return t}getJpegQuality(){return this.getParameterInt("jpegQuality",95)}getMaxImageResizeWidth(){return this.getParameterInt("maxImageResizeWidth",5e3)}getMaxImageResizeHeight(){return this.getParameterInt("maxImageResizeHeight",5e3)}getCrossDomainUrl(){return this.getParameterStr("crossDomainUrl",null)}doKeepUploads(){return this.getParameterBool("keepUploads",!1)}isTestAllowed(){return this.getParameterBool("isTestAllowed",!1)}getRelocateFromHosts(){let e=this.getParameterStr("relocateFromHosts","").split(","),t=[];for(let s=0;s<e.length;s++){let i=e[s].trim().toLowerCase();i.length>0&&t.push(i)}return t}}}).call(this,"/")}]))},function(e,t){e.exports=require("fs-extra")},function(e,t){e.exports=require("busboy")},function(e,t){e.exports=require("image-size")},function(e,t){e.exports=require("gm")},function(e,t){e.exports=require("fs")},function(e,t){e.exports=require("request")}])); | ||
!function(e,t){for(var s in t)e[s]=t[s]}(exports,function(e){var t={};function s(i){if(t[i])return t[i].exports;var r=t[i]={i:i,l:!1,exports:{}};return e[i].call(r.exports,r,r.exports,s),r.l=!0,r.exports}return s.m=e,s.c=t,s.d=function(e,t,i){s.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:i})},s.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},s.t=function(e,t){if(1&t&&(e=s(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var i=Object.create(null);if(s.r(i),Object.defineProperty(i,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var r in e)s.d(i,r,function(t){return e[t]}.bind(null,r));return i},s.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return s.d(t,"a",t),t},s.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},s.p="",s(s.s=0)}([function(e,t,s){"use strict";Object.defineProperty(t,"__esModule",{value:!0});const i=s(1),r=s(2);t.startFileUploaderMicroservice=function(e){let t=i();return r.bindFileUploader({app:t,url:e.urlUploader?e.urlUploader:"/",dir:e.dirFiles}),e.dirRoot&&t.use(i.static(e.dirRoot)),t.listen(e.port?e.port:8080,e.host?e.host:"localhost",()=>{console.log("Image Editor SDK microservice started on localhost:8080")}),t}},function(e,t){e.exports=require("express")},function(e,t,s){!function(e,t){for(var s in t)e[s]=t[s]}(t,function(e){var t={};function s(i){if(t[i])return t[i].exports;var r=t[i]={i:i,l:!1,exports:{}};return e[i].call(r.exports,r,r.exports,s),r.l=!0,r.exports}return s.m=e,s.c=t,s.d=function(e,t,i){s.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:i})},s.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},s.t=function(e,t){if(1&t&&(e=s(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var i=Object.create(null);if(s.r(i),Object.defineProperty(i,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var r in e)s.d(i,r,function(t){return e[t]}.bind(null,r));return i},s.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return s.d(t,"a",t),t},s.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},s.p="",s(s.s=11)}([function(e,t,s){"use strict";Object.defineProperty(t,"__esModule",{value:!0});class i{static createMessage(e,t=null,s=null,r=null){let n=new i;return n.code=e,null!=t&&(n.args=[],n.args.push(t),null!=s&&n.args.push(s),null!=r&&n.args.push(r)),n}static createMessageByFiles(e,t){let s=new i;return s.code=e,s.files=t,s}static createMessageByFile(e,t){let s=new i;return s.code=e,s.files=[],s.files.push(t),s}}i.FILE_ERROR_SYNTAX=-1,i.FILE_ERROR_DOES_NOT_EXIST=-2,i.FILE_ERROR_INCORRECT_IMAGE_EXT_CHANGE=-3,i.ACTION_NOT_FOUND=0,i.UNABLE_TO_CREATE_UPLOAD_DIR=1,i.UPLOAD_ID_NOT_SET=2,i.UPLOAD_ID_INCORRECT=3,i.MALFORMED_REQUEST=4,i.NO_FILE_UPLOADED=5,i.FILE_SIZE_EXCEEDS_LIMIT=6,i.INCORRECT_EXTENSION=7,i.WRITING_FILE_ERROR=8,i.UNABLE_TO_DELETE_UPLOAD_DIR=9,i.UNABLE_TO_DELETE_FILE=10,i.DIR_DOES_NOT_EXIST=11,i.FILES_NOT_SET=12,i.FILE_IS_NOT_IMAGE=13,i.DUPLICATE_NAME=14,i.FILE_ALREADY_EXISTS=15,i.FILES_ERRORS=16,i.UNABLE_TO_COPY_FILE=17,i.IMAGE_PROCESS_ERROR=18,i.MAX_RESIZE_WIDTH_EXCEEDED=19,i.MAX_RESIZE_HEIGHT_EXCEEDED=20,i.UNABLE_TO_WRITE_IMAGE_TO_FILE=21,i.INTERNAL_ERROR=22,i.DOWNLOAD_FAIL_CODE=23,i.DOWNLOAD_FAIL_IO=24,i.DOWNLOAD_FAIL_HOST_DENIED=25,i.DOWNLOAD_FAIL_INCORRECT_URL=26,t.Message=i},function(e,t,s){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.MessageException=class extends Error{constructor(e){super(),this.m_message=e}getFailMessage(){return this.m_message}}},function(e,t){e.exports=s(3)},function(e,t,s){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.RespOk=class{constructor(){this.ok=!0}}},function(e,t,s){"use strict";Object.defineProperty(t,"__esModule",{value:!0});const i=s(3);t.RespFail=class extends i.RespOk{constructor(e){super(),this.ok=!1,this.message=e}}},function(e,t,s){"use strict";Object.defineProperty(t,"__esModule",{value:!0});const i=s(7),r=s(1),n=s(0),o=s(2);t.AActionUploadId=class extends i.AAction{validateUploadId(e){if(null==e.uploadId)throw new r.MessageException(n.Message.createMessage(n.Message.UPLOAD_ID_NOT_SET));let t=this.m_config.getTmpDir()+"/"+e.uploadId;if(!o.existsSync(t)||!o.lstatSync(t).isDirectory())throw new r.MessageException(n.Message.createMessage(n.Message.UPLOAD_ID_INCORRECT))}}},function(e,t,s){"use strict";Object.defineProperty(t,"__esModule",{value:!0});const i=s(2);class r{static getNameWithoutExt(e){let t=r.getExt(e);return null==t?e:e.substring(0,e.length-t.length-1)}static getExt(e){let t=e.lastIndexOf(".");return t>-1?e.substring(t+1):null}static getFreeFileName(e,t,s){let n,o,a=s?0:-1;do{let s=e+(o=0==++a?t:r.getNameWithoutExt(t)+"_"+a+(null!=r.getExt(t)?"."+r.getExt(t):""));n=!i.existsSync(s)}while(!n);return o}static fixFileName(e){let t="";for(let s=0;s<e.length;s++){let i=e.substring(s,s+1);r.PROHIBITED_SYMBOLS.indexOf(i)>-1&&(i="_"),t+=i}return t.toString()}static isFileNameSyntaxOk(e){if(0===e.length||"."===e||e.indexOf("..")>-1)return!1;for(let t=0;t<r.PROHIBITED_SYMBOLS.length;t++)if(e.indexOf(r.PROHIBITED_SYMBOLS.charAt(t))>-1)return!1;return!(e.length>260)}static isImage(e){let t=["gif","jpg","jpeg","png","bmp"],s=r.getExt(e);for(let e=0;e<t.length;e++)if(t[e]===s)return!0;return!1}}r.PROHIBITED_SYMBOLS='/\\?%*:|"<>',t.Utils=r},function(e,t,s){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.AAction=class{setConfig(e){this.m_config=e}runWithCallback(e,t){try{this.run(e,t)}catch(e){console.log(e),t(e)}}validateBoolean(e,t){return null==e?t:e}validateInteger(e,t){return null==e?t:e}validateString(e,t){return null==e?t:e}}},function(e,t,s){"use strict";Object.defineProperty(t,"__esModule",{value:!0});const i=s(10),r=s(0),n=s(6),o=s(2),a=s(1),l=s(21),g=s(23);t.FileUploaded=class extends i.AFile{constructor(e,t,s,i){super(e,t,s),this.m_conflictsErrors=[],this.m_customErrors=[],this.m_newName=i}getBaseDir(){return this.m_config.getTmpDir()}getNewName(){return this.m_newName}checkForErrors(e){if(!super.checkForErrors(e))return!1;if(this.m_newName===this.getName()||n.Utils.isFileNameSyntaxOk(this.m_newName)||this.m_commonErrors.push(r.Message.createMessage(r.Message.FILE_ERROR_SYNTAX,this.m_newName)),n.Utils.isImage(this.getName())){let e=this.getExt(),t=n.Utils.getExt(this.m_newName);e!==t&&("jpg"===e&&"jpeg"===t||"jpeg"===e&&"jpg"===t||this.m_commonErrors.push(r.Message.createMessage(r.Message.FILE_ERROR_INCORRECT_IMAGE_EXT_CHANGE,e,t)))}return!0}addCustomError(e){this.m_customErrors.push(e)}getErrors(){let e=super.getErrors();for(const t of this.m_conflictsErrors)e.push(t);for(const t of this.m_customErrors)e.push(t);return e}getCommitedFile(e){return new l.FileCommited(this.m_config,e,this.m_newName)}checkForConflicts(e){this.m_conflictsErrors=[];let t=this.getCommitedFile(e);if(t.exists()&&this.m_conflictsErrors.push(r.Message.createMessage(r.Message.FILE_ALREADY_EXISTS,t.getName())),t.isImage()){let e=t.getFileOriginal();e.exists()&&this.m_conflictsErrors.push(r.Message.createMessage(r.Message.FILE_ALREADY_EXISTS,e.getName()));let s=t.getFilePreview();s.exists()&&this.m_conflictsErrors.push(r.Message.createMessage(r.Message.FILE_ALREADY_EXISTS,s.getName()))}}uploadAndCommit(e){let t=this.getName();this.setFreeFileName();try{let s=this.getFile();o.writeFileSync(s,e)}catch(e){new a.MessageException(r.Message.createMessage(r.Message.WRITING_FILE_ERROR,t))}}rehost(e,t){g.URLDownloader.download(e,this.getBaseDir()+"/"+this.getDir(),e=>{e instanceof g.DownloadedURL&&this.setName(e.fileName),t(e)})}commit(e,t){let s=this.getCommitedFile(e);return t&&s.setFreeFileName(),this.copyTo(s),s}isCommited(){return!1}}},function(e,t,s){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.createReqError=function(e){return{action:"error",message:e}}},function(e,t,s){"use strict";Object.defineProperty(t,"__esModule",{value:!0});const i=s(0),r=s(19),n=s(2),o=s(1),a=s(20),l=s(6);t.AFile=class{constructor(e,t,s){this.m_name=null,this.m_dir=null,this.m_commonErrors=[],this.m_config=e,this.m_dir=t,this.m_name=s}getData(){let e=new r.FileData;if(e.isCommited=this.isCommited(),e.name=this.getName(),e.dir=this.getDir(),e.bytes=this.getSize(),e.errors=this.getErrors(),e.isImage=this.isImage(),e.isImage){try{e.width=this.getImageWidth(),e.height=this.getImageHeight()}catch(t){e.width=null,e.height=null}if(e.isCommited&&(e.sizes={},null==this.m_mainFile)){let t=this.getModifications();for(let s=0;s<t.length;s++)e.sizes[t[s].getModificationName()]=t[s].getData()}}return e}getModifications(){return[]}getModificationName(){return null}getSize(){let e=this.getFile();return n.existsSync(e)?n.lstatSync(e).size:0}getErrors(){let e=[];for(const t of this.m_commonErrors)e.push(t);return e}checkForErrors(e){return this.m_commonErrors=[],l.Utils.isFileNameSyntaxOk(this.getName())?(e&&!this.exists()&&this.m_commonErrors.push(i.Message.createMessage(i.Message.FILE_ERROR_DOES_NOT_EXIST)),!0):(this.m_commonErrors.push(i.Message.createMessage(i.Message.FILE_ERROR_SYNTAX,this.getName())),!1)}setName(e){this.m_name=e}setDir(e){this.m_dir=e}getName(){return this.m_name}getDir(){return 0!==this.m_dir.length&&"/"!==this.m_dir.substr(this.m_dir.length-1)?this.m_dir+"/":this.m_dir}getUrlUploader(){let e=this.getDir()+this.getName();return e.startsWith("/")&&(e=e.substr(1)),e}getFullPath(){return this.getBaseDir()+this.getUrlUploader()}getExt(){return l.Utils.getExt(this.m_name)}getNameWithoutExt(){return l.Utils.getNameWithoutExt(this.m_name)}getFile(){return this.getFullPath()}exists(){try{return n.existsSync(this.getFile())}catch(e){return!1}}delete(){try{n.unlinkSync(this.getFile())}catch(e){throw new o.MessageException(i.Message.createMessage(i.Message.UNABLE_TO_DELETE_FILE,this.getName()))}}isImage(){return l.Utils.isImage(this.getName())}getImageWidth(){try{return a(this.getImage()).width}catch(e){throw console.log(e),new o.MessageException(i.Message.createMessage(i.Message.IMAGE_PROCESS_ERROR))}}getImageHeight(){try{return a(this.getImage()).height}catch(e){throw console.log(e),new o.MessageException(i.Message.createMessage(i.Message.IMAGE_PROCESS_ERROR))}}getImage(){return this.getFile()}setFreeFileName(){let e=l.Utils.getFreeFileName(this.getBaseDir()+this.getDir(),this.getName(),!1);this.setName(e)}copyTo(e){try{n.copySync(this.getFile(),e.getFile())}catch(t){throw console.log(t),new o.MessageException(i.Message.createMessage(i.Message.UNABLE_TO_COPY_FILE,this.getName(),e.getName()))}}}},function(e,t,s){"use strict";Object.defineProperty(t,"__esModule",{value:!0});const i=s(12),r=s(13);class n{constructor(e,t,s){this.app=e,this.url=t,this.config=s,this.servlet=new r.UploaderServlet(s),e.post("/uploader",(e,t)=>{this.upload(e,t)}),e.options("/uploader",(e,t)=>{this.uploadOptions(e,t)})}upload(e,t){let s=new i({headers:e.headers});s.on("file",function(t,s,i,r,n){"file"===t&&(e.postFile={filename:i,data:null},s.on("data",function(t){let s=e.postFile.data,i=null==s?t:Buffer.concat([s,t]);e.postFile.data=i}))}),s.on("field",(t,s,i,r,n,o)=>{"data"===t&&(e.postData=s)}),s.on("finish",()=>{this.servlet.doPost(e,t)}),e.pipe(s)}uploadOptions(e,t){this.servlet.doOptions(e,t),t.sendStatus(200)}}t.bindFileUploader=function(e){e.config||(e.config={}),e.config.dirFiles=e.dir,new n(e.app,e.url,e.config)}},function(e,t){e.exports=s(4)},function(e,t,s){"use strict";Object.defineProperty(t,"__esModule",{value:!0});const i=s(14),r=s(31),n=s(32),o=s(33),a=s(0),l=s(9),g=s(2);t.UploaderServlet=class{constructor(e={}){this.m_conf=e,this.m_actions=new i.Actions,this.m_json=new r.JsonCodec,this.m_config=new o.ServletConfig(this.m_conf),this.m_uploader=new n.Uploader(this.m_config,this.m_actions)}getReq(e){let t,s,i=e.postData,r=null,n=-1;e.postFile&&(t=e.postFile.data,r=e.postFile.filename,n=t.length);try{s=this.m_json.fromJson(i),this.m_config.isTestAllowed()&&(null!=s.test_serverConfig&&this.m_config.setTestConfig(s.test_serverConfig),null!=s.test_clearAllFiles&&s.test_clearAllFiles&&this.clearAllFiles())}catch(e){return console.log(e),null}return null!=r&&(s.m_fileName=r,s.m_fileSize=n,s.m_file=t),s}clearAllFiles(){g.removeSync(this.m_config.getTmpDir()),g.mkdirsSync(this.m_config.getTmpDir()),g.removeSync(this.m_config.getBaseDir()),g.mkdirsSync(this.m_config.getBaseDir())}addHeaders(e){null!=this.m_config.getCrossDomainUrl()&&this.m_config.getCrossDomainUrl().length>0&&(e.setHeader("Access-Control-Allow-Origin",this.m_config.getCrossDomainUrl()),e.setHeader("Access-Control-Allow-Methods","POST"),e.setHeader("Access-Control-Allow-Headers","accept, content-type"),e.setHeader("Access-Control-Max-Age","1728000"))}doOptions(e,t){this.addHeaders(t)}doPost(e,t){let s;this.addHeaders(t);let i=null;try{i=this.getReq(e)}catch(e){console.log(e)}null==i&&(i=l.createReqError(a.Message.createMessage(a.Message.MALFORMED_REQUEST))),this.m_uploader.run(i,e=>{s=this.m_json.toJson(e);try{t.contentType("application/json; charset=UTF-8"),t.send(s)}catch(e){console.log(e)}})}}},function(e,t,s){"use strict";Object.defineProperty(t,"__esModule",{value:!0});const i=s(15),r=s(16),n=s(18),o=s(26),a=s(28),l=s(30);t.Actions=class{constructor(){this.m_actions=[],this.m_actions.push(new i.ActionError),this.m_actions.push(new r.ActionUploadInit),this.m_actions.push(new o.ActionUploadAddFile),this.m_actions.push(new n.ActionUploadRemoveFile),this.m_actions.push(new a.ActionUploadCommit),this.m_actions.push(new l.ActionUploadCancel)}getActionError(){return this.getAction("error")}getAction(e){for(let t=0;t<this.m_actions.length;t++)if(this.m_actions[t].getName()===e)return this.m_actions[t];return null}}},function(e,t,s){"use strict";Object.defineProperty(t,"__esModule",{value:!0});const i=s(7),r=s(4);t.ActionError=class extends i.AAction{getName(){return"error"}run(e,t){let s=e;t(new r.RespFail(s.message))}}},function(e,t,s){"use strict";Object.defineProperty(t,"__esModule",{value:!0});const i=s(7),r=s(2),n=s(1),o=s(0),a=s(17);t.ActionUploadInit=class extends i.AAction{getName(){return"uploadInit"}run(e,t){let s,i,l="abcdefghijklmnopqrstuvwxyz0123456789";do{i="";for(let e=0;e<6;e++){let e=Math.floor(Math.random()*l.length);i+=l.substring(e,e+1)}s=this.m_config.getTmpDir()+"/"+i}while(r.existsSync(s)&&r.lstatSync(s).isDirectory());try{r.mkdirsSync(s)}catch(e){throw console.log(e),new n.MessageException(o.Message.createMessage(o.Message.UNABLE_TO_CREATE_UPLOAD_DIR))}t(new a.RespUploadInit(i,this.m_config))}}},function(e,t,s){"use strict";Object.defineProperty(t,"__esModule",{value:!0});const i=s(3);t.RespUploadInit=class extends i.RespOk{constructor(e,t){super(),this.uploadId=e,this.settings={maxImageResizeWidth:t.getMaxImageResizeWidth(),maxImageResizeHeight:t.getMaxImageResizeHeight()}}}},function(e,t,s){"use strict";Object.defineProperty(t,"__esModule",{value:!0});const i=s(5),r=s(3),n=s(1),o=s(0),a=s(8);t.ActionUploadRemoveFile=class extends i.AActionUploadId{getName(){return"uploadRemoveFile"}run(e){return new Promise((t,s)=>{let i=e;this.validateUploadId(i);let l=new a.FileUploaded(this.m_config,i.uploadId,i.name,i.name);l.checkForErrors(!0),l.getErrors().length>0?s(new n.MessageException(o.Message.createMessageByFile(o.Message.UNABLE_TO_DELETE_UPLOAD_DIR,l.getData()))):(l.delete(),t(new r.RespOk))})}}},function(e,t,s){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.FileData=class{}},function(e,t){e.exports=s(5)},function(e,t,s){"use strict";Object.defineProperty(t,"__esModule",{value:!0});const i=s(10),r=s(2),n=s(6),o=s(0),a=s(1),l=s(22);class g extends i.AFile{constructor(e,t,s){super(e,t,s)}getBaseDir(){return this.m_config.getBaseDir()}getFileModification(e){if(!this.isImage()||null!=this.m_mainFile)throw new Error("Illegal argument");let t=this.getNameWithoutExt()+"-"+e+"."+this.getExt(),s=new g(this.m_config,this.getDir(),t);return s.m_modificationName=e,s.m_mainFile=this,s}getFileOriginal(){return this.getFileModification("original")}getFilePreview(){return this.getFileModification("preview")}getModificationName(){return this.m_modificationName}getModifications(){let e=[],t=this.getFilePreview();return t.exists()&&e.push(t),(t=this.getFileOriginal()).exists()&&e.push(t),e}applySizes(e,t){try{if(!this.isImage())return void t(null);let s=-1,i=-1,r=this.getFilePreview();r.exists()&&(s=r.getImageWidth(),i=r.getImageHeight());let n=this.getImageWidth(),o=this.getImageHeight(),a=this.getFileOriginal(),l=this;a.exists()&&(l=a);let g=l.getImageWidth(),c=l.getImageHeight();this.applySizePreview(r,l,s,i,g,c,e,s=>{null==s||-1===s?this.applySizeFull(a,n,o,g,c,e,e=>{t(null==e?null:e)}):t(s)})}catch(e){t(e)}}applySizeFull(e,t,s,i,r,n,o){let a=!1,l=n[g.SIZE_FULL];if(g.SIZE_FULL in n&&(l.width===t&&l.height===s||(l.width>0||l.height>0)&&(l.width<i||l.height<r||l.enlarge)&&(a=!0)),a)try{let t=e.exists();t||this.copyTo(e),this.resizeImage(l,function(){let s=e;return e=>{e&&!t&&s.exists()&&s.delete(),o(-1===e?null:e)}}())}catch(e){o(e)}else o(null)}applySizePreview(e,t,s,i,r,n,o,a){let l=!1,c=o[g.SIZE_PREVIEW];if(g.SIZE_PREVIEW in o&&(e.exists()||t.copyTo(e),c.width===s&&c.height===i||(c.width>0||c.height>0)&&(c.width<r||c.height<n||c.enlarge)&&(l=!0)),l)try{e.resizeImage(c,e=>{a(-1===e?null:e)})}catch(e){a(e)}else a(null)}getSizes(){let e=this.getFile(),t=this.getNameWithoutExt(),s=this.getBaseDir()+"/"+this.getDir(),i=r.readdirSync(s),o=[];for(let s=0;s<i.length;s++){let r=i[s],a=n.Utils.getNameWithoutExt(r);e!==r&&0===a.indexOf(t+"-")&&o.push(a.substr(t.length+1))}return o}resizeImage(e,t){if(this.m_config.getMaxImageResizeWidth()>0&&e.width>this.m_config.getMaxImageResizeWidth())return void t(new a.MessageException(o.Message.createMessage(o.Message.MAX_RESIZE_WIDTH_EXCEEDED,e.width.toString(),this.getName(),this.m_config.getMaxImageResizeWidth().toString())));if(this.m_config.getMaxImageResizeHeight()>0&&e.height>this.m_config.getMaxImageResizeHeight())return void t(new a.MessageException(o.Message.createMessage(o.Message.MAX_RESIZE_HEIGHT_EXCEEDED,e.height.toString(),this.getName(),this.m_config.getMaxImageResizeHeight().toString())));let s=this;null!=this.m_mainFile&&(s=this.m_mainFile);let i=s.getFileOriginal();i.exists()&&(s=i);let r=this.getImageWidth(),n=this.getImageHeight();if(0===e.width&&0===e.height)return void t(null);if(0===e.width&&e.height===n)return void t(null);if(0===e.height&&e.width===r)return void t(null);if(e.width>0&&e.height>0&&e.width===r&&e.height===n)return void t(null);let l=-1,c=-1;if(e.width>0&&e.height>0?(l=e.width,c=e.height):e.width>0?(l=e.width,c=Math.floor(l/r*n)):e.height>0&&(c=e.height,l=Math.floor(c/n*r)),(l>r||c>n)&&!e.enlarge&&(l=r,c=n),this.m_config.getMaxImageResizeWidth()>0&&l>this.m_config.getMaxImageResizeWidth()||this.m_config.getMaxImageResizeHeight()>0&&c>this.m_config.getMaxImageResizeHeight()){let e=Math.max(l/this.m_config.getMaxImageResizeWidth(),c/this.m_config.getMaxImageResizeHeight());l=Math.floor(l/e),c=Math.floor(c/e)}let h=-1,u=-1;if(l/r<c/n?(h=l,u=Math.floor(h/r*n)):(u=c,h=Math.floor(u/n*r)),l===r&&h===r&&c===n&&u===n)return void t(-1);let m=g.FIT_EXACT;0===e.width?m=g.FIT_TO_HEIGHT:0===e.height&&(m=g.FIT_TO_WIDTH),(l>h||c>u)&&(h=l,u=c),this.resizeImageNative(this.getImage(),h,u,m).write(this.getImage(),(e,s,i,r)=>{t(e?new a.MessageException(o.Message.createMessage(o.Message.UNABLE_TO_WRITE_IMAGE_TO_FILE,this.getName())):null)})}resizeImageNative(e,t,s,i){let r=t,n=s;i===g.FIT_TO_WIDTH?n=Math.round(r*s/t):i===g.FIT_TO_HEIGHT&&(r=Math.round(n*t/s));let o=l.subClass({imageMagick:!0})(e);return o.resize(r,n).gravity("Center").background("none").extent(r,n),o}isCommited(){return!0}}g.SIZE_PREVIEW="preview",g.SIZE_FULL="full",g.FIT_EXACT=0,g.FIT_TO_WIDTH=1,g.FIT_TO_HEIGHT=2,t.FileCommited=g},function(e,t){e.exports=s(6)},function(e,t,s){"use strict";Object.defineProperty(t,"__esModule",{value:!0});const i=s(1),r=s(0),n=s(24),o=s(6),a=s(25);class l{constructor(){this.fileName=null,this.contentType=null,this.contentLength=-1}}t.DownloadedURL=l,t.URLDownloader=class{static download(e,t,s){a({url:e,headers:{"User-Agent":"Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.11 (KHTML, like Gecko) Chrome/23.0.1271.95 Safari/537.11"},encoding:"binary"},(a,g,c)=>{try{if(200===g.statusCode){let a=g.headers["content-disposition"],h=new l;h.contentType=g.headers["content-type"],h.contentLength=parseInt(g.headers["content-length"]);let u="";if(a){let e=a.indexOf("filename=");e>0&&(u=a.substring(e+10,a.length-1))}if(0===u.trim().length){let t=(u=e.substring(e.lastIndexOf("/")+1,e.length)).indexOf("?");t>-1&&(u=u.substring(0,t))}0===u.trim().length&&(u="url"),u=o.Utils.fixFileName(u),u=o.Utils.getFreeFileName(t,u,!1);let m=t+"/"+u;try{n.writeFileSync(m,c,{encoding:"binary"})}catch(e){return void s(new i.MessageException(r.Message.createMessage(r.Message.WRITING_FILE_ERROR,u)))}h.fileName=u,s(h)}else s(new i.MessageException(r.Message.createMessage(r.Message.DOWNLOAD_FAIL_CODE,g.statusCode.toString())))}catch(e){console.log(e),s(new i.MessageException(r.Message.createMessage(r.Message.INTERNAL_ERROR)))}})}}},function(e,t){e.exports=s(7)},function(e,t){e.exports=s(8)},function(e,t,s){"use strict";Object.defineProperty(t,"__esModule",{value:!0});const i=s(5),r=s(1),n=s(0),o=s(27),a=s(8),l=s(4);t.ActionUploadAddFile=class extends i.AActionUploadId{getName(){return"uploadAddFile"}run(e,t){let s,i=e;if(this.validateUploadId(i),null==i.url){if(null==i.m_fileName||null==i.m_file)throw new r.MessageException(n.Message.createMessage(n.Message.NO_FILE_UPLOADED));if(this.m_config.getMaxUploadFileSize()>0&&i.m_fileSize>this.m_config.getMaxUploadFileSize())throw new r.MessageException(n.Message.createMessage(n.Message.FILE_SIZE_EXCEEDS_LIMIT,i.m_fileName,i.m_fileSize.toString(),this.m_config.getMaxUploadFileSize().toString()));let e=(s=new a.FileUploaded(this.m_config,i.uploadId,i.m_fileName,i.m_fileName)).getExt().toLowerCase(),l=this.m_config.getAllowedExtensions(),g=0===l.length;for(let t=0;t<l.length&&!g;t++)g=l[t]===e;if(!g){let e="";for(let t=0;t<l.length;t++)t>0&&(e+=", "),e+=l[t];throw new r.MessageException(n.Message.createMessage(n.Message.INCORRECT_EXTENSION,i.m_fileName,e.toString()))}s.uploadAndCommit(i.m_file);let c=new o.RespUploadAddFile;c.file=s.getData(),t(c)}else{let g=this.m_config.getRelocateFromHosts(),c=null;try{c=new URL(i.url).hostname}catch(e){if(e instanceof TypeError)throw new r.MessageException(n.Message.createMessage(n.Message.DOWNLOAD_FAIL_INCORRECT_URL,i.url))}let h=!1;for(let e=0;e<g.length&&!h;e++)g[e].toLowerCase()===c&&(h=!0);if(0!==g.length&&!h)throw new r.MessageException(n.Message.createMessage(n.Message.DOWNLOAD_FAIL_HOST_DENIED,c));(s=new a.FileUploaded(this.m_config,i.uploadId,null,null)).rehost(i.url,e=>{if(e instanceof r.MessageException)t(new l.RespFail(e.getFailMessage()));else if(e instanceof Error)console.log(e),t(new l.RespFail(n.Message.createMessage(n.Message.INTERNAL_ERROR)));else{let e=new o.RespUploadAddFile;e.file=s.getData(),t(e)}})}}}},function(e,t,s){"use strict";Object.defineProperty(t,"__esModule",{value:!0});const i=s(3);t.RespUploadAddFile=class extends i.RespOk{}},function(e,t,s){"use strict";Object.defineProperty(t,"__esModule",{value:!0});const i=s(5),r=s(3),n=s(1),o=s(0),a=s(2),l=s(29),g=s(8),c=s(4);t.ActionUploadCommit=class extends i.AActionUploadId{getName(){return"uploadCommit"}validateSize(e,t){e.enlarge=this.validateBoolean(e.enlarge,"preview"===t),e.width=this.validateInteger(e.width,0),e.height=this.validateInteger(e.height,0)}validateSizes(e){if(null==e.sizes)e.sizes={};else{let t=["full","preview"];for(let s=0;s<t.length;s++)t[s]in e.sizes&&this.validateSize(e.sizes[t[s]],t[s])}}normalizeNoEndSeparator(e){return e.indexOf("..")>-1?null:(e.length>0&&"/"===e.substr(0,1)&&(e=e.substr(1)),e)}run(e,t){let s=e;if(this.validateUploadId(s),this.validateSizes(s),s.doCommit=this.validateBoolean(s.doCommit,!0),s.autoRename=this.validateBoolean(s.autoRename,!1),s.dir=this.validateString(s.dir,""),null==this.normalizeNoEndSeparator(s.dir))throw new n.MessageException(o.Message.createMessage(o.Message.DIR_DOES_NOT_EXIST,s.dir));s.dir=this.normalizeNoEndSeparator(s.dir)+"/";let i=this.m_config.getBaseDir()+s.dir;if(!a.existsSync(i))throw new n.MessageException(o.Message.createMessage(o.Message.DIR_DOES_NOT_EXIST,s.dir));if(null==s.files||0===s.files.length)throw new n.MessageException(o.Message.createMessage(o.Message.FILES_NOT_SET));let h=[];for(let e=0;e<s.files.length;e++){let t=s.files[e];if(null==t.name)throw new n.MessageException(o.Message.createMessage(o.Message.MALFORMED_REQUEST));null==t.newName&&(t.newName=t.name);let i=new g.FileUploaded(this.m_config,s.uploadId,t.name,t.newName);h.push(i),i.isImage()||0===Object.keys(s.sizes).length||i.addCustomError(o.Message.createMessage(o.Message.FILE_IS_NOT_IMAGE))}for(let e=0;e<h.length;e++){let t=h[e].getNewName();for(let s=0;s<h.length;s++){let i=h[s].getNewName();if(e!==s&&t===i){h[e].addCustomError(o.Message.createMessage(o.Message.DUPLICATE_NAME));break}}}for(let e=0;e<h.length;e++){let t=h[e];t.checkForErrors(!0),s.autoRename||t.checkForConflicts(s.dir)}let u=[];for(let e=0;e<h.length;e++)h[e].getErrors().length>0&&u.push(h[e].getData());if(u.length>0)throw new n.MessageException(o.Message.createMessageByFiles(o.Message.FILES_ERRORS,u));if(s.doCommit){this.filesCommitedCount=0,this.filesCommited=[];for(let e=0;e<h.length;e++){let t=h[e].commit(s.dir,s.autoRename);this.filesCommited.push(t)}this.applySizes(s.sizes,e=>{if(null!=e)return void(e instanceof n.MessageException?t(new c.RespFail(e.getFailMessage())):t(new c.RespFail(o.Message.createMessage(o.Message.INTERNAL_ERROR))));if(!this.m_config.doKeepUploads())try{a.removeSync(this.m_config.getTmpDir()+"/"+s.uploadId)}catch(e){console.log(e)}let i=[];for(let e=0;e<this.filesCommited.length;e++)i.push(this.filesCommited[e].getData());let r=new l.RespUploadCommit;r.files=i,t(r)})}else t(new r.RespOk)}applySizes(e,t){if(this.filesCommitedCount===this.filesCommited.length)t(null);else try{this.filesCommited[this.filesCommitedCount].applySizes(e,s=>{if(null!=s){for(let e=0;e<this.filesCommited.length;e++)this.filesCommited[e].delete();t(s)}this.filesCommitedCount++,this.applySizes(e,t)})}catch(e){for(let e=0;e<this.filesCommited.length;e++)this.filesCommited[e].delete();t(e)}}}},function(e,t,s){"use strict";Object.defineProperty(t,"__esModule",{value:!0});const i=s(3);t.RespUploadCommit=class extends i.RespOk{}},function(e,t,s){"use strict";Object.defineProperty(t,"__esModule",{value:!0});const i=s(5),r=s(3),n=s(2),o=s(1),a=s(0);t.ActionUploadCancel=class extends i.AActionUploadId{getName(){return"uploadCancel"}run(e,t){let s=e;if(this.validateUploadId(s),!this.m_config.doKeepUploads())try{n.removeSync(this.m_config.getTmpDir()+"/"+s.uploadId)}catch(e){throw console.log(e),new o.MessageException(a.Message.createMessage(a.Message.UNABLE_TO_DELETE_UPLOAD_DIR))}t(new r.RespOk)}}},function(e,t,s){"use strict";Object.defineProperty(t,"__esModule",{value:!0});const i=s(9),r=s(0);t.JsonCodec=class{fromJson(e){try{let t=JSON.parse(e);return"error"===t.action&&(t=i.createReqError(r.Message.createMessage(r.Message.ACTION_NOT_FOUND))),t}catch(e){return i.createReqError(r.Message.createMessage(r.Message.MALFORMED_REQUEST))}}toJson(e){return JSON.stringify(e)}}},function(e,t,s){"use strict";Object.defineProperty(t,"__esModule",{value:!0});const i=s(1),r=s(9),n=s(0),o=s(4);t.Uploader=class{constructor(e,t){this.m_config=e,this.m_actions=t}run(e,t){try{let s=this.m_actions.getAction(e.action);null==s&&(s=this.m_actions.getActionError(),e=r.createReqError(n.Message.createMessage(n.Message.ACTION_NOT_FOUND))),s.setConfig(this.m_config);let a=null;s.runWithCallback(e,e=>{let s=null;s=e instanceof i.MessageException?new o.RespFail(e.getFailMessage()):e instanceof Error?new o.RespFail(n.Message.createMessage(n.Message.INTERNAL_ERROR)):e,t(s)})}catch(e){console.log(e),a=new o.RespFail(n.Message.createMessage(n.Message.INTERNAL_ERROR)),t(a)}}}},function(e,t,s){"use strict";(function(e){Object.defineProperty(t,"__esModule",{value:!0});const i=s(2);t.ServletConfig=class{constructor(e){this.m_testConf={},this.m_conf=e}setTestConfig(e){this.m_testConf=e}getParameter(e,t,s){if(e in this.m_testConf)return this.addTrailingSlash(this.m_testConf[e],s);{let i=this.m_conf[e];return null!=i?this.addTrailingSlash(i,s):t}}addTrailingSlash(e,t){return null==e||!t||0!==e.length&&"/"===e.substring(e.length-1)||(e+="/"),e}getParameterStr(e,t){return this.getParameter(e,t,!1)}getParameterInt(e,t){return this.getParameter(e,t,!1)}getParameterBool(e,t){return this.getParameter(e,t,!1)}getBaseDir(){let t=e;1===t.length&&(t=t.substr(1));let s=this.getParameter("dirFiles",t+"files/",!0);return i.existsSync(s)||i.mkdirsSync(s),s}getTmpDir(){let e=this.getParameter("dirTmp",this.getBaseDir()+"tmp/",!0);return i.existsSync(e)||i.mkdirsSync(e),e}getMaxUploadFileSize(){return this.getParameterInt("maxUploadFileSize",0)}getAllowedExtensions(){let e=this.getParameterStr("allowedExtensions",null);if(null==e)return[];let t=e.split(",");for(let e=0;e<t.length;e++)t[e]=t[e].toLowerCase();return t}getJpegQuality(){return this.getParameterInt("jpegQuality",95)}getMaxImageResizeWidth(){return this.getParameterInt("maxImageResizeWidth",5e3)}getMaxImageResizeHeight(){return this.getParameterInt("maxImageResizeHeight",5e3)}getCrossDomainUrl(){return this.getParameterStr("crossDomainUrl",null)}doKeepUploads(){return this.getParameterBool("keepUploads",!1)}isTestAllowed(){return this.getParameterBool("isTestAllowed",!1)}getRelocateFromHosts(){let e=this.getParameterStr("relocateFromHosts","").split(","),t=[];for(let s=0;s<e.length;s++){let i=e[s].trim().toLowerCase();i.length>0&&t.push(i)}return t}}}).call(this,"/")}]))},function(e,t){e.exports=require("fs-extra")},function(e,t){e.exports=require("busboy")},function(e,t){e.exports=require("image-size")},function(e,t){e.exports=require("gm")},function(e,t){e.exports=require("fs")},function(e,t){e.exports=require("request")}])); |
{ | ||
"name": "@edsdk/file-uploader-microservice", | ||
"version": "1.0.4", | ||
"version": "1.0.5", | ||
"description": "Microservice which handles file uploads with using File uploader SDK and Express.", | ||
@@ -9,3 +9,3 @@ "main": "./dist/file-uploader-microservice.js", | ||
"build": "webpack", | ||
"prepublish": "ncu -a && npm run build" | ||
"prepublish": "npm run build" | ||
}, | ||
@@ -12,0 +12,0 @@ "author": "https://imageeditorsdk.com/", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
62086