<commit_before>var fs = require('fs'),
    jsftp = require("jsftp");

module.exports = {

  upload: function(req, res) {
    function afterCopy(err) {
      if(err) res.status(400).send('bad upload');
      return res.status(200).send('yay!');
    }

    function doCopy(err, data) {
      if(err) return res.status(400).send('bad');
      var ftp = new jsftp({
        host: process.env['STORAGE_HOST'],
        user: process.env['STORAGE_USER'],
        pass: process.env['STORAGE_PASS']
      });
      ftp.put(data, '/media/song.mp3', afterCopy);
    }

    function startCopy(file) {
      fs.readFile(file.fd, doCopy);
    }

    function callback(err, files) {
      if (err)
        return res.serverError(err);

      if(files.length < 1)
        return res.status(400).send('no uploaded track');

      return startCopy(files[0]);
    }

    req.file('file').upload(callback);
  },

  missing: function(req, res) {
    res.status(404).send('not found');
  }
	
};
<commit_msg>changing the upload logic a bit<commit_after>var fs = require('fs'),
    jsftp = require("jsftp");

module.exports = {

  upload: function(req, res) {
    function afterCopy(err) {
      if(err) res.status(400).send('bad upload');
      return res.status(200).send('yay!');
    }

    function doCopy(err, data) {
      if(err) return res.status(400).send('bad');
      var ftp = new jsftp({
        host: process.env['STORAGE_HOST'],
        user: process.env['STORAGE_USER'],
        pass: process.env['STORAGE_PASS']
      });
      ftp.put(data, '/media/song.mp3', afterCopy);
    }

    function startCopy(file) {
      sails.log(file);
      if(!file.fd)
        return res.status(422).send('')
      fs.readFile(file.fd || file.path, doCopy);
    }

    function callback(err, files) {
      if (err)
        return res.serverError(err);

      if(files.length < 1)
        return res.status(400).send('no uploaded track');

      return startCopy(files[0]);
    }

    req.file('file').upload(callback);
  },

  missing: function(req, res) {
    res.status(404).send('not found');
  }
	
};

{'fraction_non_alphanumeric': 0.17042726836293806, 'fraction_numerical': 0.01872299567930869, 'mean_word_length': 2.649737302977233, 'pattern_counts': {'":': 0, '<': 5, '<?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': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6867951', 'n_tokens_mistral': 749, 'n_tokens_neox': 694, 'n_words': 130}