cloudservices.js 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. /**
  2. * @license Copyright (c) 2003-2018, 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. /**
  41. * Other plugins use this token for the authorization process. It handles token requesting and refreshing.
  42. * Its value is `null` when {@link module:cloudservices/cloudservices~CloudServicesConfig#tokenUrl} is not provided.
  43. *
  44. * @readonly
  45. * @member {Object|null} #token
  46. */
  47. if ( !this.tokenUrl ) {
  48. this.token = null;
  49. return;
  50. }
  51. this.token = new CloudServices.Token( this.tokenUrl );
  52. return this.token.init();
  53. }
  54. }
  55. CloudServices.Token = Token;
  56. /**
  57. * The configuration of CKEditor Cloud Services. Introduced by the {@link module:cloudservices/cloudservices~CloudServices} plugin.
  58. *
  59. * Read more in {@link module:cloudservices/cloudservices~CloudServicesConfig}.
  60. *
  61. * @member {module:cloudservices/cloudservices~CloudServicesConfig} module:core/editor/editorconfig~EditorConfig#cloudServices
  62. */
  63. /**
  64. * The configuration for all plugins using CKEditor Cloud Services.
  65. *
  66. * ClassicEditor
  67. * .create( document.querySelector( '#editor' ), {
  68. * cloudServices: {
  69. * tokenUrl: 'https://example.com/cs-token-endpoint',
  70. * uploadUrl: 'https://your-organization-id.cke-cs.com/easyimage/upload/'
  71. * }
  72. * } )
  73. * .then( ... )
  74. * .catch( ... );
  75. *
  76. * See {@link module:core/editor/editorconfig~EditorConfig all editor options}.
  77. *
  78. * @interface CloudServicesConfig
  79. */
  80. /**
  81. * The authentication token endpoint URL for CKEditor Cloud Services.
  82. * The token endpoint is used to authenticate all plugins using Cloud Services (for instance – Easy Image).
  83. * The token URL has to point to the service where the token is generated.
  84. *
  85. * You can read about creating token endpoints in the
  86. * {@glink @cs guides/token-endpoints/tokenendpoint Creating token endpoint} guide
  87. * in {@glink @cs index Cloud Services documentation}.
  88. *
  89. * See also [Cloud Services Quick start](https://docs.ckeditor.com/cs/latest/guides/quick-start.html).
  90. *
  91. * @member {String} module:cloudservices/cloudservices~CloudServicesConfig#tokenUrl
  92. */
  93. /**
  94. * The URL to which the files should be uploaded.
  95. *
  96. * Read more in [Cloud Services Quick start](https://docs.ckeditor.com/cs/latest/guides/quick-start.html).
  97. *
  98. * @member {String} module:cloudservices/cloudservices~CloudServicesConfig#uploadUrl
  99. */