|
@ -5,6 +5,7 @@ const path = require('path') |
|
|
const fs = require('fs'); |
|
|
const fs = require('fs'); |
|
|
const OSS = require('ali-oss'); |
|
|
const OSS = require('ali-oss'); |
|
|
const uuid = require('uuid'); |
|
|
const uuid = require('uuid'); |
|
|
|
|
|
const JSZip = require('jszip'); |
|
|
|
|
|
|
|
|
const UploadPath = { |
|
|
const UploadPath = { |
|
|
project: ['.txt', '.dwg', '.doc', '.docx', '.xls', '.xlsx', ".csv", '.pdf', '.pptx', '.png', '.jpg', '.svg', '.rar', '.zip', '.jpeg', '.mp4'], |
|
|
project: ['.txt', '.dwg', '.doc', '.docx', '.xls', '.xlsx', ".csv", '.pdf', '.pptx', '.png', '.jpg', '.svg', '.rar', '.zip', '.jpeg', '.mp4'], |
|
@ -229,11 +230,70 @@ module.exports = { |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
const getFileBlob = (url) => { |
|
|
|
|
|
return new Promise((resolve, reject) => { |
|
|
|
|
|
let request = new XMLHttpRequest() |
|
|
|
|
|
request.open("GET", url, true) |
|
|
|
|
|
request.responseType = "blob" |
|
|
|
|
|
request.onload = (res) => { |
|
|
|
|
|
if (res.target.status == 200) { |
|
|
|
|
|
resolve(res.target.response) |
|
|
|
|
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
reject(res) |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
request.send() |
|
|
|
|
|
}) |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
const packBulk = async (ctx) => { |
|
|
|
|
|
console.log(11111,); |
|
|
|
|
|
try { |
|
|
|
|
|
const { fileUrl, folderId } = parse(ctx.req) |
|
|
|
|
|
const zip = new JSZip() |
|
|
|
|
|
let result = [] |
|
|
|
|
|
let files = [] |
|
|
|
|
|
console.log(22,fileUrl); |
|
|
|
|
|
fileUrl.map(a => { |
|
|
|
|
|
let url = path.join(__dirname, '../../', './client', a); |
|
|
|
|
|
|
|
|
|
|
|
files.push({ url, name: 111 }) |
|
|
|
|
|
}) |
|
|
|
|
|
for (let i in files) { |
|
|
|
|
|
let promise = getFileBlob(files[i].url).then((res) => { |
|
|
|
|
|
let format = files[i].url.substring(files[i].url.lastIndexOf("."), files[i].url.length) |
|
|
|
|
|
zip.file(files[i].name + format, res, { binary: true }) |
|
|
|
|
|
}) |
|
|
|
|
|
result.push(promise) |
|
|
|
|
|
console.log(77, promise); |
|
|
|
|
|
} |
|
|
|
|
|
console.log(33,); |
|
|
|
|
|
|
|
|
|
|
|
Promise.all(result).then(() => { |
|
|
|
|
|
zip.generateAsync({ type: "blob" }).then((res) => { |
|
|
|
|
|
console.log(55,); |
|
|
|
|
|
|
|
|
|
|
|
saveAs(res, `${111}.zip`) |
|
|
|
|
|
}) |
|
|
|
|
|
}) |
|
|
|
|
|
console.log(44,); |
|
|
|
|
|
|
|
|
|
|
|
ctx.status = 200; |
|
|
|
|
|
ctx.body = {}; |
|
|
|
|
|
} catch (error) { |
|
|
|
|
|
ctx.status = 400; |
|
|
|
|
|
ctx.fs.logger.error(error); |
|
|
|
|
|
ctx.body = { err: 'download error.' }; |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
router.use(download_); |
|
|
router.use(download_); |
|
|
router.post('/_upload/new', upload); |
|
|
router.post('/_upload/new', upload); |
|
|
router.delete('/_upload/cleanup', remove); |
|
|
router.delete('/_upload/cleanup', remove); |
|
|
router.post('/_upload/attachments/ali/:p', uploadAliOSS); |
|
|
router.post('/_upload/attachments/ali/:p', uploadAliOSS); |
|
|
router.get('/_download/attachments/ali', downloadFromAli); |
|
|
router.get('/_download/attachments/ali', downloadFromAli); |
|
|
router.post('/_upload/attachments/:p', upload_); |
|
|
router.post('/_upload/attachments/:p', upload_); |
|
|
|
|
|
router.post('/packBulk/:p', packBulk); |
|
|
} |
|
|
} |
|
|
}; |
|
|
}; |
|
|