<commit_before>/* global Dropzone */

import Ember from 'ember';
import config from 'ember-get-config';

import layout from './template';

/**
 * @module ember-osf
 * @submodule components
 */

/**
 * Support file uploads via dropzone.
 * Accepts dropzone event listeners as parameters (e.g. success, error, addedfile)
 *
 * Sample usage:
 * ```handlebars
 * {{dropzone-widget
 *   preUpload=attrs.preUpload
 *   buildUrl=buildUrl
 *   success=attrs.success
 *   defaultMessage=defaultMessage
 *   options=dropzoneOptions}}
 * ```
 *
 * @class dropzone-widget
 */
export default Ember.Component.extend({
    layout,
    session: Ember.inject.service(),
    classNameBindings: ['dropzone'],
    dropzone: true,
    enable: true,
    loadDropzone() {
        let preUpload = this.get('preUpload');
        let dropzoneOptions = this.get('options') || {};

        function CustomDropzone() {
            Dropzone.call(this, ...arguments);
        }
        CustomDropzone.prototype = Object.create(Dropzone.prototype);
        CustomDropzone.prototype.drop = function(e) {
            if (this.options.preventMultipleFiles && e.dataTransfer && e.dataTransfer.items.length > 1) {
                this.emit("drop", e);
                this.emit('error', 'None', 'Cannot upload multiple files');
                return;
            }
            return Dropzone.prototype.drop.call(this, e);
        }

        let drop = new CustomDropzone(`#${this.elementId}`, {
            url: file => typeof this.get('buildUrl') === 'function' ? this.get('buildUrl')(file) : this.get('buildUrl'),
            autoProcessQueue: false,
            dictDefaultMessage: this.get('defaultMessage') || 'Drop files here to upload',
            sending(file, xhr) {
                // Monkey patch to send the raw file instead of formData
                xhr.send = xhr.send.bind(xhr, file);
            }
        });

        // Set osf session header
        let headers = {};
<commit_msg>Also prevent uploading directories on any dropzone version<commit_after>/* global Dropzone */

import Ember from 'ember';
import config from 'ember-get-config';

import layout from './template';

/**
 * @module ember-osf
 * @submodule components
 */

/**
 * Support file uploads via dropzone.
 * Accepts dropzone event listeners as parameters (e.g. success, error, addedfile)
 *
 * Sample usage:
 * ```handlebars
 * {{dropzone-widget
 *   preUpload=attrs.preUpload
 *   buildUrl=buildUrl
 *   success=attrs.success
 *   defaultMessage=defaultMessage
 *   options=dropzoneOptions}}
 * ```
 *
 * @class dropzone-widget
 */
export default Ember.Component.extend({
    layout,
    session: Ember.inject.service(),
    classNameBindings: ['dropzone'],
    dropzone: true,
    enable: true,
    loadDropzone() {
        let preUpload = this.get('preUpload');
        let dropzoneOptions = this.get('options') || {};

        function CustomDropzone() {
            Dropzone.call(this, ...arguments);
        }
        CustomDropzone.prototype = Object.create(Dropzone.prototype);
        CustomDropzone.prototype.drop = function(e) {
            if (this.options.preventMultipleFiles && e.dataTransfer) {
                if (e.dataTransfer.items.length > 1) {
                    this.emit("drop", e);
                    this.emit('error', 'None', 'Cannot upload multiple files');
                    return;
                }
                if (e.dataTransfer.files.length === 0) {
                    this.emit("drop", e);
                    this.emit('error', 'None', 'Cannot upload directories, applications, or packages');
                    return;
                }
            }
            return Dropzone.prototype.drop.call(this, e);
        }

        let drop = new CustomDropzone(`#${this.elementId}`, {
            url: file => typeof this.get('buildUrl') === 'function' ? this.get('buildUrl')(file) : this.get('buildUrl'),
            autoProcessQueue: false,
            dictDefaultMessage: this.get('defaultMessage') || 'Drop files here to upload',
            sending(file, xhr) {
                // Monkey patch to send the raw file instead of formData
                xhr.send = xhr.send.bind(xhr, file);
            }
        });

        // Set osf session header
        let headers = {};

{'fraction_non_alphanumeric': 0.13090229079008883, 'fraction_numerical': 0.0007012622720897616, 'mean_word_length': 2.251519756838906, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '3861073', 'n_tokens_mistral': 1187, 'n_tokens_neox': 1162, 'n_words': 285}