<commit_before>// Generated by CoffeeScript 1.10.0
(function() {
  var InfoJSONCreator, Informer, cache_info_json, config, fs, iiif, info_cache, info_json_response, jp2_binary, log, resolve_source_image_path, retrieve_cached_info_json, server_info;

  fs = require('fs');

  log = require('./index').log;

  config = require('config');

  jp2_binary = config.get('jp2_binary');

  iiif = require('iiif-image');

  InfoJSONCreator = iiif.InfoJSONCreator;

  Informer = iiif.Informer(jp2_binary);

  info_cache = require('./index').info_cache;

  resolve_source_image_path = require('./resolver').resolve_source_image_path;

  retrieve_cached_info_json = require('./caching/retrieve-cached-info-json');

  server_info = require('./server-info');

  cache_info_json = require('./caching/cache-info-json');

  info_json_response = function(req, res) {

    /*
    Information requests are easy to parse, so we just take the next to the
    last element to make our id. Note that this image server does not
    decodeURIComponent as our implementation of a file resolver in
    resolve_source_image_path is not robust enough to defend against a directory
    traversal attack.
     */
    var id, source_image_path, url, url_parts;
    url = req.path;
    url_parts = url.split('/');
    id = url_parts[url_parts.length - 2];
    source_image_path = resolve_source_image_path(id);

    /*
    Check to see if the image exists. If not return a 404. If the image exists
    return the information about the image.
     */
    return fs.stat(source_image_path, function(err, stats) {
      var info_cb;
      if (err) {
        log.info({
          res: '404',
          url: url,
          ip: req.ip
        }, '404');
        return res.status(404).send('404');
      } else {
        info_cb = function(info) {
          var info_json, info_json_creator;
          info_json_creator = new InfoJSONCreator(info, server_info(req, id));
          log.info({
            res: 'info',
            url: url,
            ip: req.ip
          }, 'response info.json');
          info_json = info_json_creator.info_json;
          res.send(info_json);
          info_cache.set(id, info_json);
          log.info({
            cache: 'info',
            op: 'set',
            url: url,
            ip: req.ip
          }, 'info cached');
          return cache_info_json(req, info_json);
        };
        if (req.get('Accept') && req.get('Accept').match(/application\/ld\+json/)) {
          res.set('Content-Type', 'application/ld+json');
        }
        return retrieve_cached_info_json(id, function(info) {
          var informer;
          if (info) {
            log.info({
              cache: 'info',
              found: 'hit',
              url: url,
              ip: req.ip
            });
            return res.send(info);
          } else {
            log.info({
              cache: 'info',
              found: 'miss',
              url: url,
              ip: req.ip
            });<commit_msg>add info to profile<commit_after>// Generated by CoffeeScript 1.10.0
(function() {
  var InfoJSONCreator, Informer, cache_info_json, config, fs, iiif, info_cache, info_json_response, jp2_binary, log, resolve_source_image_path, retrieve_cached_info_json, server_info;

  fs = require('fs');

  log = require('./index').log;

  config = require('config');

  jp2_binary = config.get('jp2_binary');

  iiif = require('iiif-image');

  InfoJSONCreator = iiif.InfoJSONCreator;

  Informer = iiif.Informer(jp2_binary);

  info_cache = require('./index').info_cache;

  resolve_source_image_path = require('./resolver').resolve_source_image_path;

  retrieve_cached_info_json = require('./caching/retrieve-cached-info-json');

  server_info = require('./server-info');

  cache_info_json = require('./caching/cache-info-json');

  info_json_response = function(req, res) {

    /*
    Information requests are easy to parse, so we just take the next to the
    last element to make our id. Note that this image server does not
    decodeURIComponent as our implementation of a file resolver in
    resolve_source_image_path is not robust enough to defend against a directory
    traversal attack.
     */
    var id, source_image_path, url, url_parts;
    url = req.path;
    url_parts = url.split('/');
    id = url_parts[url_parts.length - 2];
    source_image_path = resolve_source_image_path(id);

    /*
    Check to see if the image exists. If not return a 404. If the image exists
    return the information about the image.
     */
    return fs.stat(source_image_path, function(err, stats) {
      var info_cb;
      if (err) {
        log.info({
          res: '404',
          url: url,
          ip: req.ip
        }, '404');
        return res.status(404).send('404');
      } else {
        info_cb = function(info) {
          var info_json, info_json_creator;
          info_json_creator = new InfoJSONCreator(info, server_info(req, id));
          log.info({
            res: 'info',
            url: url,
            ip: req.ip
          }, 'response info.json');
          info_json = info_json_creator.info_json;
          info_json.profile.push({
            formats: ['jpg']
          });
          res.send(info_json);
          info_cache.set(id, info_json);
          log.info({
            cache: 'info',
            op: 'set',
            url: url,
            ip: req.ip
          }, 'info cached');
          return cache_info_json(req, info_json);
        };
        if (req.get('Accept') && req.get('Accept').match(/application\/ld\+json/)) {
          res.set('Content-Type', 'application/ld+json');
        }
        return retrieve_cached_info_json(id, function(info) {
          var informer;
          if (info) {
            log.info({
              cache: 'info',
              found: 'hit',
              url: url,
              ip: req.ip
            });
            return res.send(info);
          } else {
            log.info({
              cache: 'info',
              found: 'miss',
              url: url,
              ip: req.ip
            });
{'fraction_non_alphanumeric': 0.11986863711001643, 'fraction_numerical': 0.007881773399014778, 'mean_word_length': 2.1044852191641183, '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': '4521227', 'n_tokens_mistral': 1872, 'n_tokens_neox': 1812, 'n_words': 448}