<commit_before>$(document).ready(function () {
    var proxy_endpoint = "proxy.php";
    var params = {
        proxy_to: "http://192.168.3.11/fts/index.php",
        proxy_consumer_key: "demo",
        proxy_consumer_secret: "<KEY>",
        relativePath: "/",
    };

    function getDirList() {
        params.action = 'getDirList';
        $.get(proxy_endpoint, params, function (response) {
            $("#filelist").html($("#directoryList").tmpl(response, {
                fDate: function (timestamp) {
                    return fancyDateTime(timestamp);
                },
                fSize: function (bytes) {
                    return fancyBytes(bytes);
                }
            }));
        }, 'json');
        // FIXME: optimize this
        $("#breadcrumb").html($("#directoryPathViewer").tmpl(splitPath(params.relativePath)));
        $("#breadcrumb li").click(function (event) {
            var relPath;
            if ($(this).hasClass("root")) {
                relPath = "/";
            } else {
                relPath = $(this).text();
                $.each($(this).prevUntil("li.root"), function (i, val) {
                    relPath = $(this).text() + "/" + relPath;
                });
            }
            params.relativePath = relPath;
            getDirList();
        });
    }
    $('a#ftc_add').click(function (event) {
        $('#dropbox').show();
    });
    $('a#ftc_cancel_upload').click(function (event) {
        $('#dropbox').hide();
    });
    $('a.download').live('click', function (event) {
        var tmp_rp = params.relativePath;
        params.action = 'getDownloadToken';
        params.relativePath += "/" + $(this).parent().next().text();
        $.post(proxy_endpoint, params, function (response) {
            window.location.href = response.data.downloadLocation;
        }, 'json');
        params.relativePath = tmp_rp;
    });
    $('a.open').live('click', function (event) {
        params.relativePath += "/" + $(this).parent().next().text();
        getDirList();
    });
    $('a.delete').live('click', function (event) {
        var fileName = $(this).parent().prev().prev().prev().text();
        if (confirm("Are you sure you want to delete '" + fileName + "'?")) {
            var tmp_rp = params.relativePath;
            params.action = 'deleteFile';
            params.relativePath += "/" + fileName;
            $.post(proxy_endpoint, params, function (response) {
                params.relativePath = tmp_rp;
                getDirList();
            }, 'json');
        }
    });
    $('#inputFiles').bind('change', function (e) {
        handleFiles(this.files);
        e.stopPropagation();
        e.preventDefault();
    });
    $('#dropzone').bind('dragenter dragover', function (e) {
        e.stopPropagation();
        e.preventDefault();
    });
    $('#dropzone').bind('drop', function (e) {
        e.stopPropagation();
        e.preventDefault();
        handleFiles(e.originalEvent.dataTransfer.files);
    });
    $('#startUpload').click(function (e) {
        startUpload();
        e.stopPropagation();
        e.preventDefault();
    });
    $('#cancelUpload').click(function (e) {
        cancelUpload();
        e.stopPropagation();
        e.preventDefault();
    });

    function fancyDateTime(ts) {
        var now = new Date();
        var dayStart = new Date(now.getFullYear(), now.getMonth(), now.getDate());
        var fileDateTime = new Date(ts * 1000);
        var now_ts = Math.round(now.getTime() / 1000);
        var dayStart_ts = Math.round(dayStart.getTime() / 1000);
        var hours = (fileDateTime.getHours() < 10) ? "0" + fileDateTime.getHours() : fileDateTime.getHours();
        var minutes = (fileDateTime.getMinutes() < 10) ? "0" + fileDateTime.getMinutes() : fileDateTime.getMinutes();
        var humanDate;
        if (ts > dayStart_ts) {
            // today, show just time
            humanDate = hours + ":" + minutes;
        } else if (ts > (now_ts - 60 * 60 * 24 * 7)) {
            // last week, show just day and time
            humanDate = dayToText(fileDateTime.getDay()) + " " + hours + ":" + minutes;
        } else if ((ts > now_ts - 60 * 60 * 24 * 365)) {
            // longer than a week ago, show just month+day
            humanDate = monthToText(fileDateTime.getMonth()) + " " + fileDateTime.getDate();
        } else {
            // longer than a year ago, show just year 
            humanDate = fileDateTime.getFullYear();
        }
        return humanDate;
    }

    function dayToText(day) {
        var days = {
            0: "Sun",
            1: "Mon",
            2: "Tue",
            3: "Wed",
            4: "Thu",
            5: "Fri",
            6: "Sat"
        };
        return days[day];
    }

    function monthToText(month) {
        var months = {
            0: "Jan",
            1: "Feb",
            2: "Mar",
            3: "Apr",
            4: "May",
            5: "Jun",
            6: "Jul",
            7: "Aug",
            8: "Sep",
            9: "Oct",
            10: "Nov",
            11: "Dec"
        };
        return months[month];
    }

    function fancyBytes(bytes) {
        var kilobyte = 1024;
        var megabyte = kilobyte * kilobyte;
        var gigabyte = megabyte * kilobyte;
        var terabyte = gigabyte * kilobyte;
        if (bytes >= terabyte) {
            return Math.round((bytes / terabyte)) + "TB"
        }
        if (bytes >= gigabyte) {
            return Math.round((bytes / gigabyte)) + "GB"
        }
        if (bytes >= megabyte) {
            return Math.round((bytes / megabyte)) + "MB"
        }
        if (bytes >= kilobyte) {
            return Math.round((bytes / kilobyte)) + "kB"
        }
        return bytes + " bytes";
    }

    function splitPath(fullPath) {
        var e = {
            pathEntries: []
        };
        parts = fullPath.split("/");
        $.each(parts, function (i, v) {
            if (v !== '') {
                e.pathEntries.push(v);
            }
        });
        return e;
    }
    var uploader_total_size;
    var uploader_uploaded;
    var uploader_files;
    var uploader_xhrs;
    var uploader_rdrs;
    var uploader_done;
    var uploader_block_size = 512 * 1024;

    function handleFiles(files) {
        uploader_files = files;
        uploader_total_size = 0;
        uploader_uploaded = [];
        if (uploader_files.length !== 0) {
            $('#startUpload').removeAttr('disabled');
            for (var i = 0; i < uploader_files.length; i++) {
                uploader_total_size += uploader_files[i].size;
                uploader_uploaded[i] = 0;
            }
            $('#statusBar').html("Selected " + uploader_files.length + " file(s) for upload, a total of " + fancyBytes(uploader_total_size) + ".");
            $('#progressBar').text("0%");
        }
    }

    function startUpload() {<commit_msg>increase block size to 1M<commit_after>$(document).ready(function () {
    var proxy_endpoint = "proxy.php";
    var params = {
        proxy_to: "http://192.168.3.11/fts/index.php",
        proxy_consumer_key: "demo",
        proxy_consumer_secret: "<KEY>",
        relativePath: "/",
    };

    function getDirList() {
        params.action = 'getDirList';
        $.get(proxy_endpoint, params, function (response) {
            $("#filelist").html($("#directoryList").tmpl(response, {
                fDate: function (timestamp) {
                    return fancyDateTime(timestamp);
                },
                fSize: function (bytes) {
                    return fancyBytes(bytes);
                }
            }));
        }, 'json');
        // FIXME: optimize this
        $("#breadcrumb").html($("#directoryPathViewer").tmpl(splitPath(params.relativePath)));
        $("#breadcrumb li").click(function (event) {
            var relPath;
            if ($(this).hasClass("root")) {
                relPath = "/";
            } else {
                relPath = $(this).text();
                $.each($(this).prevUntil("li.root"), function (i, val) {
                    relPath = $(this).text() + "/" + relPath;
                });
            }
            params.relativePath = relPath;
            getDirList();
        });
    }
    $('a#ftc_add').click(function (event) {
        $('#dropbox').show();
    });
    $('a#ftc_cancel_upload').click(function (event) {
        $('#dropbox').hide();
    });
    $('a.download').live('click', function (event) {
        var tmp_rp = params.relativePath;
        params.action = 'getDownloadToken';
        params.relativePath += "/" + $(this).parent().next().text();
        $.post(proxy_endpoint, params, function (response) {
            window.location.href = response.data.downloadLocation;
        }, 'json');
        params.relativePath = tmp_rp;
    });
    $('a.open').live('click', function (event) {
        params.relativePath += "/" + $(this).parent().next().text();
        getDirList();
    });
    $('a.delete').live('click', function (event) {
        var fileName = $(this).parent().prev().prev().prev().text();
        if (confirm("Are you sure you want to delete '" + fileName + "'?")) {
            var tmp_rp = params.relativePath;
            params.action = 'deleteFile';
            params.relativePath += "/" + fileName;
            $.post(proxy_endpoint, params, function (response) {
                params.relativePath = tmp_rp;
                getDirList();
            }, 'json');
        }
    });
    $('#inputFiles').bind('change', function (e) {
        handleFiles(this.files);
        e.stopPropagation();
        e.preventDefault();
    });
    $('#dropzone').bind('dragenter dragover', function (e) {
        e.stopPropagation();
        e.preventDefault();
    });
    $('#dropzone').bind('drop', function (e) {
        e.stopPropagation();
        e.preventDefault();
        handleFiles(e.originalEvent.dataTransfer.files);
    });
    $('#startUpload').click(function (e) {
        startUpload();
        e.stopPropagation();
        e.preventDefault();
    });
    $('#cancelUpload').click(function (e) {
        cancelUpload();
        e.stopPropagation();
        e.preventDefault();
    });

    function fancyDateTime(ts) {
        var now = new Date();
        var dayStart = new Date(now.getFullYear(), now.getMonth(), now.getDate());
        var fileDateTime = new Date(ts * 1000);
        var now_ts = Math.round(now.getTime() / 1000);
        var dayStart_ts = Math.round(dayStart.getTime() / 1000);
        var hours = (fileDateTime.getHours() < 10) ? "0" + fileDateTime.getHours() : fileDateTime.getHours();
        var minutes = (fileDateTime.getMinutes() < 10) ? "0" + fileDateTime.getMinutes() : fileDateTime.getMinutes();
        var humanDate;
        if (ts > dayStart_ts) {
            // today, show just time
            humanDate = hours + ":" + minutes;
        } else if (ts > (now_ts - 60 * 60 * 24 * 7)) {
            // last week, show just day and time
            humanDate = dayToText(fileDateTime.getDay()) + " " + hours + ":" + minutes;
        } else if ((ts > now_ts - 60 * 60 * 24 * 365)) {
            // longer than a week ago, show just month+day
            humanDate = monthToText(fileDateTime.getMonth()) + " " + fileDateTime.getDate();
        } else {
            // longer than a year ago, show just year 
            humanDate = fileDateTime.getFullYear();
        }
        return humanDate;
    }

    function dayToText(day) {
        var days = {
            0: "Sun",
            1: "Mon",
            2: "Tue",
            3: "Wed",
            4: "Thu",
            5: "Fri",
            6: "Sat"
        };
        return days[day];
    }

    function monthToText(month) {
        var months = {
            0: "Jan",
            1: "Feb",
            2: "Mar",
            3: "Apr",
            4: "May",
            5: "Jun",
            6: "Jul",
            7: "Aug",
            8: "Sep",
            9: "Oct",
            10: "Nov",
            11: "Dec"
        };
        return months[month];
    }

    function fancyBytes(bytes) {
        var kilobyte = 1024;
        var megabyte = kilobyte * kilobyte;
        var gigabyte = megabyte * kilobyte;
        var terabyte = gigabyte * kilobyte;
        if (bytes >= terabyte) {
            return Math.round((bytes / terabyte)) + "TB"
        }
        if (bytes >= gigabyte) {
            return Math.round((bytes / gigabyte)) + "GB"
        }
        if (bytes >= megabyte) {
            return Math.round((bytes / megabyte)) + "MB"
        }
        if (bytes >= kilobyte) {
            return Math.round((bytes / kilobyte)) + "kB"
        }
        return bytes + " bytes";
    }

    function splitPath(fullPath) {
        var e = {
            pathEntries: []
        };
        parts = fullPath.split("/");
        $.each(parts, function (i, v) {
            if (v !== '') {
                e.pathEntries.push(v);
            }
        });
        return e;
    }
    var uploader_total_size;
    var uploader_uploaded;
    var uploader_files;
    var uploader_xhrs;
    var uploader_rdrs;
    var uploader_done;
    var uploader_block_size = 1024 * 1024;

    function handleFiles(files) {
        uploader_files = files;
        uploader_total_size = 0;
        uploader_uploaded = [];
        if (uploader_files.length !== 0) {
            $('#startUpload').removeAttr('disabled');
            for (var i = 0; i < uploader_files.length; i++) {
                uploader_total_size += uploader_files[i].size;
                uploader_uploaded[i] = 0;
            }
            $('#statusBar').html("Selected " + uploader_files.length + " file(s) for upload, a total of " + fancyBytes(uploader_total_size) + ".");
            $('#progressBar').text("0%");
        }
    }

    function startUpload() {
{'fraction_non_alphanumeric': 0.15752583279138666, 'fraction_numerical': 0.011706048124864513, 'mean_word_length': 1.7411368587839176, 'pattern_counts': {'":': 4, '<': 11, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 2, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6363052', 'n_tokens_mistral': 4164, 'n_tokens_neox': 4024, 'n_words': 830}