<commit_before>navigator.getUserMedia = navigator.getUserMedia ||
                         navigator.webkitGetUserMedia ||
                         navigator.mozGetUserMedia ||
                         navigator.msGetUserMedia;


function QrAPI(apiUrl, apiPassword) {
    this.apiUrl = apiUrl;
    this.apiPassword = apiPassword;
}
QrAPI.prototype = {
    getHistory: function getHistory() {
        return $.getJSON(
            this.apiUrl,
            {
                qrcode: "",
                password: <PASSWORD>
            }
        );
    },

    scanRequest: function scanRequest(barcode) {
        'use strict';
        return $.post(
            this.apiUrl,
            {
                "qrcode": barcode,
                "password": this.apiPassword
            },
            this.scanRequestSuccess,
            'json'
        )
    },

    scanRequestSuccess: function scanRequestSuccess(data) {
        if (data.status < 1) {
            var error;

            if (data.error.length <= 0) {
                error = "Unknown error occured";
            } else {
                error = data.error;
            }
            alert(error);

        } else if (data.paid < 1){
            alert("Hasn't paid!");

        } else {
            var user = data.user.user,
                firstName = user.first_name,
                lastName = user.last_name,
                successMessage = "";

            if (firstName.length > 0) {
                successMessage = firstName;
                if (lastName.length > 0) {
                    successMessage += lastName;
                }
            } else {
                successMessage = "Sign-in successful";
            }

            console.log(data);
            alert(successMessage);
        }
    },
}

function getSources() {
    var def = $.Deferred();

    window.MediaStreamTrack.getSources(function(sources){
        def.resolve(sources);
    });

    return def;
}

function color(c) {
    document.getElementsByClassName("match")[0].style['background-color'] = c;
}

function QRScanner() {
    this.videos_idx = 0;
    this.api = null;
    qrcode.debug = true;
    this.lock = false;
}
QRScanner.prototype = {
    gum_success: function gum_success(stream) {
        console.log(stream);
        this.video.src = window.URL.createObjectURL(stream)
    },

    gum_failure: function gum_failure(error) {
        alert("Failed!");
    },

    timerCallback: function timerCallback() {
        if (this.video.paused || this.video.ended) {
            return;
        }

        this.ctx.drawImage(this.video, 0, 0)

        this.do_decode();
        setTimeout(this.timerCallback.bind(this), 125);
    },

    do_decode: function do_decode() {
        try {
            this.qrcode_callback(qrcode.decode());
        } catch (e) {
            if (e !== "Couldn't find enough finder patterns") {
                console.log("Error: " + e);
            }
        }
    },

    qrcode_callback: _.debounce(function qrcode_callback(data) {
        document.getElementById("data").innerHTML = data;
        while(this.lock) {}
        this.lock = true;
        color("green");
        this.api.scanRequest(data);
        this.lock = false;
        setTimeout('color("red")', 500);
    }, 500),

    play_callback: function play_callback() {
        setTimeout(
            function(){
                this.c1.width = this.video.videoWidth;
                this.c1.height = this.video.videoHeight;
            }.bind(this),
            125
        )

        this.timerCallback();
    },

    getSourcesCallback: function getSourcesCallback(sources) {
        var videos = (
            sources
            .filter(function(q) { return q.kind == "video" })
        )
        var env = videos.filter(function(q) { return q.facing == "environment" });<commit_msg>Client-side validation of qr-code<commit_after>navigator.getUserMedia = navigator.getUserMedia ||
                         navigator.webkitGetUserMedia ||
                         navigator.mozGetUserMedia ||
                         navigator.msGetUserMedia;


function QrAPI(apiUrl, apiPassword) {
    this.apiUrl = apiUrl;
    this.apiPassword = <PASSWORD>;
}
QrAPI.prototype = {
    getHistory: function getHistory() {
        return $.getJSON(
            this.apiUrl,
            {
                qrcode: "",
                password: this.apiPassword
            }
        );
    },

    scanRequest: function scanRequest(barcode) {
        'use strict';
        return $.post(
            this.apiUrl,
            {
                "qrcode": barcode,
                "password": <PASSWORD>.apiPassword
            },
            this.scanRequestSuccess,
            'json'
        )
    },

    scanRequestSuccess: function scanRequestSuccess(data) {
        if (data.status < 1) {
            var error;

            if (data.error.length <= 0) {
                error = "Unknown error occured";
            } else {
                error = data.error;
            }
            alert(error);

        } else if (data.paid < 1){
            alert("Hasn't paid!");

        } else {
            var user = data.user.user,
                firstName = user.first_name,
                lastName = user.last_name,
                successMessage = "";

            if (firstName.length > 0) {
                successMessage = firstName;
                if (lastName.length > 0) {
                    successMessage += lastName;
                }
            } else {
                successMessage = "Sign-in successful";
            }

            console.log(data);
            alert(successMessage);
        }
    },
}

function getSources() {
    var def = $.Deferred();

    window.MediaStreamTrack.getSources(function(sources){
        def.resolve(sources);
    });

    return def;
}

function color(c) {
    document.getElementsByClassName("match")[0].style['background-color'] = c;
}

function QRScanner() {
    this.videos_idx = 0;
    this.api = null;
    qrcode.debug = true;
    this.lock = false;
}
QRScanner.prototype = {
    gum_success: function gum_success(stream) {
        console.log(stream);
        this.video.src = window.URL.createObjectURL(stream)
    },

    gum_failure: function gum_failure(error) {
        alert("Failed!");
    },

    timerCallback: function timerCallback() {
        if (this.video.paused || this.video.ended) {
            return;
        }

        this.ctx.drawImage(this.video, 0, 0)

        this.do_decode();
        setTimeout(this.timerCallback.bind(this), 125);
    },

    do_decode: function do_decode() {
        try {
            this.qrcode_callback(qrcode.decode());
        } catch (e) {
            if (e !== "Couldn't find enough finder patterns") {
                console.log("Error: " + e);
            }
        }
    },

    qrcode_callback: _.debounce(function qrcode_callback(data) {
        document.getElementById("data").innerHTML = data;

        if (!/^[0-9]+\$\$[a-z0-9]+\$\$[A-Za-z0-9]+$/.exec(data)) {
            document.getElementById("data").innerHTML += " is invalid";
            return;
        }

        while(this.lock) {}
        this.lock = true;
        color("green");
        this.api.scanRequest(data);
        this.lock = false;
        setTimeout('color("red")', 500);
    }, 500),

    play_callback: function play_callback() {
        setTimeout(
            function(){
                this.c1.width = this.video.videoWidth;
                this.c1.height = this.video.videoHeight;
            }.bind(this),
            125
        )

        this.timerCallback();
    },

    getSourcesCallback: function getSourcesCallback(sources) {
        var videos = (
            sources
            .filter(function(q) { return q.kind == "video" })
        )
        var env = videos.filter(function(q) { return q.facing == "environment" });
{'fraction_non_alphanumeric': 0.1218274111675127, 'fraction_numerical': 0.006598984771573604, 'mean_word_length': 1.5704500978473581, 'pattern_counts': {'":': 4, '<': 12, '<?xml version=': 0, '>': 10, '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': '838376', 'n_tokens_mistral': 2306, 'n_tokens_neox': 2153, 'n_words': 393}