<commit_before>var router = require('express').Router();
var logging = require('../modules/logging');
var helpers = require('../modules/helpers');
var config = require('../modules/config');
var skins = require('../modules/skins');
var renders = require('../modules/renders');
var fs = require('fs');

var human_status = {
  0: "none",
  1: "cached",
  2: "downloaded",
  3: "checked",
  "-1": "error"
};

// valid types: head, body. helmet is query param

// The Type logic should be two separate GET
// functions once response methods are extracted
router.get('/:type/:uuid.:ext?', function(req, res) {
  var raw_type = req.params.type;

  // Check valid type for now
  if (raw_type != "body" && raw_type != "head") {
    res.status(404).send("404 Invalid Render Type");
    return;
  }

  var body = raw_type == "body";
  var uuid = req.params.uuid;
  var def = req.query.default;
  var scale = parseInt(req.query.scale) || config.default_scale;
  var helm = req.query.hasOwnProperty('helm');
  var start = new Date();
  var etag = null;

  if (scale < config.min_scale || scale > config.max_scale) {
    // Preventing from OOM crashes.
    res.status(422).send("422 Invalid Size");
  } else if (!helpers.uuid_valid(uuid)) {
    res.status(422).send("422 Invalid UUID");
    return;
  }

  // strip dashes, to lowercase
  uuid = uuid.replace(/-/g, "").toLowerCase();

  try {
    helpers.get_render(uuid, scale, helm, body, function(err, status, hash, image) {
      logging.log(uuid + " - " + human_status[status]);
      if (err) {
        logging.error(err);
      }
      etag = hash && hash.substr(0, 32) || "none";
      var matches = req.get("If-None-Match") == '"' + etag + '"';
      if (image) {
        var http_status = 200;
        if (matches) {
          http_status = 304;
        } else if (err) {
          http_status = 503;
        }
        logging.log("matches: " + matches);
        logging.log("Etag: " + req.get("If-None-Match"));
        logging.log("status: " + http_status);
        sendimage(http_status, status, image);
      } else {
        logging.log("image not found, using default.");
        handle_default(404, status);
      }<commit_msg>Revert "Lower case UUIDs - renders"<commit_after>var router = require('express').Router();
var logging = require('../modules/logging');
var helpers = require('../modules/helpers');
var config = require('../modules/config');
var skins = require('../modules/skins');
var renders = require('../modules/renders');
var fs = require('fs');

var human_status = {
  0: "none",
  1: "cached",
  2: "downloaded",
  3: "checked",
  "-1": "error"
};

// valid types: head, body. helmet is query param

// The Type logic should be two separate GET
// functions once response methods are extracted
router.get('/:type/:uuid.:ext?', function(req, res) {
  var raw_type = req.params.type;

  // Check valid type for now
  if (raw_type != "body" && raw_type != "head") {
    res.status(404).send("404 Invalid Render Type");
    return;
  }

  var body = raw_type == "body";
  var uuid = req.params.uuid;
  var def = req.query.default;
  var scale = parseInt(req.query.scale) || config.default_scale;
  var helm = req.query.hasOwnProperty('helm');
  var start = new Date();
  var etag = null;

  if (scale < config.min_scale || scale > config.max_scale) {
    // Preventing from OOM crashes.
    res.status(422).send("422 Invalid Size");
  } else if (!helpers.uuid_valid(uuid)) {
    res.status(422).send("422 Invalid UUID");
    return;
  }

  // strip dashes
  uuid = uuid.replace(/-/g, "");

  try {
    helpers.get_render(uuid, scale, helm, body, function(err, status, hash, image) {
      logging.log(uuid + " - " + human_status[status]);
      if (err) {
        logging.error(err);
      }
      etag = hash && hash.substr(0, 32) || "none";
      var matches = req.get("If-None-Match") == '"' + etag + '"';
      if (image) {
        var http_status = 200;
        if (matches) {
          http_status = 304;
        } else if (err) {
          http_status = 503;
        }
        logging.log("matches: " + matches);
        logging.log("Etag: " + req.get("If-None-Match"));
        logging.log("status: " + http_status);
        sendimage(http_status, status, image);
      } else {
        logging.log("image not found, using default.");
        handle_default(404, status);
      }
{'fraction_non_alphanumeric': 0.17164522058823528, 'fraction_numerical': 0.017463235294117647, 'mean_word_length': 2.798429319371728, 'pattern_counts': {'":': 2, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2049550', 'n_tokens_mistral': 1460, 'n_tokens_neox': 1400, 'n_words': 361}