<commit_before>var express = require('express');
var fs = require("fs");
var router = express.Router();
var multer = require('multer');

/*
 * POST helloworld request.
 */
router.post('/sayhello', function(req, res) {
  var obj;
  fs.readFile('./routes/helloworld.json', 'utf8', function (err, data) 
  {
    if (err) throw err;
    
    var jsonContent = JSON.parse(data);
    res.setHeader('Content-Type', 'application/json');
    res.end(JSON.stringify(jsonContent));
  });
});

/*
 * GET helloworld request.
 */
router.get('/sayhello', function(req, res) {
    res.setHeader('Content-Type', 'application/json');
    res.end(JSON.stringify({"response": "Hello World"}));
});


var uploadFile = multer({ dest: './public/'}).single('file')

/*
 * POST request to upload a file
 */
router.post('/upload', function(req, res) {

  try 
  {
    uploadFile(req, res, function (err) {
      if (err) 
      {
        res.setHeader('Content-Type', 'application/json');
        res.end(JSON.stringify({"response": "Error while uploading file - Check if your field name is 'file' "}));
      }
      else
      {
        res.setHeader('Content-Type', 'application/json');
        res.end(JSON.stringify({"response": "All is well"}));
      }
    });
  }
  catch (err)
  {
    res.setHeader('Content-Type', 'application/json');
    res.end(JSON.stringify({"response": "All is well"}));
  }
});

module.exports = router;<commit_msg>added validataion where there is no file in request<commit_after>var express = require('express');
var fs = require("fs");
var router = express.Router();
var multer = require('multer');

/*
 * POST helloworld request.
 */
router.post('/sayhello', function(req, res) {
  var obj;
  fs.readFile('./routes/helloworld.json', 'utf8', function (err, data) 
  {
    if (err) throw err;
    
    var jsonContent = JSON.parse(data);
    res.setHeader('Content-Type', 'application/json');
    res.end(JSON.stringify(jsonContent));
  });
});

/*
 * GET helloworld request.
 */
router.get('/sayhello', function(req, res) {
    res.setHeader('Content-Type', 'application/json');
    res.end(JSON.stringify({"response": "Hello World"}));
});


var uploadFile = multer({ dest: './public/'}).single('file')

/*
 * POST request to upload a file
 */
router.post('/upload', function(req, res) {

  if (!req.files) {
        res.setHeader('Content-Type', 'application/json');
        res.end(JSON.stringify({"response": "File not found in the request"}));
  } 
  try 
  {
    uploadFile(req, res, function (err) {
      if (err) 
      {
        res.setHeader('Content-Type', 'application/json');
        res.end(JSON.stringify({"response": "Error while uploading file - Check if your field name is 'file' "}));
      }
      else
      {
        res.setHeader('Content-Type', 'application/json');
        res.end(JSON.stringify({"response": "All is well"}));
      }
    });
  }
  catch (err)
  {
    res.setHeader('Content-Type', 'application/json');
    res.end(JSON.stringify({"response": "All is well"}));
  }
});

module.exports = router;
{'fraction_non_alphanumeric': 0.18811556139198948, 'fraction_numerical': 0.0006565988181221273, 'mean_word_length': 3.2496513249651326, 'pattern_counts': {'":': 9, '<': 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': '2089785', 'n_tokens_mistral': 988, 'n_tokens_neox': 973, 'n_words': 214}