<commit_before>var fs = require('fs') ,
    knox = require('knox'),
    path = require('path'),
common = require('../../../api/common');


module.exports = function(req, res){
    console.log("Faces Game Upload")
    console.log(req.files)      ;
    var name= req.files.Filedata.name
    fu(req,function(err,value) {
        console.log(value)      ;
        if(err)
        {
            console.log('error :' )      ;
            for(var propertyName in err) {

                console.log(propertyName + ": "+ err[propertyName])  ;
            }

            res.write(err);
            res.end();
        }
        else {
            console.log('success :' +'http://www.uru.org.il/faces_game/uploads/'+name)
            res.write('http://www.uru.org.il/faces_game/uploads/'+name);
            res.end();
        }
    });

};


function fu(req,callback) {

    var sanitize_filename = function(filename) {
            // This regex matches any character that's not alphanumeric, '_', '-' or '.', thus sanitizing the filename.
            // Hebrew characters are not allowed because they would wreak havoc with the url in any case.
            var regex = /[^-\w_\.]/g;
            return decodeURIComponent(filename).replace(regex, '-');
        },
        filename_to_path = function (filename) {
            return path.join(__dirname,'..','deliver','public','cdn', filename);
        },
        create_file = function (filename, callback) {
            // This function attempts to create 0_filename, 1_filename, etc., until it finds a file that doesn't exist.
            // Then it creates that and returns by calling callback(null, name, path, stream);
            var attempt = function (index) {
                var name = index + '_' + filename;
                var path = filename_to_path(name);
                fs.exists(path, function (exists) {
                    if (exists) {
                        attempt(index + 1);
                    } else {
                        // File doesn't exist. We can create it
                        callback(null, name, path, fs.createWriteStream(path));
                    }
                });
            };
            attempt(0);
        },
        writeToFile = function (fName, stream, callback){
            create_file(sanitize_filename(fName), function (err, filename, fullPath, os) {
                if (err) {
                    return callback(err);
                }<commit_msg>faces game<commit_after>var fs = require('fs') ,
    knox = require('knox'),
    path = require('path'),
common = require('../../../api/common');


module.exports = function(req, res){
    console.log("Faces Game Upload")
    console.log(req.files)      ;
    var name= req.files.Filedata.name
    fu(req,function(err,value) {
        console.log(value)      ;
        if(err)
        {
            console.log('error :' )      ;
            for(var propertyName in err) {

                console.log(propertyName + ": "+ err[propertyName])  ;
            }

            res.write(err);
            res.end();
        }
        else {
            console.log('success :' +'http://www.uru.org.il/faces_game/uploads/'+name)
            res.write('http://www.uru.org.il/faces_game/uploads/'+name);
            res.end();
        }
    });

};


function fu(req,callback) {

    var sanitize_filename = function(filename) {
            // This regex matches any character that's not alphanumeric, '_', '-' or '.', thus sanitizing the filename.
            // Hebrew characters are not allowed because they would wreak havoc with the url in any case.
            var regex = /[^-\w_\.]/g;
            return decodeURIComponent(filename).replace(regex, '-');
        },
        filename_to_path = function (filename) {
            return path.join(__dirname,'..','deliver','public','cdn', filename);
        },
        create_file = function (filename, callback) {
            // This function attempts to create 0_filename, 1_filename, etc., until it finds a file that doesn't exist.
            // Then it creates that and returns by calling callback(null, name, path, stream);
            var attempt = function (index) {
                var name = index + '_' + filename;
                var path =    req.files.Filedata.path+'/'+ filename
                fs.exists(path, function (exists) {
                    if (exists) {
                        attempt(index + 1);
                    } else {
                        // File doesn't exist. We can create it
                        callback(null, name, path, fs.createWriteStream(path));
                    }
                });
            };
            attempt(0);
        },
        writeToFile = function (fName, stream, callback){
            create_file(sanitize_filename(fName), function (err, filename, fullPath, os) {
                if (err) {
                    return callback(err);
                }
{'fraction_non_alphanumeric': 0.13017871649065801, 'fraction_numerical': 0.0016246953696181965, 'mean_word_length': 1.6141188959660298, 'pattern_counts': {'":': 2, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 4, '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': '5387161', 'n_tokens_mistral': 1348, 'n_tokens_neox': 1292, 'n_words': 320}