<commit_before>(function(global){

    class StatusItem extends Observable{
        constructor(type){
            super();
            this._status = 'new';
            this._type = type;
            this._id = Math.random();
        }
        getId(){
            return this._id;
        }
        getLabel(){

        }
        getType(){
            return this._type;
        }
        getStatus(){
            return this._status;
        }
        setStatus(status){
            this._status = status;
            this.notify('status');
        }
        process(completeCallback){
            this._doProcess(completeCallback);
        }
        abort(completeCallback){
            if(this._status !== 'loading') return;
            console.log('Should Stop XHR');
            this._doAbort(completeCallback);
        }
    }

    class UploadItem extends StatusItem{

        constructor(file, targetNode, relativePath = null){
            super('file');
            this._file = file;
            this._status = 'new';
            this._progress = 0;
            this._targetNode = targetNode;
            this._repositoryId = global.pydio.user.activeRepository;
            this._relativePath = relativePath;
        }
        getMqConfigs(){
            return global.pydio.getPluginConfigs('mq');
        }
        getFile(){
            return this._file;
        }
        getSize(){
            return this._file.size;
        }
        getLabel(){
            return this._relativePath ? this._relativePath : this._file.name;
        }
        getProgress(){
            return this._progress;
        }
        setProgress(newValue, bytes = null){
            this._progress = newValue;
            this.notify('progress', newValue);
            if(bytes !== null) {
                this.notify('bytes', bytes);
            }
        }
        getRelativePath(){
            return this._relativePath;
        }
        buildQueryString(){

            let fullPath = this._targetNode.getPath();
            if(this._relativePath) {
                fullPath += PathUtils.getDirname(this._relativePath);
            }
            let currentRepo = global.pydio.user.activeRepository;

            let queryString = '&get_action=upload&xhr_uploader=true&dir=' + encodeURIComponent(fullPath);

            let dataModel = global.pydio.getContextHolder();
            let nodeName = PathUtils.getBasename(this._file.name);
            var newNode = new AjxpNode(fullPath+"/"+nodeName);
            if(this._file.size){
                newNode.getMetadata().set("filesize", this._file.size);
            }
            try{
                let params = null;
                if(currentRepo !== this._repositoryId) {
                    params = {tmp_repository_id:this._repositoryId};
                }
                dataModel.applyCheckHook(newNode, params);
            }catch(e){
                throw new Error('Error while checking before uploads');
            }
            let overwriteStatus = UploaderConfigs.getInstance().getOption("DEFAULT_EXISTING", "upload_existing");
            if(overwriteStatus === 'rename'){
                queryString += '&auto_rename=true';
            }else if(overwriteStatus === 'alert' && !this._relativePath && currentRepo === this._repositoryId){
                if(dataModel.fileNameExists(nodeName, false, this._targetNode)){
                    if(!global.confirm(MessageHash[124])){
                        throw new Error('File already exists');
                    }
                }
            }
            if(currentRepo !== this._repositoryId){
                queryString += '&tmp_repository_id=' + this._repositoryId;
            }
            return queryString;
        }
        _doProcess(completeCallback){
            let complete = function(){
                this.setStatus('loaded');
                completeCallback();
            }.bind(this);
            let error = function(){
                this.setStatus('error');
                completeCallback();
            }.bind(this);
            let progress = function(computableEvent){
                let percentage = Math.round((computableEvent.loaded * 100) / computableEvent.total);
                let bytesLoaded = computableEvent.loaded;
                this.setProgress(percentage, bytesLoaded);
            }.bind(this);
            this.setStatus('loading');

            let queryString;
            try{
                queryString = this.buildQueryString();
            }catch(e){
                this.setStatus('error');
                completeCallback();
                return;
            }

            // Checks applied.
            if(this.getMqConfigs().get('UPLOAD_ACTIVE')){

                this.tryAlternativeUpload(complete, progress, function(){
                    // Failed, switch back to normal upload.
                    this.xhr = PydioApi.getClient().uploadFile(this._file,'userfile_0',queryString,complete,error,progress);
                });

            }else{

                this.xhr = PydioApi.getClient().uploadFile(this._file,'userfile_0',queryString,complete,error,progress);

            }

        }
        _doAbort(completeCallback){
            if(this.xhr){
                try{
                    this.xhr.abort();
                }catch(e){}
            }
        }

        tryAlternativeUpload(completeCallback, progressCallback, errorCallback){
            let configs = this.getMqConfigs();
            var host = configs.get("BOOSTER_MAIN_HOST");
            if(configs.get("BOOSTER_UPLOAD_ADVANCED") && configs.get("BOOSTER_UPLOAD_ADVANCED")['booster_ws_advanced'] === 'custom' && configs.get("BOOSTER_UPLOAD_ADVANCED")['WS_HOST']){
                host = configs.get("BOOSTER_UPLOAD_ADVANCED")['WS_HOST'];
            }
            var port = configs.get("BOOSTER_MAIN_PORT");
            if(configs.get("BOOSTER_UPLOAD_ADVANCED") && configs.get("BOOSTER_UPLOAD_ADVANCED")['booster_upload_advanced'] === 'custom' && configs.get("BOOSTER_UPLOAD_ADVANCED")['WS_PORT']){
                port = configs.get("BOOSTER_UPLOAD_ADVANCED")['WS_PORT'];
            }
            let fullPath = this._targetNode.getPath();
            if(this._relativePath) {
                fullPath += PathUtils.getDirname(this._relativePath);
            }
            fullPath += '/' + PathUtils.getBasename(this._file.name);

            let url = "http"+(configs.get("UPLOAD_SECURE")?"s":"")+"://"+host+":"+port+"/"+configs.get("UPLOAD_PATH")+"/"+this._repositoryId + fullPath;
            let queryString = '';
            let overwriteStatus = UploaderConfigs.getInstance().getOption("DEFAULT_EXISTING", "upload_existing");
            if(overwriteStatus === 'rename') {
                queryString += 'auto_rename=true';
            }
            try{
                console.log(url);<commit_msg>Remove log<commit_after>(function(global){

    class StatusItem extends Observable{
        constructor(type){
            super();
            this._status = 'new';
            this._type = type;
            this._id = Math.random();
        }
        getId(){
            return this._id;
        }
        getLabel(){

        }
        getType(){
            return this._type;
        }
        getStatus(){
            return this._status;
        }
        setStatus(status){
            this._status = status;
            this.notify('status');
        }
        process(completeCallback){
            this._doProcess(completeCallback);
        }
        abort(completeCallback){
            if(this._status !== 'loading') return;
            console.log('Should Stop XHR');
            this._doAbort(completeCallback);
        }
    }

    class UploadItem extends StatusItem{

        constructor(file, targetNode, relativePath = null){
            super('file');
            this._file = file;
            this._status = 'new';
            this._progress = 0;
            this._targetNode = targetNode;
            this._repositoryId = global.pydio.user.activeRepository;
            this._relativePath = relativePath;
        }
        getMqConfigs(){
            return global.pydio.getPluginConfigs('mq');
        }
        getFile(){
            return this._file;
        }
        getSize(){
            return this._file.size;
        }
        getLabel(){
            return this._relativePath ? this._relativePath : this._file.name;
        }
        getProgress(){
            return this._progress;
        }
        setProgress(newValue, bytes = null){
            this._progress = newValue;
            this.notify('progress', newValue);
            if(bytes !== null) {
                this.notify('bytes', bytes);
            }
        }
        getRelativePath(){
            return this._relativePath;
        }
        buildQueryString(){

            let fullPath = this._targetNode.getPath();
            if(this._relativePath) {
                fullPath += PathUtils.getDirname(this._relativePath);
            }
            let currentRepo = global.pydio.user.activeRepository;

            let queryString = '&get_action=upload&xhr_uploader=true&dir=' + encodeURIComponent(fullPath);

            let dataModel = global.pydio.getContextHolder();
            let nodeName = PathUtils.getBasename(this._file.name);
            var newNode = new AjxpNode(fullPath+"/"+nodeName);
            if(this._file.size){
                newNode.getMetadata().set("filesize", this._file.size);
            }
            try{
                let params = null;
                if(currentRepo !== this._repositoryId) {
                    params = {tmp_repository_id:this._repositoryId};
                }
                dataModel.applyCheckHook(newNode, params);
            }catch(e){
                throw new Error('Error while checking before uploads');
            }
            let overwriteStatus = UploaderConfigs.getInstance().getOption("DEFAULT_EXISTING", "upload_existing");
            if(overwriteStatus === 'rename'){
                queryString += '&auto_rename=true';
            }else if(overwriteStatus === 'alert' && !this._relativePath && currentRepo === this._repositoryId){
                if(dataModel.fileNameExists(nodeName, false, this._targetNode)){
                    if(!global.confirm(MessageHash[124])){
                        throw new Error('File already exists');
                    }
                }
            }
            if(currentRepo !== this._repositoryId){
                queryString += '&tmp_repository_id=' + this._repositoryId;
            }
            return queryString;
        }
        _doProcess(completeCallback){
            let complete = function(){
                this.setStatus('loaded');
                completeCallback();
            }.bind(this);
            let error = function(){
                this.setStatus('error');
                completeCallback();
            }.bind(this);
            let progress = function(computableEvent){
                let percentage = Math.round((computableEvent.loaded * 100) / computableEvent.total);
                let bytesLoaded = computableEvent.loaded;
                this.setProgress(percentage, bytesLoaded);
            }.bind(this);
            this.setStatus('loading');

            let queryString;
            try{
                queryString = this.buildQueryString();
            }catch(e){
                this.setStatus('error');
                completeCallback();
                return;
            }

            // Checks applied.
            if(this.getMqConfigs().get('UPLOAD_ACTIVE')){

                this.tryAlternativeUpload(complete, progress, function(){
                    // Failed, switch back to normal upload.
                    this.xhr = PydioApi.getClient().uploadFile(this._file,'userfile_0',queryString,complete,error,progress);
                });

            }else{

                this.xhr = PydioApi.getClient().uploadFile(this._file,'userfile_0',queryString,complete,error,progress);

            }

        }
        _doAbort(completeCallback){
            if(this.xhr){
                try{
                    this.xhr.abort();
                }catch(e){}
            }
        }

        tryAlternativeUpload(completeCallback, progressCallback, errorCallback){
            let configs = this.getMqConfigs();
            var host = configs.get("BOOSTER_MAIN_HOST");
            if(configs.get("BOOSTER_UPLOAD_ADVANCED") && configs.get("BOOSTER_UPLOAD_ADVANCED")['booster_ws_advanced'] === 'custom' && configs.get("BOOSTER_UPLOAD_ADVANCED")['WS_HOST']){
                host = configs.get("BOOSTER_UPLOAD_ADVANCED")['WS_HOST'];
            }
            var port = configs.get("BOOSTER_MAIN_PORT");
            if(configs.get("BOOSTER_UPLOAD_ADVANCED") && configs.get("BOOSTER_UPLOAD_ADVANCED")['booster_upload_advanced'] === 'custom' && configs.get("BOOSTER_UPLOAD_ADVANCED")['WS_PORT']){
                port = configs.get("BOOSTER_UPLOAD_ADVANCED")['WS_PORT'];
            }
            let fullPath = this._targetNode.getPath();
            if(this._relativePath) {
                fullPath += PathUtils.getDirname(this._relativePath);
            }
            fullPath += '/' + PathUtils.getBasename(this._file.name);

            let url = "http"+(configs.get("UPLOAD_SECURE")?"s":"")+"://"+host+":"+port+"/"+configs.get("UPLOAD_PATH")+"/"+this._repositoryId + fullPath;
            let queryString = '';
            let overwriteStatus = UploaderConfigs.getInstance().getOption("DEFAULT_EXISTING", "upload_existing");
            if(overwriteStatus === 'rename') {
                queryString += 'auto_rename=true';
            }
            try{
{'fraction_non_alphanumeric': 0.11997959034915082, 'fraction_numerical': 0.001312048983162038, 'mean_word_length': 1.712534598655595, 'pattern_counts': {'":': 6, '<': 3, '<?xml version=': 0, '>': 3, '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': '4226581', 'n_tokens_mistral': 3683, 'n_tokens_neox': 3573, 'n_words': 541}