<commit_before>/**
 * TestController
 *
 * @description :: Server-side logic for managing tests
 * @help        :: See http://sailsjs.org/#!/documentation/concepts/Controllers
 */

module.exports = {
  index: function (req,res){

    res.writeHead(200, {'content-type': 'text/html'});
    res.end(
    '<form action="https://master.sigma/api/test/upload" enctype="multipart/form-data" method="post">'+
    '<input type="text" name="title"><br>'+
    '<input type="file" name="image" multiple="multiple"><br>'+
    '<input type="submit" value="Upload">'+
    '</form>'
  );
  },

  uploadImage: function  (req, res) {

    req.file('image').upload({
      dirname: './assets/post/images/',
      saveAs: function(_file,cb){
        /* optional. default file name */
        var oNameFile = _file.filename;
        var extFile = oNameFile.substr(oNameFile.lastIndexOf('.'),oNameFile.length);
        var fileName = require('randomstring').generate(7) + extFile;
        cb(null,fileName);
       },
      maxBytes: 15 * 1024 * 1024
    },function whenDone(err, files) {
      if (err)
        return res.serverError(err);

      // If no files were uploaded, respond with an error.
      if (files.length === 0){<commit_msg>Add UploadService for load images in server folder. Delete uid in Article model. Comments in ArticleController.<commit_after>/**
 * TestController
 *
 * @description :: Server-side logic for managing tests
 * @help        :: See http://sailsjs.org/#!/documentation/concepts/Controllers
 */
/*global Test UploadFileService Article*/
module.exports = {


  index: function (req,res){
    res.writeHead(200, {'content-type': 'text/html'});
    res.end(
    '<form action="https://master.sigma/api/test/uploadTest" enctype="multipart/form-data" method="post">'+
    '<input type="text" name="title"><br>'+
    '<input type="file" name="image" multiple="multiple"><br>'+
    '<input type="submit" value="Upload">'+
    '</form>'
  );
  },
  params: function(req,res){
    return res.ok(JSON.stringify(req.allParams()));
  },
  tcreate: function (req,res) {
    var article = {};
    try{
      article = {
        title : require('randomstring').generate(7),
        creator: require('randomstring').generate({
          length: 3,
          charset: 'numeric'
        }),
        url : req.param('url'),
        state : 'disable'
      };
    }catch(err){
      sails.log.warnig(err);
      return res.serverError(err);
    }

    Article.create(article).exec(function (err, record) {
      if(err) {

        sails.log.warnig(err.code,err.details);

        if(err.code === 'E_VALIDATION')
          return res.badRequest({attributes:err.invalidAttributes});

        return res.serverErro(err);
      }
      sails.log.debug('+ Article create : ',record);
    });
  },
  uploadTest: function (req,res){
    var file = UploadFileService.image(req,'image');
    return res.ok(JSON.stringify(file));
  },
  uploadImage: function  (req, res) {
    sails.log.debug('+ Upload image file');
    req.file('image').upload({
      dirname: './assets/post/images/',
      saveAs: function(_file,cb){
        /* optional. default file name */
        var oNameFile = _file.filename;
        var extFile = oNameFile.substr(oNameFile.lastIndexOf('.'),oNameFile.length);
        var fileName = require('randomstring').generate(7) + extFile;
        cb(null,fileName);
      },
      maxBytes: 15 * 1024 * 1024
    },function whenDone(err, files) {
      if (err)
        return res.serverError(err);

      // If no files were uploaded, respond with an error.
      if (files.length === 0){
{'fraction_non_alphanumeric': 0.16773296244784422, 'fraction_numerical': 0.00890125173852573, 'mean_word_length': 2.912948857453754, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 17, 'https://': 2, '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': '5374563', 'n_tokens_mistral': 1139, 'n_tokens_neox': 1104, 'n_words': 234}