iqc下载文件
continuous-integration/drone/push Build is passing
Details
continuous-integration/drone/push Build is passing
Details
parent
8ad50b5618
commit
b866ffdd49
|
@ -40,3 +40,11 @@ export function deleteTaskStudy(params) {
|
||||||
params
|
params
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
// 获取iqc下载文件信息
|
||||||
|
export function getCRCUploadedStudyInfo(data) {
|
||||||
|
return request({
|
||||||
|
url: '/DownloadAndUpload/getCRCUploadedStudyInfo',
|
||||||
|
method: 'post',
|
||||||
|
data
|
||||||
|
})
|
||||||
|
}
|
|
@ -0,0 +1,48 @@
|
||||||
|
import streamSaver from "streamsaver";
|
||||||
|
import "streamsaver/examples/zip-stream.js";
|
||||||
|
|
||||||
|
// 下载文件并压缩
|
||||||
|
function zipFiles(zipName, files) {
|
||||||
|
console.log("同步下载打包开始时间:" + new Date());
|
||||||
|
// 创建压缩文件输出流
|
||||||
|
const zipFileOutputStream = streamSaver.createWriteStream(zipName);
|
||||||
|
// 创建下载文件流
|
||||||
|
const fileIterator = files.values();
|
||||||
|
const readableZipStream = new ZIP({
|
||||||
|
async pull(ctrl) {
|
||||||
|
const fileInfo = fileIterator.next();
|
||||||
|
if (fileInfo.done) {//迭代终止
|
||||||
|
ctrl.close();
|
||||||
|
} else {
|
||||||
|
const { name, url } = fileInfo.value;
|
||||||
|
return fetch(url).then(res => {
|
||||||
|
ctrl.enqueue({
|
||||||
|
name,
|
||||||
|
stream: () => res.body
|
||||||
|
});
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
if (window.WritableStream && readableZipStream.pipeTo) {
|
||||||
|
// 开始下载
|
||||||
|
readableZipStream
|
||||||
|
.pipeTo(zipFileOutputStream)
|
||||||
|
.then(() => console.log("同步下载打包结束时间:" + new Date()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// 下载文件并修改名称
|
||||||
|
async function updateFile(file, name) {
|
||||||
|
try {
|
||||||
|
const fileOutputStream = streamSaver.createWriteStream(name);
|
||||||
|
let res = await fetch(file);
|
||||||
|
res.body.pipeTo(fileOutputStream);
|
||||||
|
} catch (err) {
|
||||||
|
console.log(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
export function downLoadFile(file, name, type = 'file') {
|
||||||
|
if (type === 'zip') return zipFiles(name, file);
|
||||||
|
return updateFile(file, name)
|
||||||
|
|
||||||
|
}
|
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue