<commit_before>// web.js
var fs = require("fs");
var path = require("path");

var express = require("express");
var logfmt = require("logfmt");
var mime = require("mime");


// Locals
var pastes = {}; // maps paste ID => creation time


// Clean up pastes
fs.readdirSync(path.join(__dirname, "pastes")).forEach(function(file) {
  fs.unlinkSync(path.join(__dirname, "pastes", file));
});


// Initiate
var app = express();

// middleware
app.use(logfmt.requestLogger()); // logfmt
app.use(express.urlencoded()); // support URL-encoded bodies


// Serves the main page
app.get("/", function(req, res) {
  res.sendfile(path.join(__dirname, "public",  "index.html"));
});

// Serves other public files
app.get("/public/:file", function(req, res) {
  var file = req.params.file;

  // MIME type handling
  var type = mime.lookup(file, "");
  if (!res.getHeader("content-type") && type != "") {
    var charset = mime.charsets.lookup(type);
    res.setHeader("Content-Type", type + (charset ? "; charset=" + charset : ""));
  }

  // Send the file
  res.sendfile(path.join(__dirname, "public", file), function(err) {
    if (err) {
      res.setHeader("Content-Type", "text/html");
      res.status(404).sendfile(path.join(__dirname, "public", "404.html"));
    }
  });
});


// Serves a paste
app.get(/^\/([a-b0-9]{1,2})(\.\w+)?\/?$/, function(req, res) {
  var file = req.params[0];
  var ext = req.params[1];

  // MIME type handling
  var type = mime.lookup(ext, "");
  if (!res.getHeader("content-type") && type != "") {
    var charset = mime.charsets.lookup(type);
    res.setHeader("Content-Type", type + (charset ? "; charset=" + charset : ""));
  }

  // Send the file
  res.sendfile(path.join(__dirname, "pastes", file), {}, function(err) {
    if (err) {
      res.setHeader("Content-Type", "text/html");
      res.status(404).sendfile(path.join(__dirname, "public", "404.html"));
    }
  });
});
<commit_msg>Fix regex typo<commit_after>// web.js
var fs = require("fs");
var path = require("path");

var express = require("express");
var logfmt = require("logfmt");
var mime = require("mime");


// Locals
var pastes = {}; // maps paste ID => creation time


// Clean up pastes
fs.readdirSync(path.join(__dirname, "pastes")).forEach(function(file) {
  fs.unlinkSync(path.join(__dirname, "pastes", file));
});


// Initiate
var app = express();

// middleware
app.use(logfmt.requestLogger()); // logfmt
app.use(express.urlencoded()); // support URL-encoded bodies


// Serves the main page
app.get("/", function(req, res) {
  res.sendfile(path.join(__dirname, "public",  "index.html"));
});

// Serves other public files
app.get("/public/:file", function(req, res) {
  var file = req.params.file;

  // MIME type handling
  var type = mime.lookup(file, "");
  if (!res.getHeader("content-type") && type != "") {
    var charset = mime.charsets.lookup(type);
    res.setHeader("Content-Type", type + (charset ? "; charset=" + charset : ""));
  }

  // Send the file
  res.sendfile(path.join(__dirname, "public", file), function(err) {
    if (err) {
      res.setHeader("Content-Type", "text/html");
      res.status(404).sendfile(path.join(__dirname, "public", "404.html"));
    }
  });
});


// Serves a paste
app.get(/^\/([a-z0-9]{1,2})(\.\w+)?\/?$/, function(req, res) {
  var file = req.params[0];
  var ext = req.params[1];

  // MIME type handling
  var type = mime.lookup(ext, "");
  if (!res.getHeader("content-type") && type != "") {
    var charset = mime.charsets.lookup(type);
    res.setHeader("Content-Type", type + (charset ? "; charset=" + charset : ""));
  }

  // Send the file
  res.sendfile(path.join(__dirname, "pastes", file), {}, function(err) {
    if (err) {
      res.setHeader("Content-Type", "text/html");
      res.status(404).sendfile(path.join(__dirname, "public", "404.html"));
    }
  });
});

{'fraction_non_alphanumeric': 0.21352127381884625, 'fraction_numerical': 0.009397024275646046, 'mean_word_length': 3.567342073897497, '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': '6006536', 'n_tokens_mistral': 1364, 'n_tokens_neox': 1311, 'n_words': 278}