{"size": 556, "ext": "js", "max_stars_repo_path": "modles/upload.js", "max_stars_repo_name": "ChenArno/app-publish", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "modles/upload.js", "max_issues_repo_name": "ChenArno/app-publish", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "modles/upload.js", "max_forks_repo_name": "ChenArno/app-publish", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 26.4761904762, "max_line_length": 90, "alphanum_fraction": 0.6978417266}
const multer = require('multer');
const md5 = require('md5');
const config = require('../config');

const storage = multer.diskStorage({
  //设置上传文件路径,以后可以扩展成上传至七牛,文件服务器等等
  //Note:如果你传递的是一个函数，你负责创建文件夹，如果你传递的是一个字符串，multer会自动创建
  destination: config.upload.path,
  //TODO:文件区分目录存放
  //获取文件MD5，重命名，添加后缀,文件重复会直接覆盖
  filename(req, file, cb) {
    const fileFormat = file.originalname.split(".");
    cb(null, file.originalname.split('.apk')[0] + '.' + fileFormat[fileFormat.length - 1])
  }
})

const uploader = multer({
  storage
});

module.exports = uploader