plugin.js 1.7 KB

12345
  1. /*
  2. Copyright (c) 2003-2022, CKSource Holding sp. z o.o. All rights reserved.
  3. For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
  4. */
  5. !function(){CKEDITOR.plugins.add("cloudservices",{requires:"filetools,ajax",onLoad:function(){function e(e,r,n,t){o.call(this,e,r,n),this.customToken=t}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,t=o.customToken||r.token;o instanceof CKEDITOR.plugins.cloudservices.cloudServicesLoader&&(n.file=n.upload,delete n.upload,t?e.data.fileLoader.xhr.setRequestHeader("Authorization",t):(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(t){CKEDITOR.warn("filetools-response-error",{responseText:n.responseText})}}})}}),CKEDITOR.plugins.cloudservices={cloudServicesLoader:null}}();