<commit_before>/**
 * Created with JetBrains WebStorm.
 * User: jonathan
 * Date: 14/01/2014
 * Time: 18:25
 * To change this template use File | Settings | File Templates.
 */
module.exports = function (app, config, passport, redisClient) {
  var formidable = require('formidable');

  app.post('/events/ubersmith/event/:event'
    , function(req, res){
      var form = new formidable.IncomingForm;
      var fields = {};

      app.locals.logger.log('debug', 'incoming event', { type: 'event', event: req.params.event, path: req.path })

      form.parse(req, function(err, fields, files){
        if (err) {
          app.locals.logger.log('error', 'could not process incoming event', { error: err, event: req.params.event, path: req.path });
          res.send(500);
        }
	      app.locals.logger.log('debug', 'parsing form', { type: 'event', fields: fields, files: files, event: req.params.event });
      });

      form.on('field', function(name, value) {
        app.locals.logger.log('debug', 'event field received', { type: 'event', field: name, event: req.params.event, value: value });
        fields[name] = value;
      });

      form.on('progress', function(bytesReceived, bytesExpected) {
        app.locals.logger.log('debug', 'incoming form data', { bytesReceived: bytesReceived, bytesExpected: bytesExpected });
      });

      form.on('error', function(err) {
        app.locals.logger.log('error', 'could not process incoming event', { error: err, event: req.params.event, path: req.path });
        res.send(500);
      });

      form.on('end', function() {
        app.locals.logger.log('debug', 'event complete', { type: 'event', event: req.params.event, fields: fields});

        if ('user' in fields)
        {
           var username = fields['user'];
        } else {
          var username = 'none';<commit_msg>handle JSON data sent as "uploaded file", useful for stdin and curl<commit_after>/**
 * Created with JetBrains WebStorm.
 * User: jonathan
 * Date: 14/01/2014
 * Time: 18:25
 * To change this template use File | Settings | File Templates.
 */
module.exports = function (app, config, passport, redisClient) {
  var formidable = require('formidable');
  var _ = require('underscore');

  app.post('/events/:source/event/:event'
    , function(req, res){
      var form = new formidable.IncomingForm;
      var fields = {};

      app.locals.logger.log('debug', 'incoming event', { type: 'event', event: req.params.event, path: req.path })

      form.parse(req, function(err, fields, files){
        if (err) {
          app.locals.logger.log('error', 'could not process incoming event', { error: err, event: req.params.event, path: req.path });
          res.send(500);
        }
	      app.locals.logger.log('debug', 'parsing form', { type: 'event', fields: fields, files: files, event: req.params.event });
      });

      form.on('field', function(name, value) {
        app.locals.logger.log('debug', 'event field received', { type: 'event', field: name, event: req.params.event, value: value });
        fields[name] = value;
      });

      form.on('progress', function(bytesReceived, bytesExpected) {
        app.locals.logger.log('debug', 'incoming form data', { bytesReceived: bytesReceived, bytesExpected: bytesExpected });
      });

      form.on('error', function(err) {
        app.locals.logger.log('error', 'could not process incoming event', { error: err, event: req.params.event, path: req.path });
        res.send(500);
      });

      form.on('aborted', function() {
        app.locals.logger.log('debug', 'aborted', { });
      });
      form.on('fileBegin', function(name, file) {
        app.locals.logger.log('debug', 'fileBegin', { name: name, file: file.toJSON() });
      });

      form.on('file', function(name, file) {
        var fs = require('fs');
        app.locals.logger.log('debug', 'file', { name: name, file: file.toJSON() });
        var filename = file.toJSON().path;
        var fileJSON = fs.readFileSync(filename,'utf8');
        _.defaults(fields, JSON.parse(fileJSON));
      });

      form.on('end', function() {
        app.locals.logger.log('debug', 'event complete', { type: 'event', event: req.params.event, fields: fields});

        if ('user' in fields)
        {
           var username = fields['user'];
        } else {
          var username = 'none';
{'fraction_non_alphanumeric': 0.16754526701810682, 'fraction_numerical': 0.008480403392161356, 'mean_word_length': 2.892952720785013, 'pattern_counts': {'":': 0, '<': 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': '2175432', 'n_tokens_mistral': 1360, 'n_tokens_neox': 1302, 'n_words': 329}