<commit_before>var Screenshot = require('./screenshotModel');
var User = require('../user/userModel');
var takeScreenshot = require('../../screenshotCapture/script.js');
var Promise = require('bluebird');

exports.list = function(req, res, next){
  // user found through router.param
  var user = req.foundUser;
  // find screenshots whos user_id's match the found users username
  Screenshot.find({ user_id: user.username }, function(err, screenshots){
    if (err) return res.status(500).json({
      status: 500, message: 'Internal Server Error'
    });
    res.status(200).json(screenshots);
  });
};

exports.create = function(req, res, next) {
  var url = req.body.url;
  var username = req.params.username;
  var annotatedImage = req.body.annotatedImage;

  takeScreenshot(url, function(imageUrl) {
    var originalImage = imageUrl;
    // TODO: change annotatedImage to something real
    var annotatedImage = imageUrl;

    var newScreenshot = new Screenshot({url: url, originalImage: originalImage,
                      annotatedImage: annotatedImage, user_id: username});
    console.log('new screenshot:', newScreenshot);

    newScreenshot.save(function(err, screenshot) {
      if (err) {
        console.log('err', err);
        return res.status(500).end(err);
      }
      User.findOne({username: username}, function(err, user) {
        if (err) {
          console.log('err', err);
          return res.status(404).end(err);
        }
        User.update({username: username}, {$push: {"images": screenshot._id}}, function(err, numAffected, rawResponse) {
          if (err) {
            console.log('err', err);
            return res.status(500).end(err);
          }
          res.status(201).end(screenshot);
        })
      })
    });
  });
};

exports.show = function(req, res, next) {
  var username = req.params.username;
  var id = req.params.id;
  Screenshot.findOne({ _id: id }, function(err, screenshot) {
    if (err) return res.send(500);
    res.status(200).json(screenshot);
  });
};
<commit_msg>change return format for errors<commit_after>var Screenshot = require('./screenshotModel');
var User = require('../user/userModel');
var takeScreenshot = require('../../screenshotCapture/script.js');
var Promise = require('bluebird');

exports.list = function(req, res, next){
  // user found through router.param
  var user = req.foundUser;
  // find screenshots whos user_id's match the found users username
  Screenshot.find({ user_id: user.username }, function(err, screenshots){
    if (err) return res.status(500).json({
      status: 500, message: 'Internal Server Error'
    });
    res.status(200).json(screenshots);
  });
};

exports.create = function(req, res, next) {
  var url = req.body.url;
  var username = req.params.username;
  var annotatedImage = req.body.annotatedImage;

  takeScreenshot(url, function(imageUrl) {
    var originalImage = imageUrl;
    // TODO: change annotatedImage to something real
    var annotatedImage = imageUrl;

    var newScreenshot = new Screenshot({url: url, originalImage: originalImage,
                      annotatedImage: annotatedImage, user_id: username});
    console.log('new screenshot:', newScreenshot);

    newScreenshot.save(function(err, screenshot) {
      if (err) {
        console.log('err', err);
        return res.status(500).json({ message: err });
      }
      User.findOne({username: username}, function(err, user) {
        if (err) {
          console.log('err', err);
          return res.status(404).json({ message: err });
        }
        User.update({username: username}, {$push: {"images": screenshot._id}}, function(err, numAffected, rawResponse) {
          if (err) {
            console.log('err', err);
            return res.status(500).json({ message: err });
          }
          res.status(201).json(screenshot);
        })
      })
    });
  });
};

exports.show = function(req, res, next) {
  var username = req.params.username;
  var id = req.params.id;
  Screenshot.findOne({ _id: id }, function(err, screenshot) {
    if (err) return res.send(500);
    res.status(200).json(screenshot);
  });
};

{'fraction_non_alphanumeric': 0.14839022028564514, 'fraction_numerical': 0.013071895424836602, 'mean_word_length': 3.0509803921568626, 'pattern_counts': {'":': 2, '<': 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': '968911', 'n_tokens_mistral': 1333, 'n_tokens_neox': 1240, 'n_words': 294}