<commit_before>var key = require('../utils/key');
var sync = require('synchronize');
var request = require('request');
var _ = require('underscore');


// The API that returns the in-email representation.
module.exports = function(req, res) {
  var term = req.query.text.trim();

  if (/^http:\/\/giphy\.com\/\S+/.test(term)) {
    // Special-case: handle strings in the special URL form that are suggested by the commandHint
    // API. This is how the command hint menu suggests an exact Giphy image.
    handleIdString(term.replace(/^http:\/\/giphy\.com\//, ''), req, res);
  } else {
    // Else, assume it was a search string.
    handleSearchString(term, req, res);
  }
};

function handleIdString(id, req, res) {
  var response;
  try {
    response = sync.await(request({
      url: 'http://api.giphy.com/v1/gifs/' + encodeURIComponent(id),
      qs: {
        api_key: key
      },
      gzip: true,
      json: true,
      timeout: 15 * 1000
    }, sync.defer()));
  } catch (e) {
    res.status(500).send('Error');
    return;
  }

  var image = response.body.data.images.original;
  var width = image.width > 600 ? 600 : image.width;
  var html = '<p><img style="max-width:100%;" src="' + image.url + '" width="' + width + '"/></p>';
  res.json({
    body: html
  });
}

function handleSearchString(term, req, res) {
  var response;
  try {
    response = sync.await(request({
      url: 'http://api.giphy.com/v1/gifs/random',
      qs: {
        tag: term,
        api_key: key
      },
      gzip: true,
      json: true,
      timeout: 15 * 1000
    }, sync.defer()));
  } catch (e) {
    res.status(500).send('Error');
    return;
  }

  var data = response.body.data;

  // Cap at 600px wide
  var width = data.image_width > 600 ? 600 : data.image_width;
  var html = '<p><img style="max-width:100%;" src="' + data.image_url + '" width="' + width + '"/></p>';
  res.json({
    body: html
  });
}<commit_msg>Remove paragraph tag that adds extra spacing.<commit_after>var key = require('../utils/key');
var sync = require('synchronize');
var request = require('request');
var _ = require('underscore');


// The API that returns the in-email representation.
module.exports = function(req, res) {
  var term = req.query.text.trim();

  if (/^http:\/\/giphy\.com\/\S+/.test(term)) {
    // Special-case: handle strings in the special URL form that are suggested by the commandHint
    // API. This is how the command hint menu suggests an exact Giphy image.
    handleIdString(term.replace(/^http:\/\/giphy\.com\//, ''), req, res);
  } else {
    // Else, assume it was a search string.
    handleSearchString(term, req, res);
  }
};

function handleIdString(id, req, res) {
  var response;
  try {
    response = sync.await(request({
      url: 'http://api.giphy.com/v1/gifs/' + encodeURIComponent(id),
      qs: {
        api_key: key
      },
      gzip: true,
      json: true,
      timeout: 15 * 1000
    }, sync.defer()));
  } catch (e) {
    res.status(500).send('Error');
    return;
  }

  var image = response.body.data.images.original;
  var width = image.width > 600 ? 600 : image.width;
  var html = '<img style="max-width:100%;" src="' + image.url + '" width="' + width + '"/>';
  res.json({
    body: html
    // Add raw:true if you're returning content that you want the user to be able to edit
  });
}

function handleSearchString(term, req, res) {
  var response;
  try {
    response = sync.await(request({
      url: 'http://api.giphy.com/v1/gifs/random',
      qs: {
        tag: term,
        api_key: key
      },
      gzip: true,
      json: true,
      timeout: 15 * 1000
    }, sync.defer()));
  } catch (e) {
    res.status(500).send('Error');
    return;
  }

  var data = response.body.data;

  // Cap at 600px wide
  var width = data.image_width > 600 ? 600 : data.image_width;
  var html = '<img style="max-width:100%;" src="' + data.image_url + '" width="' + width + '"/>';
  res.json({
    body: html
    // Add raw:true if you're returning content that you want the user to be able to edit
  });
}
{'fraction_non_alphanumeric': 0.1697973306969847, 'fraction_numerical': 0.020266930301532378, 'mean_word_length': 2.6263440860215055, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 15, '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': '7270574', 'n_tokens_mistral': 1448, 'n_tokens_neox': 1349, 'n_words': 372}