<commit_before>"use strict";

var extend = require('extend');
var fs = require('fs');

var logger = require('../logger');
var route_helper = require('../helper/route');
var scanner = require('../scanner');

var file_max_size = require('../config').get('FILE:MAX_SIZE');
var router = require('express').Router();
var upload = require('multer')({limits: {fileSize: file_max_size}, dest: '/tmp/'});


function handle_err(res, err) {
  logger.warn(err);
  res.status(err.status || 500).render("error", {
    message: err.message || "Oops, something bad happened.",
    error: err
  });
}



router.get('/', (req, res) => {
  route_helper.do_render(res, 'usage-scan');
});

router.get('/file', (req, res) => {
  route_helper.do_render(res, 'usage-scan-file');
});

router.post('/file', upload.single('file'), (req, res) => {
  scanner.scan_file(
    req.file.path,
    route_helper.collect_options(req)
  ).then(
    (result) => {
      logger.info(result);
      res.send(result);
    }, (err) => {
      handle_err(res, err);
    });
});


router.get('/uri', (req, res) => {
  route_helper.do_render(res, 'usage-scan-uri');
});

router.post('/uri', (req, res) => {
  scanner.scan_uri(
    req.body.uri,
    route_helper.collect_options(req)
  ).then(
    (result) => {
      logger.info(result);
      res.send(result);
    }, (err) => {
      return handle_err(res, err);
    });
});


router.get('/text', (req, res) => {
  route_helper.do_render(res, 'usage-scan-text');
});

router.post('/text', (req, res) => {
  scanner.scan_text(
    req.body.text,
    route_helper.collect_options(req)
  ).then(
    (result) => {
      logger.info(result);
      res.send(result);
    }, (err) => {
      return handle_err(res, err);
    });
});

module.exports = router;
<commit_msg>fix: error message if file left empty<commit_after>"use strict";

var extend = require('extend');
var fs = require('fs');

var logger = require('../logger');
var route_helper = require('../helper/route');
var scanner = require('../scanner');

var file_max_size = require('../config').get('FILE:MAX_SIZE');
var router = require('express').Router();
var upload = require('multer')({limits: {fileSize: file_max_size}, dest: '/tmp/'});


function handle_err(res, err) {
  logger.warn(err);
  res.status(err.status || 500).render("error", {
    message: err.message || "Oops, something bad happened.",
    error: err
  });
}



router.get('/', (req, res) => {
  route_helper.do_render(res, 'usage-scan');
});

router.get('/file', (req, res) => {
  route_helper.do_render(res, 'usage-scan-file');
});

router.post('/file', upload.single('file'), (req, res) => {
  scanner.scan_file(
    req.file ? req.file.path : undefined,
    route_helper.collect_options(req)
  ).then(
    (result) => {
      logger.info(result);
      res.send(result);
    }, (err) => {
      handle_err(res, err);
    });
});


router.get('/uri', (req, res) => {
  route_helper.do_render(res, 'usage-scan-uri');
});

router.post('/uri', (req, res) => {
  scanner.scan_uri(
    req.body.uri,
    route_helper.collect_options(req)
  ).then(
    (result) => {
      logger.info(result);
      res.send(result);
    }, (err) => {
      return handle_err(res, err);
    });
});


router.get('/text', (req, res) => {
  route_helper.do_render(res, 'usage-scan-text');
});

router.post('/text', (req, res) => {
  scanner.scan_text(
    req.body.text,
    route_helper.collect_options(req)
  ).then(
    (result) => {
      logger.info(result);
      res.send(result);
    }, (err) => {
      return handle_err(res, err);
    });
});

module.exports = router;

{'fraction_non_alphanumeric': 0.21665274296853243, 'fraction_numerical': 0.001670843776106934, 'mean_word_length': 3.4455445544554455, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 29, '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': '6484011', 'n_tokens_mistral': 1286, 'n_tokens_neox': 1269, 'n_words': 224}