...
|
...
|
@@ -29,58 +29,63 @@ class FileApi { |
|
|
let fileNameWithoutType = _.split(fileName, '.')[0];
|
|
|
let fileSavePath = path.join(FILE_SAVE_ROOT_PATH, fileName); // 文件保存到服务器的路径
|
|
|
|
|
|
let readable = fs.createReadStream(file.path);
|
|
|
let writable = fs.createWriteStream(fileSavePath);
|
|
|
await new Promise((resolve, reject) => {
|
|
|
let readable = fs.createReadStream(file.path);
|
|
|
let writable = fs.createWriteStream(fileSavePath);
|
|
|
|
|
|
readable.pipe(writable);
|
|
|
|
|
|
readable.on('end', async() => {
|
|
|
ws.broadcast(BROADCAST_PATH, {
|
|
|
state: '压缩包已经上传到服务器,开始解压...'
|
|
|
readable.pipe(writable);
|
|
|
readable.on('end', result => {
|
|
|
resolve(result);
|
|
|
});
|
|
|
});
|
|
|
|
|
|
let fileDistPath = path.join(FILE_SAVE_ROOT_PATH, actPath); // 文件解压的路径
|
|
|
ws.broadcast(BROADCAST_PATH, {
|
|
|
state: '压缩包已经上传到服务器,开始解压...'
|
|
|
});
|
|
|
|
|
|
shelljs.mkdir('-p', fileDistPath);
|
|
|
let fileDistPath = path.join(FILE_SAVE_ROOT_PATH, actPath); // 文件解压的路径
|
|
|
|
|
|
// 解压
|
|
|
await decompress(path.resolve(fileSavePath), path.resolve(fileDistPath), {
|
|
|
plugins: [
|
|
|
decompressUnzip()
|
|
|
]
|
|
|
});
|
|
|
shelljs.mkdir('-p', fileDistPath);
|
|
|
|
|
|
// 解压
|
|
|
await decompress(path.resolve(fileSavePath), path.resolve(fileDistPath), {
|
|
|
plugins: [
|
|
|
decompressUnzip()
|
|
|
]
|
|
|
});
|
|
|
|
|
|
ws.broadcast(BROADCAST_PATH, {
|
|
|
state: '压缩包已经解压成功,开始校验文件...'
|
|
|
});
|
|
|
|
|
|
let fileList = rd.readSync(fileDistPath); // 读取待上传的文件列表
|
|
|
let testRes = this._testFiles(fileList); // 文件校验
|
|
|
|
|
|
if (testRes) {
|
|
|
ws.broadcast(BROADCAST_PATH, {
|
|
|
state: '压缩包已经解压成功,开始校验文件...'
|
|
|
state: '校验文件通过,开始将文件上传到七牛...'
|
|
|
});
|
|
|
|
|
|
let fileList = rd.readSync(fileDistPath); // 读取待上传的文件列表
|
|
|
let testRes = this._testFiles(fileList); // 文件校验
|
|
|
|
|
|
if (testRes) {
|
|
|
ws.broadcast(BROADCAST_PATH, {
|
|
|
state: '校验文件通过,开始将文件上传到七牛...'
|
|
|
});
|
|
|
let fileModel = new FileModel();
|
|
|
let insertRes = await fileModel.insert({ // 上传记录写库
|
|
|
date: moment().format('YYYY-MM-DD HH:mm'),
|
|
|
fileName: fileName,
|
|
|
actPath: actPath,
|
|
|
username: '' // TODO
|
|
|
});
|
|
|
|
|
|
let fileModel = new FileModel();
|
|
|
let insertRes = await fileModel.insert({ // 上传记录写库
|
|
|
date: moment().format('YYYY-MM-DD HH:mm'),
|
|
|
fileName: fileName,
|
|
|
actPath: actPath,
|
|
|
username: '' // TODO
|
|
|
});
|
|
|
await this._uploadToQiniu(fileList, fileDistPath);
|
|
|
|
|
|
await this._uploadToQiniu(fileList, fileDistPath);
|
|
|
ws.broadcast(BROADCAST_PATH, {
|
|
|
state: '文件上传到七牛处理结束!'
|
|
|
});
|
|
|
} else {
|
|
|
ws.broadcast(BROADCAST_PATH, {
|
|
|
state: '校验文件失败,非法上传!'
|
|
|
});
|
|
|
}
|
|
|
|
|
|
ws.broadcast(BROADCAST_PATH, {
|
|
|
state: '文件上传到七牛处理结束!'
|
|
|
});
|
|
|
} else {
|
|
|
ws.broadcast(BROADCAST_PATH, {
|
|
|
state: '校验文件失败,非法上传!'
|
|
|
});
|
|
|
}
|
|
|
});
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
/**
|
...
|
...
|
@@ -100,11 +105,11 @@ class FileApi { |
|
|
qn.uploadFileAsync(filepath, {key:fileKey}).then(result => {
|
|
|
if (result && result.url) {
|
|
|
ws.broadcast(BROADCAST_PATH, {
|
|
|
state: `${filepath} 上传到七牛成功`
|
|
|
state: `${fileKey} 上传到七牛成功`
|
|
|
});
|
|
|
} else {
|
|
|
ws.broadcast(BROADCAST_PATH, {
|
|
|
state: `${filepath} 上传到七牛失败`
|
|
|
state: `${fileKey} 上传到七牛失败`
|
|
|
});
|
|
|
}
|
|
|
resolve(result);
|
...
|
...
|
|