<commit_before>'use strict';

var restify = require('restify');

module.exports = function(debugMode) {
  var debug;
  if(debugMode === true) {
    debug = console.log;
  }
  if(!debugMode) {
    debug = function() {};
  }
  else {
    debug = debugMode;
  }

  // Create a fake HTTP server
  var apiServer = restify.createServer();
  apiServer.use(restify.acceptParser(apiServer.acceptable));
  apiServer.use(restify.queryParser());
  apiServer.use(restify.bodyParser());

  apiServer.post('/documents', function(req, res, next) {
    debug("POST " + req.url, req.params);

    if(!req.params.identifier) {
      return next(new restify.MissingParameterError("Specify identifier parameter."));
    }


    res.send(200, req.params);
    next();
  });

  apiServer.del('/documents/identifier/:identifier', function(req, res, next) {
    if(!req.params.identifier) {
      return next(new restify.MissingParameterError("Specify identifier parameter."));
    }

    debug("DELETE /documents", req.params.identifier);

    res.send(204);
    next();
  });

  apiServer.post('/documents/identifier/:identifier/file', function(req, res, next) {
    debug("POST " + req.url, req.params);

    if(!req.params.identifier) {
      return next(new restify.MissingParameterError("Specify identifier parameter."));
    }

    if(!req.files || !req.files.file) {
      return next(new restify.MissingParameterError("Expected a file."));
    }

    if(req.files.file.size === 0) {
      return next(new restify.MissingParameterError("File sent to /document/file is empty and contains no data."));
    }

    res.send(204);
    next();
  });

  return apiServer;<commit_msg>fix debug DELETE /documents<commit_after>'use strict';

var restify = require('restify');

module.exports = function(debugMode) {
  var debug;
  if(debugMode === true) {
    debug = console.log;
  }
  if(!debugMode) {
    debug = function() {};
  }
  else {
    debug = debugMode;
  }

  // Create a fake HTTP server
  var apiServer = restify.createServer();
  apiServer.use(restify.acceptParser(apiServer.acceptable));
  apiServer.use(restify.queryParser());
  apiServer.use(restify.bodyParser());

  apiServer.post('/documents', function(req, res, next) {
    debug("POST " + req.url, req.params);

    if(!req.params.identifier) {
      return next(new restify.MissingParameterError("Specify identifier parameter."));
    }

    res.send(200, req.params);
    next();
  });

  apiServer.del('/documents/identifier/:identifier', function(req, res, next) {
    debug("DELETE /documents" + req.url, req.params);

    if(!req.params.identifier) {
      return next(new restify.MissingParameterError("Specify identifier parameter."));
    }

    res.send(204);
    next();
  });

  apiServer.post('/documents/identifier/:identifier/file', function(req, res, next) {
    debug("POST " + req.url, req.params);

    if(!req.params.identifier) {
      return next(new restify.MissingParameterError("Specify identifier parameter."));
    }

    if(!req.files || !req.files.file) {
      return next(new restify.MissingParameterError("Expected a file."));
    }

    if(req.files.file.size === 0) {
      return next(new restify.MissingParameterError("File sent to /document/file is empty and contains no data."));
    }

    res.send(204);
    next();
  });

  return apiServer;
{'fraction_non_alphanumeric': 0.15735735735735737, 'fraction_numerical': 0.006006006006006006, 'mean_word_length': 3.513550135501355, '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': '2323795', 'n_tokens_mistral': 1063, 'n_tokens_neox': 1013, 'n_words': 201}