<commit_before>const url = require('url');
const mimeTypes = require('mime-types');
const path = require('path');
const headFile = require('./head-file');
const getStatic = require('./get-static');
const getFile = require('./get-file');
const getFiles = require('./get-files');
const putFile = require('./put-file');
const deleteFile = require('./delete-file');
const deleteFiles = require('./delete-files');
const getAuthHandler = require('./get-auth');
const BlobbyClient = require('blobby-client');

module.exports = (argv, config) => {
  const client = new BlobbyClient(argv, config);

  if (typeof config.logger === 'function') {
    client.on('warn', msg => logger.warn(msg));
    client.on('error', msg => logger.error(msg));
  }

  return async (req, res) => {
    if (typeof config.httpHandler === 'function') {
      if (config.httpHandler(req, res) === false) return; // if handled by parent ignore request
    }
    const urlInfo = url.parse(req.url, true, true);
    let safePathname;
    try {
      safePathname = decodeURI(urlInfo.pathname).split('/').map(decodeURIComponent).join('/');
    } catch (ex) {
      client.emit('error', { message: `Cannot decodeURI ${urlInfo.pathname}`, stack: ex.stack || ex });
<commit_msg>fix logger<commit_after>const url = require('url');
const mimeTypes = require('mime-types');
const path = require('path');
const headFile = require('./head-file');
const getStatic = require('./get-static');
const getFile = require('./get-file');
const getFiles = require('./get-files');
const putFile = require('./put-file');
const deleteFile = require('./delete-file');
const deleteFiles = require('./delete-files');
const getAuthHandler = require('./get-auth');
const BlobbyClient = require('blobby-client');

module.exports = (argv, config) => {
  const client = new BlobbyClient(argv, config);

  if (typeof config.logger === 'object') {
    client.on('warn', msg => config.logger.warn(msg));
    client.on('error', msg => config.logger.error(msg));
  }

  return async (req, res) => {
    if (typeof config.httpHandler === 'function') {
      if (config.httpHandler(req, res) === false) return; // if handled by parent ignore request
    }
    const urlInfo = url.parse(req.url, true, true);
    let safePathname;
    try {
      safePathname = decodeURI(urlInfo.pathname).split('/').map(decodeURIComponent).join('/');
    } catch (ex) {
      client.emit('error', { message: `Cannot decodeURI ${urlInfo.pathname}`, stack: ex.stack || ex });

{'fraction_non_alphanumeric': 0.18672032193158955, 'fraction_numerical': 0.0, 'mean_word_length': 4.200836820083682, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 11, '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': '3171565', 'n_tokens_mistral': 734, 'n_tokens_neox': 731, 'n_words': 189}