cloudservices.js 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. /**
  2. * @license Copyright (c) 2003-2017, CKSource - Frederico Knabben. All rights reserved.
  3. * For licensing, see LICENSE.md.
  4. */
  5. /**
  6. * @module cloudservices/cloudservices
  7. */
  8. import Plugin from '@ckeditor/ckeditor5-core/src/plugin';
  9. import Token from '@ckeditor/ckeditor-cloudservices-core/src/token/token';
  10. /**
  11. * Plugin introducing CKEditor 5's Cloud Services integration.
  12. * It takes care of the {@link module:cloudservices/cloudservices~CloudServicesConfig `config.cloudService`}
  13. * configuration options and initializes the token provider.
  14. *
  15. * @extends module:core/plugin~Plugin
  16. */
  17. export default class CloudServices extends Plugin {
  18. /**
  19. * @inheritDoc
  20. */
  21. init() {
  22. const editor = this.editor;
  23. const config = editor.config;
  24. const options = config.get( 'cloudServices' ) || {};
  25. for ( const optionName in options ) {
  26. this[ optionName ] = options[ optionName ];
  27. }
  28. /**
  29. * The authentication token URL for CKEditor Cloud Services.
  30. *
  31. * @readonly
  32. * @member {String|undefined} #tokenUrl
  33. */
  34. /**
  35. * The URL to which the files should be uploaded.
  36. *
  37. * @readonly
  38. * @member {String} #uploadUrl
  39. */
  40. if ( !this.uploadUrl ) {
  41. this.uploadUrl = 'https://files.cke-cs.com/upload/';
  42. }
  43. /**
  44. * Other plugins use this token for the authorization process. It handles token requesting and refreshing.
  45. * Its value is `null` when {@link module:cloudservices/cloudservices~CloudServicesConfig#tokenUrl} is not provided.
  46. *
  47. * @readonly
  48. * @member {Object|null} #token
  49. */
  50. if ( !this.tokenUrl ) {
  51. this.token = null;
  52. return;
  53. }
  54. this.token = new CloudServices.Token( this.tokenUrl );
  55. return this.token.init();
  56. }
  57. }
  58. CloudServices.Token = Token;
  59. /**
  60. * The configuration of CKEditor Cloud Services. Introduced by the {@link module:cloudservices/cloudservices~CloudServices} plugin.
  61. *
  62. * Read more in {@link module:cloudservices/cloudservices~CloudServicesConfig}.
  63. *
  64. * @member {module:cloudservices/cloudservices~CloudServicesConfig} module:core/editor/editorconfig~EditorConfig#cloudServices
  65. */
  66. /**
  67. * The configuration for all plugins using CKEditor Cloud Services.
  68. *
  69. * ClassicEditor
  70. * .create( document.querySelector( '#editor' ), {
  71. * cloudServices: {
  72. * uploadUrl: 'https://your-organisation-id.cke-cs.com/easyimage/upload/',
  73. * tokenUrl: 'https://example.com/cs-token-endpoint'
  74. * }
  75. * } )
  76. * .then( ... )
  77. * .catch( ... );
  78. *
  79. * See {@link module:core/editor/editorconfig~EditorConfig all editor options}.
  80. *
  81. * @interface CloudServicesConfig
  82. */
  83. /**
  84. * The authentication token URL for CKEditor Cloud Services. The token is used to authenticate all plugins using Cloud Services,
  85. * for instance Easy Image. The token URL has to point to the service where the token is generated.
  86. *
  87. * See [Cloud Services Quick Start](https://docs.ckeditor.com/cs/latest/guides/quick-start.html).
  88. *
  89. * @member {String} module:cloudservices/cloudservices~CloudServicesConfig#tokenUrl
  90. */
  91. /**
  92. * The URL to which the files should be uploaded.
  93. *
  94. * @member {String} [module:cloudservices/cloudservices~CloudServicesConfig#uploadUrl]
  95. */