<commit_before>/**
 * Uploader.js
 *
 * Copyright, Moxiecode Systems AB
 * Released under LGPL License.
 *
 * License: http://www.tinymce.com/license
 * Contributing: http://www.tinymce.com/contributing
 */

/**
 * Upload blobs or blob infos to the specified URL or handler.
 *
 * @private
 * @class tinymce.file.Uploader
 * @example
 * var uploader = new Uploader({
 *     url: '/upload.php',
 *     basePath: '/base/path',
 *     credentials: true,
 *     handler: function(data, success, failure) {
 *         ...
 *     }
 * });
 *
 * uploader.upload(blobInfos).then(function(result) {
 *     ...
 * });
 */
define("tinymce/file/Uploader", [
	"tinymce/util/Promise",
	"tinymce/util/Tools"
], function(Promise, Tools) {
	return function(settings) {
		function defaultHandler(blobInfo, success, failure) {
			var xhr, formData;

			xhr = new XMLHttpRequest();
			xhr.withCredentials = settings.credentials;
			xhr.open('POST', settings.url);

			xhr.onload = function() {
				var json;

				if (xhr.status != 200) {
					failure("HTTP Error: " + xhr.status);
					return;
				}

				json = JSON.parse(xhr.responseText);

				if (!json || typeof json.location != "string") {
					failure("Invalid JSON: " + xhr.responseText);
					return;
				}

				success(json.location);
			};

			formData = new FormData();
			formData.append('file', blobInfo.blob());

			xhr.send(formData);
		}

		function upload(blobInfos) {
			return new Promise(function(resolve) {
				var handler = settings.handler, queue, index = 0;

				queue = Tools.map(blobInfos, function(blobInfo) {
					return {
						status: false,
						blobInfo: blobInfo,
						url: ''
					};
				});

				function uploadNext() {
					var queueItem = queue[index++];

					if (!queueItem) {
						resolve(queue);
						return;
					}

					handler(queueItem.blobInfo, function(url) {
						queueItem.url = url;
						queueItem.status = true;
					}, function() {
						queueItem.status = false;
					});
				}<commit_msg>Fixed so the upload handler gets proper data and so that next gets executed.<commit_after>/**
 * Uploader.js
 *
 * Copyright, Moxiecode Systems AB
 * Released under LGPL License.
 *
 * License: http://www.tinymce.com/license
 * Contributing: http://www.tinymce.com/contributing
 */

/**
 * Upload blobs or blob infos to the specified URL or handler.
 *
 * @private
 * @class tinymce.file.Uploader
 * @example
 * var uploader = new Uploader({
 *     url: '/upload.php',
 *     basePath: '/base/path',
 *     credentials: true,
 *     handler: function(data, success, failure) {
 *         ...
 *     }
 * });
 *
 * uploader.upload(blobInfos).then(function(result) {
 *     ...
 * });
 */
define("tinymce/file/Uploader", [
	"tinymce/util/Promise",
	"tinymce/util/Tools"
], function(Promise, Tools) {
	return function(settings) {
		function blobInfoToData(blobInfo) {
			var fileName = "x";

			return {
				id: blobInfo.id,
				blob: blobInfo.blob,
				base64: blobInfo.base64,
				filename: Tools.constant(fileName)
			};
		}

		function defaultHandler(blobInfo, success, failure) {
			var xhr, formData;

			xhr = new XMLHttpRequest();
			xhr.withCredentials = settings.credentials;
			xhr.open('POST', settings.url);

			xhr.onload = function() {
				var json;

				if (xhr.status != 200) {
					failure("HTTP Error: " + xhr.status);
					return;
				}

				json = JSON.parse(xhr.responseText);

				if (!json || typeof json.location != "string") {
					failure("Invalid JSON: " + xhr.responseText);
					return;
				}

				success(json.location);
			};

			formData = new FormData();
			formData.append('file', blobInfo.blob());

			xhr.send(formData);
		}

		function upload(blobInfos) {
			return new Promise(function(resolve) {
				var handler = settings.handler, queue, index = 0;

				queue = Tools.map(blobInfos, function(blobInfo) {
					return {
						status: false,
						blobInfo: blobInfo,
						url: ''
					};
				});

				function uploadNext() {
					var queueItem = queue[index++];

					if (!queueItem) {
						resolve(queue);
						return;
					}

					handler(blobInfoToData(queueItem.blobInfo), function(url) {
						queueItem.url = url;
						queueItem.status = true;
						uploadNext();
					}, function() {
						queueItem.status = false;
						uploadNext();
					});
				}
{'fraction_non_alphanumeric': 0.14850327408793265, 'fraction_numerical': 0.002806361085126286, 'mean_word_length': 2.696629213483146, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 4, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4210293', 'n_tokens_mistral': 1756, 'n_tokens_neox': 1390, 'n_words': 293}