CKEDITOR.plugins.add("cloudservices",{requires:"filetools,ajax",onLoad:function(){function e(e,r,n,s){o.call(this,e,r,n),this.customToken=s}var o=CKEDITOR.fileTools.fileLoader;e.prototype=CKEDITOR.tools.extend({},o.prototype),e.prototype.upload=function(e,r){(e=e||this.editor.config.cloudServices_uploadUrl)?o.prototype.upload.call(this,e,r):CKEDITOR.error("cloudservices-no-upload-url")},CKEDITOR.plugins.cloudservices.cloudServicesLoader=e},beforeInit:function(e){var o=e.config.cloudServices_tokenUrl,r={token:null,REFRESH_INTERVAL:e.CLOUD_SERVICES_TOKEN_INTERVAL||36e5,refreshToken:function(){CKEDITOR.ajax.load(o,(function(e){e&&(r.token=e)}))},init:function(){this.refreshToken();var o=window.setInterval(this.refreshToken,this.REFRESH_INTERVAL);e.once("destroy",(function(){window.clearInterval(o)}))}};o?r.init():CKEDITOR.error("cloudservices-no-token-url"),e.on("fileUploadRequest",(function(e){var o=e.data.fileLoader,n=e.data.requestData,s=o.customToken||r.token;o instanceof CKEDITOR.plugins.cloudservices.cloudServicesLoader&&(n.file=n.upload,delete n.upload,s?e.data.fileLoader.xhr.setRequestHeader("Authorization",s):(CKEDITOR.error("cloudservices-no-token"),e.cancel()))}),null,null,6),e.on("fileUploadResponse",(function(e){var o,r=e.data.fileLoader,n=r.xhr;if(r instanceof CKEDITOR.plugins.cloudservices.cloudServicesLoader){e.stop();try{o=JSON.parse(n.responseText),e.data.response=o}catch(e){CKEDITOR.warn("filetools-response-error",{responseText:n.responseText})}}}))}}),CKEDITOR.plugins.cloudservices={cloudServicesLoader:null};