<commit_before>const express = require('express'),
      fileRouter = express.Router(),
      formidable = require('formidable'),
      path = require('path'),
      fs = require('fs');

// TODO: Discuss use upload/download on uri
// TODO: Get File by _id
// TODO: Delete File by _id
/*
  To delete a single file, we have to pass two parameters: user._id
  and file._id. We have to create a query string that comes with 
  both parameters. userId and fileId
*/
const routes = function (User) {
  fileRouter.route('/')
    .post((req, res) => {
      let userFile = {
        userId: null,
        fileName: null,
        fileSize: null,
        fileType: null
      };

      let form = new formidable.IncomingForm();
      form.multiples = true;
      form.uploadDir = path.join(__dirname, '../uploads');

      form.on('file', function(field, file) {
        fs.rename(file.path, path.join(form.uploadDir, file.name));
        userFile.fileName = file.name;
        userFile.fileSize = file.size;
        userFile.fileType = file.type;
      });

      // More info: http://stackoverflow.com/questions/30128701/parse-form-value-with-formidable-to-filename
      form.on('field', function(name, field) {
        if (name === 'userId') {
          userFile.userId = field;<commit_msg>Added comments.<commit_after>const express = require('express'),
      fileRouter = express.Router(),
      formidable = require('formidable'),
      path = require('path'),
      fs = require('fs');

// TODO: Discuss use upload/download on uri
// TODO: Get File by _id
// TODO: Delete File by _id
/*
  To delete a single file, we have to pass two parameters: user._id
  and file._id. We have to create a query string that comes with 
  both parameters. userId and fileId
 
  On client:
  // Delete a user
  var url = "http://localhost:8080/api/v1/users";
  var xhr = new XMLHttpRequest();
  xhr.open("DELETE", url+'/12', true);
  xhr.onload = function () {
    var users = JSON.parse(xhr.responseText);
    if (xhr.readyState == 4 && xhr.status == "200") {
      console.table(users);
    } else {
      console.error(users);
    }
  }
  xhr.send(null);
*/
const routes = function (User) {
  fileRouter.route('/')
    .post((req, res) => {
      let userFile = {
        userId: null,
        fileName: null,
        fileSize: null,
        fileType: null
      };

      let form = new formidable.IncomingForm();
      form.multiples = true;
      form.uploadDir = path.join(__dirname, '../uploads');

      form.on('file', function(field, file) {
        fs.rename(file.path, path.join(form.uploadDir, file.name));
        userFile.fileName = file.name;
        userFile.fileSize = file.size;
        userFile.fileType = file.type;
      });

      // More info: http://stackoverflow.com/questions/30128701/parse-form-value-with-formidable-to-filename
      form.on('field', function(name, field) {
        if (name === 'userId') {
          userFile.userId = field;
{'fraction_non_alphanumeric': 0.14121232644768034, 'fraction_numerical': 0.009143244158482899, 'mean_word_length': 2.5334928229665072, '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': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '91803', 'n_tokens_mistral': 927, 'n_tokens_neox': 898, 'n_words': 239}