<commit_before>var router = require('express').Router();
var multer = require('multer');
var path = require('path');
const imagemin = require('imagemin');
const imageminJpegtran = require('imagemin-jpegtran');
const imageminPngquant = require('imagemin-pngquant');
const imageminSvgo = require('imagemin-svgo');

var config = require('../config');
var Thing = require('../models/thing');

var uploadPath = path.join(__dirname, '..', 'uploads');

var upload = multer({
  storage: multer.diskStorage({
    destination: uploadPath,
    /**
     * file name: unix time stamp + file extension
     */
    filename: function (req, file, cb) {
      switch (file.mimetype) {
        case 'image/jpeg':
          cb(null, Date.now() + '.jpg');
          break;
        case 'image/png':
          cb(null, Date.now() + '.png');
        case 'image/svg+xml':
          cb(null, Date.now() + '.svg');
      }
    }
  }),
  /**
   * allowed formats: jpeg, png and svg
   */
  fileFilter: function (req, file, cb) {
    const isAllowed = file.mimetype === 'image/jpeg' || file.mimetype === 'image/png' || file.mimetype === 'image/svg+xml';
    cb(null, isAllowed);
  }
});

/* upload files */
router.post('/', upload.single('file'), function (req, res, next) {
  if (req.file) {
    imagemin([req.file.path], uploadPath, {
      plugins: [
        imageminJpegtran(),
        imageminPngquant({quality: '65-80'})
      ]
    }).then(files => true);
    res.send({
      filename: req.file.filename,
      path: '/uploads/' + req.file.filename,
      url: config.url + '/uploads/' + req.file.filename
    });
  } else {
    res.status(400).send({ message: 'invalid file. make sure file format is correct. (.jpg, .png or .svg)' });
  }
});

module.exports = router;<commit_msg>minify svg and wait compression complete<commit_after>var router = require('express').Router();
var multer = require('multer');
var path = require('path');
const imagemin = require('imagemin');
const imageminJpegtran = require('imagemin-jpegtran');
const imageminPngquant = require('imagemin-pngquant');
const imageminSvgo = require('imagemin-svgo');

var config = require('../config');
var Thing = require('../models/thing');

var uploadPath = path.join(__dirname, '..', 'uploads');

var upload = multer({
  storage: multer.diskStorage({
    destination: uploadPath,
    /**
     * file name: unix time stamp + file extension
     */
    filename: function (req, file, cb) {
      switch (file.mimetype) {
        case 'image/jpeg':
          cb(null, Date.now() + '.jpg');
          break;
        case 'image/png':
          cb(null, Date.now() + '.png');
        case 'image/svg+xml':
          cb(null, Date.now() + '.svg');
      }
    }
  }),
  /**
   * allowed formats: jpeg, png and svg
   */
  fileFilter: function (req, file, cb) {
    const isAllowed = file.mimetype === 'image/jpeg' || file.mimetype === 'image/png' || file.mimetype === 'image/svg+xml';
    cb(null, isAllowed);
  }
});

/* upload files */
router.post('/', upload.single('file'), function (req, res, next) {
  if (req.file) {
    imagemin([req.file.path], uploadPath, {
      plugins: [
        imageminJpegtran(),
        imageminPngquant({quality: '65-80'}),
        imageminSvgo()
      ]
    }).then(files => true);
    res.send({
      filename: req.file.filename,
      path: '/uploads/' + req.file.filename,
      url: config.url + '/uploads/' + req.file.filename
    });
  } else {
    res.status(400).send({ message: 'invalid file. make sure file format is correct. (.jpg, .png or .svg)' });
  }
});

module.exports = router;
{'fraction_non_alphanumeric': 0.18255521386636847, 'fraction_numerical': 0.003913894324853229, 'mean_word_length': 2.868108108108108, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 4}, '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': '5477987', 'n_tokens_mistral': 1196, 'n_tokens_neox': 1152, 'n_words': 273}