<commit_before>var express = require('express');
var router = express.Router();
var request = require('request');
var MongoClient = require('mongodb').MongoClient;
var ObjectId = require('mongodb').ObjectId;

router.use(function(req, res, next) {
    res.header("Access-Control-Allow-Origin", "*");
    next();
});

function createError(message, status) {
    var err = new Error(message);
    err.status = status;

    return err;
}

router.post('/', function(req, res, next) {
    if (process.env.SKIP_FACEBOOK_AUTH) {
        console.log("skip facebook auth");

        next();
    } else {
        var access_token = req.body.access_token;

        if (! access_token) {
            next(createError("access_token is required", 429));

            return;
        } else if (access_token === "") {
            next(createError("access_token is required", 429));

            return;
        }

        console.log("facebook auth with access_token " + access_token);

        request.get({
            url: "https://graph.facebook.com/v2.6/me",
            qs: {
                access_token: access_token,
                fields: "id,name",
                format: "json",
            }
        }, function(error, response, body) {
            if (error) {
                console.log("request error");
                next(createError("access_token is invalid", 401));

                return;
            }

            var content = JSON.parse(body);

            if (content.error) {
                console.log("request response with error field");
                next(createError("access_token is invalid", 401));

                return;
            }

            req.facebook = {id: content.id, name: content.name};

            next();
        });
    }
});

router.post('/', function(req, res, next) {
    var author = {};

    if (req.body.email && (typeof req.body.email === "string") && req.body.email !== "") {
        author.email = req.body.email;
    }

    if (req.facebook) {
        author.id = req.facebook.id,
        author.name = req.facebook.name,
        author.type = "facebook";
    } else {
        author.type = "test";
    }

    var data = {
        author: author,<commit_msg>Insert with created_at<commit_after>var express = require('express');
var router = express.Router();
var request = require('request');
var MongoClient = require('mongodb').MongoClient;
var ObjectId = require('mongodb').ObjectId;

router.use(function(req, res, next) {
    res.header("Access-Control-Allow-Origin", "*");
    next();
});

function createError(message, status) {
    var err = new Error(message);
    err.status = status;

    return err;
}

router.post('/', function(req, res, next) {
    if (process.env.SKIP_FACEBOOK_AUTH) {
        console.log("skip facebook auth");

        next();
    } else {
        var access_token = req.body.access_token;

        if (! access_token) {
            next(createError("access_token is required", 429));

            return;
        } else if (access_token === "") {
            next(createError("access_token is required", 429));

            return;
        }

        console.log("facebook auth with access_token " + access_token);

        request.get({
            url: "https://graph.facebook.com/v2.6/me",
            qs: {
                access_token: access_token,
                fields: "id,name",
                format: "json",
            }
        }, function(error, response, body) {
            if (error) {
                console.log("request error");
                next(createError("access_token is invalid", 401));

                return;
            }

            var content = JSON.parse(body);

            if (content.error) {
                console.log("request response with error field");
                next(createError("access_token is invalid", 401));

                return;
            }

            req.facebook = {id: content.id, name: content.name};

            next();
        });
    }
});

router.post('/', function(req, res, next) {
    var author = {};

    if (req.body.email && (typeof req.body.email === "string") && req.body.email !== "") {
        author.email = req.body.email;
    }

    if (req.facebook) {
        author.id = req.facebook.id,
        author.name = req.facebook.name,
        author.type = "facebook";
    } else {
        author.type = "test";
    }

    var data = {
        author: author,
        created_at: new Date(),
{'fraction_non_alphanumeric': 0.1440393647953478, 'fraction_numerical': 0.0062625810780586, 'mean_word_length': 1.8851612903225807, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 2, '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': '714456', 'n_tokens_mistral': 1322, 'n_tokens_neox': 1237, 'n_words': 278}