<commit_before>const url = require('url')
const image = require('./image')

module.exports = (req, res) => {
  let {pathname, query} = url.parse(req.url, true)

  if (pathname === '/favicon.ico') {
    return ''
  }
  if (pathname === '/') {
    pathname = Math.random().toString()
  } else {
    res.setHeader('Cache-Control', 'max-age=2592000, public')
  }
  if (query.type === 'svg') {
    res.setHeader('Content-Type', 'svg+xml')
  } else {
    res.setHeader('Content-Type', 'image/png')
  }

  if (query.type === 'svg') {
    return image.generateSVG(pathname)
  }

  return image.generatePNG(pathname, query.size)
}<commit_msg>Accept type by extension<commit_after>const url = require('url')
const image = require('./image')
const svgExt = /\.svg$/;
const pngExt = /\.png$/;

module.exports = (req, res) => {
  let {pathname, query} = url.parse(req.url, true)

  if (pathname === '/favicon.ico') {
    return ''
  }
  if (pathname === '/') {
    pathname = Math.random().toString()
  } else {
    res.setHeader('Cache-Control', 'max-age=2592000, public')
  }
  if (query.type === 'svg' || svgExt.test(pathname)) {
    res.setHeader('Content-Type', 'svg+xml')
    return image.generateSVG(pathname.replace(svgExt, ''));
  }
  res.setHeader('Content-Type', 'image/png')
  return image.generatePNG(pathname.replace(pngExt, ''), query.size)
}
{'fraction_non_alphanumeric': 0.20386904761904762, 'fraction_numerical': 0.010416666666666666, 'mean_word_length': 3.6219931271477663, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 2}, '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': '5343025', 'n_tokens_mistral': 498, 'n_tokens_neox': 477, 'n_words': 90}