去除多文件
parent
9accbc79be
commit
7de39e7f11
@ -1,21 +0,0 @@
|
|||||||
const fs = require('fs');
|
|
||||||
module.exports = async function mkdir(filePath) {
|
|
||||||
console.log(filePath);
|
|
||||||
if (await fs.existsSync(filePath)) {
|
|
||||||
console.log('该路径已存在');
|
|
||||||
}else{
|
|
||||||
console.log('该路径不存在');
|
|
||||||
const dirCache={};
|
|
||||||
filePath=filePath.replace(/\\/g,"/");
|
|
||||||
console.log(filePath);
|
|
||||||
const arr=filePath.split('/');
|
|
||||||
let dir=arr[0];
|
|
||||||
for(let i=1;i<arr.length;i++){
|
|
||||||
if(!dirCache[dir]&&!fs.existsSync(dir)){
|
|
||||||
dirCache[dir]=true;
|
|
||||||
await fs.mkdirSync(dir);
|
|
||||||
}
|
|
||||||
dir=dir+'/'+arr[i];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,19 +0,0 @@
|
|||||||
const multer = require('multer');
|
|
||||||
const path = require('path');
|
|
||||||
const fs = require('fs');
|
|
||||||
const UUID = require('uuid');
|
|
||||||
const mkdir = require('../global/mkdir');
|
|
||||||
// 上传文件的位置
|
|
||||||
const uploadPath = default_config.upload_path;
|
|
||||||
( async ()=>{
|
|
||||||
await mkdir(uploadPath);
|
|
||||||
})()
|
|
||||||
console.log(uploadPath);
|
|
||||||
|
|
||||||
const filename = (req, file, cb) => {
|
|
||||||
console.log('filename');
|
|
||||||
const name = UUID.v1();
|
|
||||||
let type = file.originalname.split('.').reverse()[0];
|
|
||||||
type = type ? `.${type}` : '';
|
|
||||||
cb(null, `${name}${type}`);
|
|
||||||
}
|
|
||||||
Loading…
Reference in New Issue