@ckeditor/ckeditor5-adapter-ckfinder 39.0.1 → 40.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -113,7 +113,7 @@ Internal changes only (updated dependencies, documentation, etc.).
113
113
 
114
114
  ### BREAKING CHANGES
115
115
 
116
- * The license under which CKEditor 5 is released has been changed from a triple GPL, LGPL and MPL license to a GPL2+ only. See [ckeditor/ckeditor5#991](https://github.com/ckeditor/ckeditor5/issues/991) for more information.
116
+ * The license under which CKEditor 5 is released has been changed from a triple GPL, LGPL and MPL license to a GPL2+ only. See [ckeditor/ckeditor5#991](https://github.com/ckeditor/ckeditor5/issues/991) for more information.
117
117
 
118
118
 
119
119
  ## [1.0.0-beta.4](https://github.com/ckeditor/ckeditor5-adapter-ckfinder/compare/v1.0.0-beta.2...v1.0.0-beta.4) (2018-04-19)
package/LICENSE.md CHANGED
@@ -1,7 +1,7 @@
1
1
  Software License Agreement
2
2
  ==========================
3
3
 
4
- **CKEditor 5 CKFinder adapter** – https://github.com/ckeditor/ckeditor5-adapter-ckfinder <br>
4
+ **CKEditor&nbsp;5 CKFinder adapter** – https://github.com/ckeditor/ckeditor5-adapter-ckfinder <br>
5
5
  Copyright (c) 2003-2023, [CKSource Holding sp. z o.o.](https://cksource.com) All rights reserved.
6
6
 
7
7
  Licensed under the terms of [GNU General Public License Version 2 or later](http://www.gnu.org/licenses/gpl.html).
package/README.md CHANGED
@@ -1,17 +1,17 @@
1
- CKEditor 5 CKFinder adapter
1
+ CKEditor&nbsp;5 CKFinder adapter
2
2
  ========================================
3
3
 
4
4
  [![npm version](https://badge.fury.io/js/%40ckeditor%2Fckeditor5-adapter-ckfinder.svg)](https://www.npmjs.com/package/@ckeditor/ckeditor5-adapter-ckfinder)
5
5
  [![Coverage Status](https://coveralls.io/repos/github/ckeditor/ckeditor5/badge.svg?branch=master)](https://coveralls.io/github/ckeditor/ckeditor5?branch=master)
6
6
  [![Build Status](https://travis-ci.com/ckeditor/ckeditor5.svg?branch=master)](https://app.travis-ci.com/github/ckeditor/ckeditor5)
7
7
 
8
- This package implements a CKEditor 5 upload adapter compatible with the [CKFinder file manager and uploader](https://ckeditor.com/ckfinder/)'s server–side connector.
8
+ This package implements a CKEditor&nbsp;5 upload adapter compatible with the [CKFinder file manager and uploader](https://ckeditor.com/ckfinder/)'s server–side connector.
9
9
 
10
10
  ## Documentation
11
11
 
12
12
  See the ["CKFinder integration" guide](https://ckeditor.com/docs/ckeditor5/latest/features/ckfinder.html) and the [plugin documentation](https://ckeditor.com/docs/ckeditor5/latest/api/adapter-ckfinder.html) to learn how to configure the adapter.
13
13
 
14
- Check out the {@link features/image-upload/image-upload comprehensive "Image upload overview"} to learn about other ways to upload images into CKEditor 5.
14
+ Check out the {@link features/image-upload/image-upload comprehensive "Image upload overview"} to learn about other ways to upload images into CKEditor&nbsp;5.
15
15
 
16
16
  ## License
17
17
 
@@ -0,0 +1 @@
1
+ {"version":3,"file":"adapter-ckfinder.js","mappings":";;;;;;;;;;;;;;;;;;;;;AAAA;AACA;AACA;AACA;;AAEA;;AAEA;AACA;AACA;;AAE4C;AACU;;AAEf;;AAEvC;AACA;AACA;AACA,YAAY,wFAAwF;AACpG;AACA,oBAAoB,yCAAyC;AAC7D;AACA,kBAAkB,wFAAwF;AAC1G;AACA;AACA;AACA;AACe,oCAAoC,sDAAM;AACzD;AACA;AACA;AACA;AACA,WAAW,gEAAc;AACzB;;AAEA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;;AAEA;AACA,2BAA2B,gEAAc;AACzC;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,YAAY,yCAAyC;AACrD,YAAY,QAAQ;AACpB,YAAY,8BAA8B;AAC1C;AACA;AACA;AACA;AACA;AACA,cAAc,yCAAyC;AACvD;AACA;;AAEA;AACA;AACA;AACA,cAAc,QAAQ;AACtB;AACA;;AAEA;AACA;AACA;AACA,cAAc,8BAA8B;AAC5C;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA,cAAc;AACd;AACA;AACA;AACA;AACA;AACA;AACA;AACA,KAAK;AACL,IAAI;AACJ;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA,YAAY,UAAU;AACtB,YAAY,UAAU;AACtB,YAAY,MAAM;AAClB;AACA;AACA;AACA;AACA;AACA,yDAAyD,WAAW;;AAEpE;AACA;AACA;AACA;;AAEA;AACA;AACA;;AAEA;AACA;AACA,KAAK;AACL,IAAI;;AAEJ;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,KAAK;AACL;AACA;;AAEA;AACA;AACA;AACA;AACA,YAAY,MAAM;AAClB;AACA;AACA;AACA;AACA;AACA,8BAA8B,oDAAY;;AAE1C;AACA;AACA;AACA;;;;;;;;;;;;;;;;;;AC7LA;AACA;AACA;AACA;;AAEA;;AAEA;AACA;AACA;;AAEA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA,aAAa;AACb;AACO;AACP;;AAEA;AACA;AACA;AACA;;AAEA;AACA;;AAEA;AACA;AACA;AACA,WAAW,QAAQ;AACnB,aAAa;AACb;AACO;AACP;AACA,wCAAwC;;AAExC;AACA;AACA;;AAEA;AACA;AACA;AACA;;AAEA;AACA;;AAEA;AACA;AACA;AACA,WAAW,QAAQ;AACnB,WAAW,QAAQ;AACnB;AACO;AACP,sFAAsF;AACtF;;AAEA;AACA;AACA;AACA,WAAW,QAAQ;AACnB,aAAa;AACb;AACA;AACA;;AAEA;;AAEA,kBAAkB,uBAAuB;AACzC;AACA;AACA;;AAEA;AACA;;;;;;;;;;;AClFA;;;;;;;;;;ACAA;;;;;;;;;;;ACAA;;;;;;UCAA;UACA;;UAEA;UACA;UACA;UACA;UACA;UACA;UACA;UACA;UACA;UACA;UACA;UACA;UACA;;UAEA;UACA;;UAEA;UACA;UACA;;;;;WCtBA;WACA;WACA;WACA;WACA,yCAAyC,wCAAwC;WACjF;WACA;WACA;;;;;WCPA;;;;;WCAA;WACA;WACA;WACA,uDAAuD,iBAAiB;WACxE;WACA,gDAAgD,aAAa;WAC7D;;;;;;;;;;;;;;;;ACNA;AACA;AACA;AACA;;AAEA;AACA;AACA;;AAE2D","sources":["webpack://CKEditor5.adapterCkfinder/./src/uploadadapter.js","webpack://CKEditor5.adapterCkfinder/./src/utils.js","webpack://CKEditor5.adapterCkfinder/delegated \"./src/core.js\" from dll-reference CKEditor5.dll","webpack://CKEditor5.adapterCkfinder/delegated \"./src/upload.js\" from dll-reference CKEditor5.dll","webpack://CKEditor5.adapterCkfinder/external var \"CKEditor5.dll\"","webpack://CKEditor5.adapterCkfinder/webpack/bootstrap","webpack://CKEditor5.adapterCkfinder/webpack/runtime/define property getters","webpack://CKEditor5.adapterCkfinder/webpack/runtime/hasOwnProperty shorthand","webpack://CKEditor5.adapterCkfinder/webpack/runtime/make namespace object","webpack://CKEditor5.adapterCkfinder/./src/index.js"],"sourcesContent":["/**\n * @license Copyright (c) 2003-2022, CKSource Holding sp. z o.o. All rights reserved.\n * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license\n */\n\n/* globals XMLHttpRequest, FormData */\n\n/**\n * @module adapter-ckfinder/uploadadapter\n */\n\nimport { Plugin } from 'ckeditor5/src/core';\nimport { FileRepository } from 'ckeditor5/src/upload';\n\nimport { getCsrfToken } from './utils';\n\n/**\n * A plugin that enables file uploads in CKEditor 5 using the CKFinder server–side connector.\n *\n * See the {@glink features/images/image-upload/ckfinder \"CKFinder file manager integration\" guide} to learn how to configure\n * and use this feature as well as find out more about the full integration with the file manager\n * provided by the {@link module:ckfinder/ckfinder~CKFinder} plugin.\n *\n * Check out the {@glink features/images/image-upload/image-upload comprehensive \"Image upload overview\"} to learn about\n * other ways to upload images into CKEditor 5.\n *\n * @extends module:core/plugin~Plugin\n */\nexport default class CKFinderUploadAdapter extends Plugin {\n\t/**\n\t * @inheritDoc\n\t */\n\tstatic get requires() {\n\t\treturn [ FileRepository ];\n\t}\n\n\t/**\n\t * @inheritDoc\n\t */\n\tstatic get pluginName() {\n\t\treturn 'CKFinderUploadAdapter';\n\t}\n\n\t/**\n\t * @inheritDoc\n\t */\n\tinit() {\n\t\tconst url = this.editor.config.get( 'ckfinder.uploadUrl' );\n\n\t\tif ( !url ) {\n\t\t\treturn;\n\t\t}\n\n\t\t// Register CKFinderAdapter\n\t\tthis.editor.plugins.get( FileRepository ).createUploadAdapter = loader => new UploadAdapter( loader, url, this.editor.t );\n\t}\n}\n\n/**\n * Upload adapter for CKFinder.\n *\n * @private\n * @implements module:upload/filerepository~UploadAdapter\n */\nclass UploadAdapter {\n\t/**\n\t * Creates a new adapter instance.\n\t *\n\t * @param {module:upload/filerepository~FileLoader} loader\n\t * @param {String} url\n\t * @param {module:utils/locale~Locale#t} t\n\t */\n\tconstructor( loader, url, t ) {\n\t\t/**\n\t\t * FileLoader instance to use during the upload.\n\t\t *\n\t\t * @member {module:upload/filerepository~FileLoader} #loader\n\t\t */\n\t\tthis.loader = loader;\n\n\t\t/**\n\t\t * Upload URL.\n\t\t *\n\t\t * @member {String} #url\n\t\t */\n\t\tthis.url = url;\n\n\t\t/**\n\t\t * Locale translation method.\n\t\t *\n\t\t * @member {module:utils/locale~Locale#t} #t\n\t\t */\n\t\tthis.t = t;\n\t}\n\n\t/**\n\t * Starts the upload process.\n\t *\n\t * @see module:upload/filerepository~UploadAdapter#upload\n\t * @returns {Promise.<Object>}\n\t */\n\tupload() {\n\t\treturn this.loader.file.then( file => {\n\t\t\treturn new Promise( ( resolve, reject ) => {\n\t\t\t\tthis._initRequest();\n\t\t\t\tthis._initListeners( resolve, reject, file );\n\t\t\t\tthis._sendRequest( file );\n\t\t\t} );\n\t\t} );\n\t}\n\n\t/**\n\t * Aborts the upload process.\n\t *\n\t * @see module:upload/filerepository~UploadAdapter#abort\n\t */\n\tabort() {\n\t\tif ( this.xhr ) {\n\t\t\tthis.xhr.abort();\n\t\t}\n\t}\n\n\t/**\n\t * Initializes the XMLHttpRequest object.\n\t *\n\t * @private\n\t */\n\t_initRequest() {\n\t\tconst xhr = this.xhr = new XMLHttpRequest();\n\n\t\txhr.open( 'POST', this.url, true );\n\t\txhr.responseType = 'json';\n\t}\n\n\t/**\n\t * Initializes XMLHttpRequest listeners.\n\t *\n\t * @private\n\t * @param {Function} resolve Callback function to be called when the request is successful.\n\t * @param {Function} reject Callback function to be called when the request cannot be completed.\n\t * @param {File} file File instance to be uploaded.\n\t */\n\t_initListeners( resolve, reject, file ) {\n\t\tconst xhr = this.xhr;\n\t\tconst loader = this.loader;\n\t\tconst t = this.t;\n\t\tconst genericError = t( 'Cannot upload file:' ) + ` ${ file.name }.`;\n\n\t\txhr.addEventListener( 'error', () => reject( genericError ) );\n\t\txhr.addEventListener( 'abort', () => reject() );\n\t\txhr.addEventListener( 'load', () => {\n\t\t\tconst response = xhr.response;\n\n\t\t\tif ( !response || !response.uploaded ) {\n\t\t\t\treturn reject( response && response.error && response.error.message ? response.error.message : genericError );\n\t\t\t}\n\n\t\t\tresolve( {\n\t\t\t\tdefault: response.url\n\t\t\t} );\n\t\t} );\n\n\t\t// Upload progress when it's supported.\n\t\t/* istanbul ignore else */\n\t\tif ( xhr.upload ) {\n\t\t\txhr.upload.addEventListener( 'progress', evt => {\n\t\t\t\tif ( evt.lengthComputable ) {\n\t\t\t\t\tloader.uploadTotal = evt.total;\n\t\t\t\t\tloader.uploaded = evt.loaded;\n\t\t\t\t}\n\t\t\t} );\n\t\t}\n\t}\n\n\t/**\n\t * Prepares the data and sends the request.\n\t *\n\t * @private\n\t * @param {File} file File instance to be uploaded.\n\t */\n\t_sendRequest( file ) {\n\t\t// Prepare form data.\n\t\tconst data = new FormData();\n\t\tdata.append( 'upload', file );\n\t\tdata.append( 'ckCsrfToken', getCsrfToken() );\n\n\t\t// Send request.\n\t\tthis.xhr.send( data );\n\t}\n}\n","/**\n * @license Copyright (c) 2003-2022, CKSource Holding sp. z o.o. All rights reserved.\n * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license\n */\n\n/* globals window, document */\n\n/**\n * @module adapter-ckfinder/utils\n */\n\nconst TOKEN_COOKIE_NAME = 'ckCsrfToken';\nconst TOKEN_LENGTH = 40;\nconst tokenCharset = 'abcdefghijklmnopqrstuvwxyz0123456789';\n\n/**\n * Returns the CSRF token value. The value is a hash stored in `document.cookie`\n * under the `ckCsrfToken` key. The CSRF token can be used to secure the communication\n * between the web browser and the CKFinder server.\n *\n * @returns {String}\n */\nexport function getCsrfToken() {\n\tlet token = getCookie( TOKEN_COOKIE_NAME );\n\n\tif ( !token || token.length != TOKEN_LENGTH ) {\n\t\ttoken = generateToken( TOKEN_LENGTH );\n\t\tsetCookie( TOKEN_COOKIE_NAME, token );\n\t}\n\n\treturn token;\n}\n\n/**\n * Returns the value of the cookie with a given name or `null` if the cookie is not found.\n *\n * @param {String} name\n * @returns {String|null}\n */\nexport function getCookie( name ) {\n\tname = name.toLowerCase();\n\tconst parts = document.cookie.split( ';' );\n\n\tfor ( const part of parts ) {\n\t\tconst pair = part.split( '=' );\n\t\tconst key = decodeURIComponent( pair[ 0 ].trim().toLowerCase() );\n\n\t\tif ( key === name ) {\n\t\t\treturn decodeURIComponent( pair[ 1 ] );\n\t\t}\n\t}\n\n\treturn null;\n}\n\n/**\n * Sets the value of the cookie with a given name.\n *\n * @param {String} name\n * @param {String} value\n */\nexport function setCookie( name, value ) {\n\tdocument.cookie = encodeURIComponent( name ) + '=' + encodeURIComponent( value ) + ';path=/';\n}\n\n// Generates the CSRF token with the given length.\n//\n// @private\n// @param {Number} length\n// @returns {string}\nfunction generateToken( length ) {\n\tlet result = '';\n\tconst randValues = new Uint8Array( length );\n\n\twindow.crypto.getRandomValues( randValues );\n\n\tfor ( let j = 0; j < randValues.length; j++ ) {\n\t\tconst character = tokenCharset.charAt( randValues[ j ] % tokenCharset.length );\n\t\tresult += Math.random() > 0.5 ? character.toUpperCase() : character;\n\t}\n\n\treturn result;\n}\n","module.exports = (__webpack_require__(/*! dll-reference CKEditor5.dll */ \"dll-reference CKEditor5.dll\"))(\"./src/core.js\");","module.exports = (__webpack_require__(/*! dll-reference CKEditor5.dll */ \"dll-reference CKEditor5.dll\"))(\"./src/upload.js\");","module.exports = CKEditor5.dll;","// The module cache\nvar __webpack_module_cache__ = {};\n\n// The require function\nfunction __webpack_require__(moduleId) {\n\t// Check if module is in cache\n\tvar cachedModule = __webpack_module_cache__[moduleId];\n\tif (cachedModule !== undefined) {\n\t\treturn cachedModule.exports;\n\t}\n\t// Create a new module (and put it into the cache)\n\tvar module = __webpack_module_cache__[moduleId] = {\n\t\t// no module.id needed\n\t\t// no module.loaded needed\n\t\texports: {}\n\t};\n\n\t// Execute the module function\n\t__webpack_modules__[moduleId](module, module.exports, __webpack_require__);\n\n\t// Return the exports of the module\n\treturn module.exports;\n}\n\n","// define getter functions for harmony exports\n__webpack_require__.d = (exports, definition) => {\n\tfor(var key in definition) {\n\t\tif(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {\n\t\t\tObject.defineProperty(exports, key, { enumerable: true, get: definition[key] });\n\t\t}\n\t}\n};","__webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))","// define __esModule on exports\n__webpack_require__.r = (exports) => {\n\tif(typeof Symbol !== 'undefined' && Symbol.toStringTag) {\n\t\tObject.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });\n\t}\n\tObject.defineProperty(exports, '__esModule', { value: true });\n};","/**\n * @license Copyright (c) 2003-2022, CKSource Holding sp. z o.o. All rights reserved.\n * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license\n */\n\n/**\n * @module adapter-ckfinder\n */\n\nexport { default as UploadAdapter } from './uploadadapter';\n"],"names":[],"sourceRoot":""}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ckeditor/ckeditor5-adapter-ckfinder",
3
- "version": "39.0.1",
3
+ "version": "40.0.0",
4
4
  "description": "CKFinder adapter for CKEditor 5.",
5
5
  "keywords": [
6
6
  "ckeditor",
@@ -12,11 +12,7 @@
12
12
  ],
13
13
  "main": "src/index.js",
14
14
  "dependencies": {
15
- "ckeditor5": "39.0.1"
16
- },
17
- "engines": {
18
- "node": ">=16.0.0",
19
- "npm": ">=5.7.1"
15
+ "ckeditor5": "40.0.0"
20
16
  },
21
17
  "author": "CKSource (http://cksource.com/)",
22
18
  "license": "GPL-2.0-or-later",
@@ -1,10 +1,10 @@
1
- /**
2
- * @license Copyright (c) 2003-2023, 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
- import type { UploadAdapter } from './index';
6
- declare module '@ckeditor/ckeditor5-core' {
7
- interface PluginsMap {
8
- [UploadAdapter.pluginName]: UploadAdapter;
9
- }
10
- }
1
+ /**
2
+ * @license Copyright (c) 2003-2023, 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
+ import type { UploadAdapter } from './index';
6
+ declare module '@ckeditor/ckeditor5-core' {
7
+ interface PluginsMap {
8
+ [UploadAdapter.pluginName]: UploadAdapter;
9
+ }
10
+ }
@@ -1,5 +1,5 @@
1
- /**
2
- * @license Copyright (c) 2003-2023, 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
- export {};
1
+ /**
2
+ * @license Copyright (c) 2003-2023, 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
+ export {};
package/src/index.d.ts CHANGED
@@ -1,9 +1,9 @@
1
- /**
2
- * @license Copyright (c) 2003-2023, 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
- /**
6
- * @module adapter-ckfinder
7
- */
8
- export { default as UploadAdapter } from './uploadadapter';
9
- import './augmentation';
1
+ /**
2
+ * @license Copyright (c) 2003-2023, 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
+ /**
6
+ * @module adapter-ckfinder
7
+ */
8
+ export { default as UploadAdapter } from './uploadadapter';
9
+ import './augmentation';
package/src/index.js CHANGED
@@ -1,9 +1,9 @@
1
- /**
2
- * @license Copyright (c) 2003-2023, 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
- /**
6
- * @module adapter-ckfinder
7
- */
8
- export { default as UploadAdapter } from './uploadadapter';
9
- import './augmentation';
1
+ /**
2
+ * @license Copyright (c) 2003-2023, 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
+ /**
6
+ * @module adapter-ckfinder
7
+ */
8
+ export { default as UploadAdapter } from './uploadadapter';
9
+ import './augmentation';
@@ -1,33 +1,33 @@
1
- /**
2
- * @license Copyright (c) 2003-2023, 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
- /**
6
- * @module adapter-ckfinder/uploadadapter
7
- */
8
- import { Plugin } from 'ckeditor5/src/core';
9
- import { FileRepository } from 'ckeditor5/src/upload';
10
- /**
11
- * A plugin that enables file uploads in CKEditor 5 using the CKFinder server–side connector.
12
- *
13
- * See the {@glink features/file-management/ckfinder "CKFinder file manager integration"} guide to learn how to configure
14
- * and use this feature as well as find out more about the full integration with the file manager
15
- * provided by the {@link module:ckfinder/ckfinder~CKFinder} plugin.
16
- *
17
- * Check out the {@glink features/images/image-upload/image-upload comprehensive "Image upload overview"} guide to learn
18
- * about other ways to upload images into CKEditor 5.
19
- */
20
- export default class CKFinderUploadAdapter extends Plugin {
21
- /**
22
- * @inheritDoc
23
- */
24
- static get requires(): readonly [typeof FileRepository];
25
- /**
26
- * @inheritDoc
27
- */
28
- static get pluginName(): "CKFinderUploadAdapter";
29
- /**
30
- * @inheritDoc
31
- */
32
- init(): void;
33
- }
1
+ /**
2
+ * @license Copyright (c) 2003-2023, 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
+ /**
6
+ * @module adapter-ckfinder/uploadadapter
7
+ */
8
+ import { Plugin } from 'ckeditor5/src/core';
9
+ import { FileRepository } from 'ckeditor5/src/upload';
10
+ /**
11
+ * A plugin that enables file uploads in CKEditor 5 using the CKFinder server–side connector.
12
+ *
13
+ * See the {@glink features/file-management/ckfinder "CKFinder file manager integration"} guide to learn how to configure
14
+ * and use this feature as well as find out more about the full integration with the file manager
15
+ * provided by the {@link module:ckfinder/ckfinder~CKFinder} plugin.
16
+ *
17
+ * Check out the {@glink features/images/image-upload/image-upload comprehensive "Image upload overview"} guide to learn
18
+ * about other ways to upload images into CKEditor 5.
19
+ */
20
+ export default class CKFinderUploadAdapter extends Plugin {
21
+ /**
22
+ * @inheritDoc
23
+ */
24
+ static get requires(): readonly [typeof FileRepository];
25
+ /**
26
+ * @inheritDoc
27
+ */
28
+ static get pluginName(): "CKFinderUploadAdapter";
29
+ /**
30
+ * @inheritDoc
31
+ */
32
+ init(): void;
33
+ }
@@ -1,138 +1,138 @@
1
- /**
2
- * @license Copyright (c) 2003-2023, 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
- /* globals XMLHttpRequest, FormData */
6
- /**
7
- * @module adapter-ckfinder/uploadadapter
8
- */
9
- import { Plugin } from 'ckeditor5/src/core';
10
- import { FileRepository } from 'ckeditor5/src/upload';
11
- import { getCsrfToken } from './utils';
12
- /**
13
- * A plugin that enables file uploads in CKEditor 5 using the CKFinder server–side connector.
14
- *
15
- * See the {@glink features/file-management/ckfinder "CKFinder file manager integration"} guide to learn how to configure
16
- * and use this feature as well as find out more about the full integration with the file manager
17
- * provided by the {@link module:ckfinder/ckfinder~CKFinder} plugin.
18
- *
19
- * Check out the {@glink features/images/image-upload/image-upload comprehensive "Image upload overview"} guide to learn
20
- * about other ways to upload images into CKEditor 5.
21
- */
22
- export default class CKFinderUploadAdapter extends Plugin {
23
- /**
24
- * @inheritDoc
25
- */
26
- static get requires() {
27
- return [FileRepository];
28
- }
29
- /**
30
- * @inheritDoc
31
- */
32
- static get pluginName() {
33
- return 'CKFinderUploadAdapter';
34
- }
35
- /**
36
- * @inheritDoc
37
- */
38
- init() {
39
- const url = this.editor.config.get('ckfinder.uploadUrl');
40
- if (!url) {
41
- return;
42
- }
43
- // Register CKFinderAdapter
44
- this.editor.plugins.get(FileRepository).createUploadAdapter = loader => new UploadAdapter(loader, url, this.editor.t);
45
- }
46
- }
47
- /**
48
- * Upload adapter for CKFinder.
49
- */
50
- class UploadAdapter {
51
- /**
52
- * Creates a new adapter instance.
53
- */
54
- constructor(loader, url, t) {
55
- this.loader = loader;
56
- this.url = url;
57
- this.t = t;
58
- }
59
- /**
60
- * Starts the upload process.
61
- *
62
- * @see module:upload/filerepository~UploadAdapter#upload
63
- */
64
- upload() {
65
- return this.loader.file.then(file => {
66
- return new Promise((resolve, reject) => {
67
- this._initRequest();
68
- this._initListeners(resolve, reject, file);
69
- this._sendRequest(file);
70
- });
71
- });
72
- }
73
- /**
74
- * Aborts the upload process.
75
- *
76
- * @see module:upload/filerepository~UploadAdapter#abort
77
- */
78
- abort() {
79
- if (this.xhr) {
80
- this.xhr.abort();
81
- }
82
- }
83
- /**
84
- * Initializes the XMLHttpRequest object.
85
- */
86
- _initRequest() {
87
- const xhr = this.xhr = new XMLHttpRequest();
88
- xhr.open('POST', this.url, true);
89
- xhr.responseType = 'json';
90
- }
91
- /**
92
- * Initializes XMLHttpRequest listeners.
93
- *
94
- * @param resolve Callback function to be called when the request is successful.
95
- * @param reject Callback function to be called when the request cannot be completed.
96
- * @param file File instance to be uploaded.
97
- */
98
- _initListeners(resolve, reject, file) {
99
- const xhr = this.xhr;
100
- const loader = this.loader;
101
- const t = this.t;
102
- const genericError = t('Cannot upload file:') + ` ${file.name}.`;
103
- xhr.addEventListener('error', () => reject(genericError));
104
- xhr.addEventListener('abort', () => reject());
105
- xhr.addEventListener('load', () => {
106
- const response = xhr.response;
107
- if (!response || !response.uploaded) {
108
- return reject(response && response.error && response.error.message ? response.error.message : genericError);
109
- }
110
- resolve({
111
- default: response.url
112
- });
113
- });
114
- // Upload progress when it's supported.
115
- /* istanbul ignore else -- @preserve */
116
- if (xhr.upload) {
117
- xhr.upload.addEventListener('progress', evt => {
118
- if (evt.lengthComputable) {
119
- loader.uploadTotal = evt.total;
120
- loader.uploaded = evt.loaded;
121
- }
122
- });
123
- }
124
- }
125
- /**
126
- * Prepares the data and sends the request.
127
- *
128
- * @param file File instance to be uploaded.
129
- */
130
- _sendRequest(file) {
131
- // Prepare form data.
132
- const data = new FormData();
133
- data.append('upload', file);
134
- data.append('ckCsrfToken', getCsrfToken());
135
- // Send request.
136
- this.xhr.send(data);
137
- }
138
- }
1
+ /**
2
+ * @license Copyright (c) 2003-2023, 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
+ /* globals XMLHttpRequest, FormData */
6
+ /**
7
+ * @module adapter-ckfinder/uploadadapter
8
+ */
9
+ import { Plugin } from 'ckeditor5/src/core';
10
+ import { FileRepository } from 'ckeditor5/src/upload';
11
+ import { getCsrfToken } from './utils';
12
+ /**
13
+ * A plugin that enables file uploads in CKEditor 5 using the CKFinder server–side connector.
14
+ *
15
+ * See the {@glink features/file-management/ckfinder "CKFinder file manager integration"} guide to learn how to configure
16
+ * and use this feature as well as find out more about the full integration with the file manager
17
+ * provided by the {@link module:ckfinder/ckfinder~CKFinder} plugin.
18
+ *
19
+ * Check out the {@glink features/images/image-upload/image-upload comprehensive "Image upload overview"} guide to learn
20
+ * about other ways to upload images into CKEditor 5.
21
+ */
22
+ export default class CKFinderUploadAdapter extends Plugin {
23
+ /**
24
+ * @inheritDoc
25
+ */
26
+ static get requires() {
27
+ return [FileRepository];
28
+ }
29
+ /**
30
+ * @inheritDoc
31
+ */
32
+ static get pluginName() {
33
+ return 'CKFinderUploadAdapter';
34
+ }
35
+ /**
36
+ * @inheritDoc
37
+ */
38
+ init() {
39
+ const url = this.editor.config.get('ckfinder.uploadUrl');
40
+ if (!url) {
41
+ return;
42
+ }
43
+ // Register CKFinderAdapter
44
+ this.editor.plugins.get(FileRepository).createUploadAdapter = loader => new UploadAdapter(loader, url, this.editor.t);
45
+ }
46
+ }
47
+ /**
48
+ * Upload adapter for CKFinder.
49
+ */
50
+ class UploadAdapter {
51
+ /**
52
+ * Creates a new adapter instance.
53
+ */
54
+ constructor(loader, url, t) {
55
+ this.loader = loader;
56
+ this.url = url;
57
+ this.t = t;
58
+ }
59
+ /**
60
+ * Starts the upload process.
61
+ *
62
+ * @see module:upload/filerepository~UploadAdapter#upload
63
+ */
64
+ upload() {
65
+ return this.loader.file.then(file => {
66
+ return new Promise((resolve, reject) => {
67
+ this._initRequest();
68
+ this._initListeners(resolve, reject, file);
69
+ this._sendRequest(file);
70
+ });
71
+ });
72
+ }
73
+ /**
74
+ * Aborts the upload process.
75
+ *
76
+ * @see module:upload/filerepository~UploadAdapter#abort
77
+ */
78
+ abort() {
79
+ if (this.xhr) {
80
+ this.xhr.abort();
81
+ }
82
+ }
83
+ /**
84
+ * Initializes the XMLHttpRequest object.
85
+ */
86
+ _initRequest() {
87
+ const xhr = this.xhr = new XMLHttpRequest();
88
+ xhr.open('POST', this.url, true);
89
+ xhr.responseType = 'json';
90
+ }
91
+ /**
92
+ * Initializes XMLHttpRequest listeners.
93
+ *
94
+ * @param resolve Callback function to be called when the request is successful.
95
+ * @param reject Callback function to be called when the request cannot be completed.
96
+ * @param file File instance to be uploaded.
97
+ */
98
+ _initListeners(resolve, reject, file) {
99
+ const xhr = this.xhr;
100
+ const loader = this.loader;
101
+ const t = this.t;
102
+ const genericError = t('Cannot upload file:') + ` ${file.name}.`;
103
+ xhr.addEventListener('error', () => reject(genericError));
104
+ xhr.addEventListener('abort', () => reject());
105
+ xhr.addEventListener('load', () => {
106
+ const response = xhr.response;
107
+ if (!response || !response.uploaded) {
108
+ return reject(response && response.error && response.error.message ? response.error.message : genericError);
109
+ }
110
+ resolve({
111
+ default: response.url
112
+ });
113
+ });
114
+ // Upload progress when it's supported.
115
+ /* istanbul ignore else -- @preserve */
116
+ if (xhr.upload) {
117
+ xhr.upload.addEventListener('progress', evt => {
118
+ if (evt.lengthComputable) {
119
+ loader.uploadTotal = evt.total;
120
+ loader.uploaded = evt.loaded;
121
+ }
122
+ });
123
+ }
124
+ }
125
+ /**
126
+ * Prepares the data and sends the request.
127
+ *
128
+ * @param file File instance to be uploaded.
129
+ */
130
+ _sendRequest(file) {
131
+ // Prepare form data.
132
+ const data = new FormData();
133
+ data.append('upload', file);
134
+ data.append('ckCsrfToken', getCsrfToken());
135
+ // Send request.
136
+ this.xhr.send(data);
137
+ }
138
+ }
package/src/utils.d.ts CHANGED
@@ -1,18 +1,18 @@
1
- /**
2
- * @license Copyright (c) 2003-2023, 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
- /**
6
- * Returns the CSRF token value. The value is a hash stored in `document.cookie`
7
- * under the `ckCsrfToken` key. The CSRF token can be used to secure the communication
8
- * between the web browser and the CKFinder server.
9
- */
10
- export declare function getCsrfToken(): string;
11
- /**
12
- * Returns the value of the cookie with a given name or `null` if the cookie is not found.
13
- */
14
- export declare function getCookie(name: string): string | null;
15
- /**
16
- * Sets the value of the cookie with a given name.
17
- */
18
- export declare function setCookie(name: string, value: string): void;
1
+ /**
2
+ * @license Copyright (c) 2003-2023, 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
+ /**
6
+ * Returns the CSRF token value. The value is a hash stored in `document.cookie`
7
+ * under the `ckCsrfToken` key. The CSRF token can be used to secure the communication
8
+ * between the web browser and the CKFinder server.
9
+ */
10
+ export declare function getCsrfToken(): string;
11
+ /**
12
+ * Returns the value of the cookie with a given name or `null` if the cookie is not found.
13
+ */
14
+ export declare function getCookie(name: string): string | null;
15
+ /**
16
+ * Sets the value of the cookie with a given name.
17
+ */
18
+ export declare function setCookie(name: string, value: string): void;
package/src/utils.js CHANGED
@@ -1,58 +1,58 @@
1
- /**
2
- * @license Copyright (c) 2003-2023, 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
- /* globals window, document */
6
- /**
7
- * @module adapter-ckfinder/utils
8
- */
9
- const TOKEN_COOKIE_NAME = 'ckCsrfToken';
10
- const TOKEN_LENGTH = 40;
11
- const tokenCharset = 'abcdefghijklmnopqrstuvwxyz0123456789';
12
- /**
13
- * Returns the CSRF token value. The value is a hash stored in `document.cookie`
14
- * under the `ckCsrfToken` key. The CSRF token can be used to secure the communication
15
- * between the web browser and the CKFinder server.
16
- */
17
- export function getCsrfToken() {
18
- let token = getCookie(TOKEN_COOKIE_NAME);
19
- if (!token || token.length != TOKEN_LENGTH) {
20
- token = generateToken(TOKEN_LENGTH);
21
- setCookie(TOKEN_COOKIE_NAME, token);
22
- }
23
- return token;
24
- }
25
- /**
26
- * Returns the value of the cookie with a given name or `null` if the cookie is not found.
27
- */
28
- export function getCookie(name) {
29
- name = name.toLowerCase();
30
- const parts = document.cookie.split(';');
31
- for (const part of parts) {
32
- const pair = part.split('=');
33
- const key = decodeURIComponent(pair[0].trim().toLowerCase());
34
- if (key === name) {
35
- return decodeURIComponent(pair[1]);
36
- }
37
- }
38
- return null;
39
- }
40
- /**
41
- * Sets the value of the cookie with a given name.
42
- */
43
- export function setCookie(name, value) {
44
- document.cookie = encodeURIComponent(name) + '=' + encodeURIComponent(value) + ';path=/';
45
- }
46
- /**
47
- * Generates the CSRF token with the given length.
48
- */
49
- function generateToken(length) {
50
- let result = '';
51
- const randValues = new Uint8Array(length);
52
- window.crypto.getRandomValues(randValues);
53
- for (let j = 0; j < randValues.length; j++) {
54
- const character = tokenCharset.charAt(randValues[j] % tokenCharset.length);
55
- result += Math.random() > 0.5 ? character.toUpperCase() : character;
56
- }
57
- return result;
58
- }
1
+ /**
2
+ * @license Copyright (c) 2003-2023, 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
+ /* globals window, document */
6
+ /**
7
+ * @module adapter-ckfinder/utils
8
+ */
9
+ const TOKEN_COOKIE_NAME = 'ckCsrfToken';
10
+ const TOKEN_LENGTH = 40;
11
+ const tokenCharset = 'abcdefghijklmnopqrstuvwxyz0123456789';
12
+ /**
13
+ * Returns the CSRF token value. The value is a hash stored in `document.cookie`
14
+ * under the `ckCsrfToken` key. The CSRF token can be used to secure the communication
15
+ * between the web browser and the CKFinder server.
16
+ */
17
+ export function getCsrfToken() {
18
+ let token = getCookie(TOKEN_COOKIE_NAME);
19
+ if (!token || token.length != TOKEN_LENGTH) {
20
+ token = generateToken(TOKEN_LENGTH);
21
+ setCookie(TOKEN_COOKIE_NAME, token);
22
+ }
23
+ return token;
24
+ }
25
+ /**
26
+ * Returns the value of the cookie with a given name or `null` if the cookie is not found.
27
+ */
28
+ export function getCookie(name) {
29
+ name = name.toLowerCase();
30
+ const parts = document.cookie.split(';');
31
+ for (const part of parts) {
32
+ const pair = part.split('=');
33
+ const key = decodeURIComponent(pair[0].trim().toLowerCase());
34
+ if (key === name) {
35
+ return decodeURIComponent(pair[1]);
36
+ }
37
+ }
38
+ return null;
39
+ }
40
+ /**
41
+ * Sets the value of the cookie with a given name.
42
+ */
43
+ export function setCookie(name, value) {
44
+ document.cookie = encodeURIComponent(name) + '=' + encodeURIComponent(value) + ';path=/';
45
+ }
46
+ /**
47
+ * Generates the CSRF token with the given length.
48
+ */
49
+ function generateToken(length) {
50
+ let result = '';
51
+ const randValues = new Uint8Array(length);
52
+ window.crypto.getRandomValues(randValues);
53
+ for (let j = 0; j < randValues.length; j++) {
54
+ const character = tokenCharset.charAt(randValues[j] % tokenCharset.length);
55
+ result += Math.random() > 0.5 ? character.toUpperCase() : character;
56
+ }
57
+ return result;
58
+ }