<commit_before>var Upload = {
    xhr : null,
    attached : [],
    failed : [],
    progressed : [],
    get : null,
    name : null,
    file : null,
    canvas : null,
    uploadButton : null,

    init : function() {
        if (Upload.file) {
            Upload_ajaxSend({
                name: Upload.name,
                size: Upload.file.size,
                type: Upload.file.type
            });
        }
    },

    attach : function(func) {
        if (typeof(func) === "function") {
            this.attached.push(func);
        }
    },

    fail : function(func) {
        if (typeof(func) === "function") {
            this.failed.push(func);
        }
    },

    progress : function(func) {
        if (typeof(func) === "function") {
            this.progressed.push(func);
        }
    },

    launchAttached : function() {
        for(var i = 0; i < Upload.attached.length; i++) {
            Upload.attached[i]({
                name: Upload.name,
                size: Upload.file.size,
                type: Upload.file.type,
                uri:  Upload.get
            });
        }
    },

    launchFailed : function() {
        for(var i = 0; i < Upload.failed.length; i++) {
            Upload.failed[i]();
        }
    },

    launchProgressed : function(percent) {
        for(var i = 0; i < Upload.progressed.length; i++) {
            Upload.progressed[i](percent);
        }
    },

    preview : function(file) {
        Upload.canvas = null;
        Upload.uploadButton = document.querySelector('#upload_button');

        var resolvedFile = file ? file : document.getElementById('file').files[0];
        Upload.name = resolvedFile.name;
        Upload.check(resolvedFile);
    },

    check : function(file) {
        if (!file.type.match(/image.*/)) {
            console.log("Not a picture !");
            Upload.prepare(file);
        } else {
            var reader = new FileReader();
            reader.readAsDataURL(file);

            reader.onload = function (ev) {
                MovimUtils.getOrientation(file, function(orientation) {
                    Upload.compress(ev.target.result, file, orientation);
                });
            };
        };
    },

    compress : function(src, file, orientation) {
        var image = new Image();
        image.onload = function()
        {
            var limit = 1920;

            var width = image.naturalWidth;
            var height = image.naturalHeight;

            Upload.canvas = document.createElement('canvas');

            if ([5,6,7,8].indexOf(orientation) > -1) {
                Upload.canvas.width = height;
                Upload.canvas.height = width;
            } else {
                Upload.canvas.width = width;
                Upload.canvas.height = height;
            }

            ctx = Upload.canvas.getContext("2d");

            switch (orientation) {
                case 2: ctx.transform(-1, 0, 0, 1, width, 0); break;
                case 3: ctx.transform(-1, 0, 0, -1, width, height ); break;
                case 4: ctx.transform(1, 0, 0, -1, 0, height ); break;
                case 5: ctx.transform(0, 1, 1, 0, 0, 0); break;
                case 6: ctx.transform(0, 1, -1, 0, height , 0); break;
                case 7: ctx.transform(0, -1, -1, 0, height , width); break;
                case 8: ctx.transform(0, -1, 1, 0, 0, width); break;
                default: ctx.transform(1, 0, 0, 1, 0, 0);
            }

            ctx.drawImage(image, 0, 0, width, height);

            if (file.size > SMALL_PICTURE_LIMIT) {
                var ratio = Math.min(limit / width, limit / height);

                if (ratio < 1) {
                    width = Math.round(width*ratio);
                    height = Math.round(height*ratio);
                }

                if (typeof Upload.canvas.toBlob == 'function') {<commit_msg>Fix picture resize during upload<commit_after>var Upload = {
    xhr : null,
    attached : [],
    failed : [],
    progressed : [],
    get : null,
    name : null,
    file : null,
    canvas : null,
    uploadButton : null,

    init : function() {
        if (Upload.file) {
            Upload_ajaxSend({
                name: Upload.name,
                size: Upload.file.size,
                type: Upload.file.type
            });
        }
    },

    attach : function(func) {
        if (typeof(func) === "function") {
            this.attached.push(func);
        }
    },

    fail : function(func) {
        if (typeof(func) === "function") {
            this.failed.push(func);
        }
    },

    progress : function(func) {
        if (typeof(func) === "function") {
            this.progressed.push(func);
        }
    },

    launchAttached : function() {
        for(var i = 0; i < Upload.attached.length; i++) {
            Upload.attached[i]({
                name: Upload.name,
                size: Upload.file.size,
                type: Upload.file.type,
                uri:  Upload.get
            });
        }
    },

    launchFailed : function() {
        for(var i = 0; i < Upload.failed.length; i++) {
            Upload.failed[i]();
        }
    },

    launchProgressed : function(percent) {
        for(var i = 0; i < Upload.progressed.length; i++) {
            Upload.progressed[i](percent);
        }
    },

    preview : function(file) {
        Upload.canvas = null;
        Upload.uploadButton = document.querySelector('#upload_button');

        var resolvedFile = file ? file : document.getElementById('file').files[0];
        Upload.name = resolvedFile.name;
        Upload.check(resolvedFile);
    },

    check : function(file) {
        if (!file.type.match(/image.*/)) {
            console.log("Not a picture !");
            Upload.prepare(file);
        } else {
            var reader = new FileReader();
            reader.readAsDataURL(file);

            reader.onload = function (ev) {
                MovimUtils.getOrientation(file, function(orientation) {
                    Upload.compress(ev.target.result, file, orientation);
                });
            };
        };
    },

    compress : function(src, file, orientation) {
        var image = new Image();
        image.onload = function()
        {
            if (file.size > SMALL_PICTURE_LIMIT) {
                var limit = 1920;
                var width = image.naturalWidth;
                var height = image.naturalHeight;

                var ratio = Math.min(limit / width, limit / height);

                if (ratio < 1) {
                    width = Math.round(width*ratio);
                    height = Math.round(height*ratio);
                }

                Upload.canvas = document.createElement('canvas');

                if ([5,6,7,8].indexOf(orientation) > -1) {
                    Upload.canvas.width = height;
                    Upload.canvas.height = width;
                } else {
                    Upload.canvas.width = width;
                    Upload.canvas.height = height;
                }

                ctx = Upload.canvas.getContext("2d");

                switch (orientation) {
                    case 2: ctx.transform(-1, 0, 0, 1, width, 0); break;
                    case 3: ctx.transform(-1, 0, 0, -1, width, height ); break;
                    case 4: ctx.transform(1, 0, 0, -1, 0, height ); break;
                    case 5: ctx.transform(0, 1, 1, 0, 0, 0); break;
                    case 6: ctx.transform(0, 1, -1, 0, height , 0); break;
                    case 7: ctx.transform(0, -1, -1, 0, height , width); break;
                    case 8: ctx.transform(0, -1, 1, 0, 0, width); break;
                    default: ctx.transform(1, 0, 0, 1, 0, 0);
                }

                ctx.drawImage(image, 0, 0, width, height);

                if (typeof Upload.canvas.toBlob == 'function') {
{'fraction_non_alphanumeric': 0.13435114503816795, 'fraction_numerical': 0.01628498727735369, 'mean_word_length': 1.4202586206896552, 'pattern_counts': {'":': 0, '<': 11, '<?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': '3801215', 'n_tokens_mistral': 2410, 'n_tokens_neox': 2180, 'n_words': 502}