| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122 |
- /**
- * @license Copyright (c) 2003-2017, CKSource - Frederico Knabben. All rights reserved.
- * For licensing, see LICENSE.md.
- */
- /**
- * @module easy-image/cloudservicesuploadadapter
- */
- import Plugin from '@ckeditor/ckeditor5-core/src/plugin';
- import FileRepository from '@ckeditor/ckeditor5-upload/src/filerepository';
- import UploadGateway from '@ckeditor/ckeditor-cloudservices-core/src/uploadgateway/uploadgateway';
- import CloudServices from '@ckeditor/ckeditor5-cloudservices/src/cloudservices';
- /**
- * A plugin which enables upload to Cloud Services.
- *
- * It is mainly used by the {@link module:easy-image/easyimage~EasyImage} feature.
- *
- * After enabling this adapter you need to configure the Cloud Services integration through
- * {@link module:easy-image/cloudservicesuploadadapter~CloudServicesAdapterConfig `config.cloudServices`}.
- *
- * @extends module:core/plugin~Plugin
- */
- export default class CloudServicesUploadAdapter extends Plugin {
- /**
- * @inheritDoc
- */
- static get requires() {
- return [ FileRepository, CloudServices ];
- }
- /**
- * @inheritDoc
- */
- init() {
- const editor = this.editor;
- const cloudServices = editor.plugins.get( CloudServices );
- const token = cloudServices.token;
- const uploadUrl = cloudServices.uploadUrl || 'https://files.cke-cs.com/upload/';
- this._uploadGateway = new CloudServicesUploadAdapter._UploadGateway( token, uploadUrl );
- editor.plugins.get( FileRepository ).createAdapter = loader => {
- return new Adapter( this._uploadGateway, loader );
- };
- }
- }
- /**
- * @private
- */
- class Adapter {
- constructor( uploadGateway, loader ) {
- this.uploadGateway = uploadGateway;
- this.loader = loader;
- }
- upload() {
- this.fileUploader = this.uploadGateway.upload( this.loader.file );
- this.fileUploader.on( 'progress', ( evt, data ) => {
- this.loader.uploadTotal = data.total;
- this.loader.uploaded = data.uploaded;
- } );
- return this.fileUploader.send();
- }
- abort() {
- this.fileUploader.abort();
- }
- }
- // Store the API in static property to easily overwrite it in tests.
- // Too bad dependency injection does not work in Webpack + ES 6 (const) + Babel.
- CloudServicesUploadAdapter._UploadGateway = UploadGateway;
- /**
- * The configuration of the {@link module:easy-image/cloudservicesuploadadapter~CloudServicesUploadAdapter Cloud Services upload adapter}.
- *
- * It is used mainly by the {@link module:easy-image/easyimage~EasyImage} feature.
- *
- * Read more in {@link module:easy-image/cloudservicesuploadadapter~CloudServicesAdapterConfig}.
- *
- * @member {module:easy-image/cloudservicesuploadadapter~CloudServicesAdapterConfig}
- * module:core/editor/editorconfig~EditorConfig#cloudServices
- */
- /**
- * The configuration of the {@link module:easy-image/cloudservicesuploadadapter~CloudServicesUploadAdapter Cloud Services upload adapter}.
- *
- * It is used mainly by the {@link module:easy-image/easyimage~EasyImage} feature.
- *
- * ClassicEditor
- * .create( editorElement, {
- * cloudServices: {
- * tokenUrl: '...'
- * }
- * } )
- * .then( ... )
- * .catch( ... );
- *
- * See {@link module:core/editor/editorconfig~EditorConfig all editor options}.
- *
- * @interface CloudServicesAdapterConfig
- */
- /**
- * The URL to which the files should be uploaded.
- *
- * @member {String} [module:easy-image/cloudservicesuploadadapter~CloudServicesAdapterConfig#uploadUrl='https://files.cke-cs.com/upload/']
- */
- /**
- * The token to the Cloud Services application. You can obtain it from the token service.
- *
- * @member {String} module:easy-image/cloudservicesuploadadapter~CloudServicesAdapterConfig#token
- */
|