<commit_before>const path = require('path');

module.exports = function (req, res, next) {
  // the embedded viewer is not handled by this file
  if (!!req.query.embedded) return next();

  const Project = req.app.locals.models.Project;

  const conditions = {
    owner: req.params.owner,
    project: req.params.project
  };

  Project.findOne(conditions, (err, result) => {
    if (err) {
      return res.status(500).send(err);
    }

    if (!result || (!result.report && !result.presentation)) {
      return res.status(404).send('No valid content found.');
    }

    if (result.report) {
      res.redirect(path.join(req.url, 'report'));
    } else if (result.presentation) {
      res.redirect(path.join(req.url, 'presentation'));
    }
  });
}
<commit_msg>Case insensitive URLs!<commit_after>const path = require('path');

module.exports = function (req, res, next) {
  // the embedded viewer is not handled by this file
  if (!!req.query.embedded) return next();

  const Project = req.app.locals.models.Project;

  const conditions = {
    owner: {$regex: new RegExp('^' + req.params.owner.toLowerCase(), 'i')},
    project: {$regex: new RegExp('^' + req.params.project.toLowerCase(), 'i')}
  };

  Project.findOne(conditions, (err, result) => {
    if (err) {
      return res.status(500).send(err);
    }

    if (!result || (!result.report && !result.presentation)) {
      return res.status(404).send('No valid content found.');
    }

    if (result.report) {
      res.redirect(path.join(req.url, 'report'));
    } else if (result.presentation) {
      res.redirect(path.join(req.url, 'presentation'));
    }
  });
}

{'fraction_non_alphanumeric': 0.1730886850152905, 'fraction_numerical': 0.007339449541284404, 'mean_word_length': 3.227390180878553, 'pattern_counts': {'":': 0, '<': 3, '<?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': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2756938', 'n_tokens_mistral': 543, 'n_tokens_neox': 518, 'n_words': 120}