Răsfoiți Sursa

Docs: Added the config.simpleUpload.withCredentials API docs entry. Code refactoring.

Aleksander Nowodzinski 5 ani în urmă
părinte
comite
d1f95242ad

+ 26 - 5
packages/ckeditor5-upload/src/adapters/simpleuploadadapter.js

@@ -201,15 +201,14 @@ class Adapter {
 		// Set headers if specified.
 		const headers = this.options.headers || {};
 
+		// Use the withCredentials flag if specified.
+		const withCredentials = this.options.withCredentials || false;
+
 		for ( const headerName of Object.keys( headers ) ) {
 			this.xhr.setRequestHeader( headerName, headers[ headerName ] );
 		}
 
-		// Set withCredentials if specified
-		const withCredentials = this.options.withCredentials || false;
-		if ( withCredentials ) {
-			this.xhr.withCredentials = true;
-		}
+		this.xhr.withCredentials = withCredentials;
 
 		// Prepare the form data.
 		const data = new FormData();
@@ -288,3 +287,25 @@ class Adapter {
  *
  * @member {Object.<String, String>} module:upload/adapters/simpleuploadadapter~SimpleUploadConfig#headers
  */
+
+/**
+ * This flag enables the
+ * [`withCredentials`](https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest/withCredentials)
+ * property of the request sent to the server during the upload. It affects cross-site requests only and, for instance,
+ * allows credentials such as cookies to be sent along with the request.
+ *
+ *		ClassicEditor
+ *			.create( editorElement, {
+ *				simpleUpload: {
+ *					withCredentials: true
+ *				}
+ *			} );
+ *			.then( ... )
+ *			.catch( ... );
+ *
+ * Learn more about the server application requirements in the
+ * {@glink features/image-upload/simple-upload-adapter#server-side-configuration "Server-side configuration"} section
+ * of the feature guide.
+ *
+ * @member {Boolean} [module:upload/adapters/simpleuploadadapter~SimpleUploadConfig#withCredentials=false]
+ */