|
@@ -150,17 +150,20 @@ module.exports.createZip = createZip
|
|
|
|
|
|
const download = require('download')
|
|
|
export async function downloadUrl(url,options) {
|
|
|
- // OSS权限校验
|
|
|
- let response = await fetch(url)
|
|
|
- console.log(url)
|
|
|
- if(response?.status==403){
|
|
|
- url = await signatureUrl(url);
|
|
|
- }
|
|
|
+
|
|
|
// console.log(url)
|
|
|
if(!fs.existsSync(options?.tempDir)) fs.mkdirSync(options?.tempDir);
|
|
|
// console.log(url)
|
|
|
+ // 本地文件直接复制
|
|
|
if(url?.startsWith("/")) {return url};
|
|
|
|
|
|
+ // 网络地址:OSS权限校验
|
|
|
+ let response = await fetch(url)
|
|
|
+ console.log(url)
|
|
|
+ if(response?.status==403){
|
|
|
+ url = await signatureUrl(url);
|
|
|
+ }
|
|
|
+
|
|
|
// 保留文件名
|
|
|
let filename = ""
|
|
|
if(options?.keepFileName){
|
|
@@ -204,7 +207,10 @@ export async function downloadUrl(url,options) {
|
|
|
plist.push((async ()=>{
|
|
|
try{
|
|
|
filePath = await downloadUrl(mergeFiles[index],options);
|
|
|
- }catch(err){}
|
|
|
+ // console.log("down",filePath)
|
|
|
+ }catch(err){
|
|
|
+ console.log(err)
|
|
|
+ }
|
|
|
if(filePath){
|
|
|
mergeFileMap[index] = filePath // 按原有顺序整理
|
|
|
// filePathList.push(filePath)
|
|
@@ -215,7 +221,9 @@ export async function downloadUrl(url,options) {
|
|
|
await Promise.all(plist);
|
|
|
merge = true;
|
|
|
}
|
|
|
+ // console.log("mergeFileMap",mergeFileMap)
|
|
|
let filePathList = mergeFiles?.map((item,index)=>mergeFileMap[index]).filter(item=>item)
|
|
|
+ // console.log("filePathList",filePathList)
|
|
|
|
|
|
// console.log("DOWNLOADED:",filePathList)
|
|
|
filePathList = filePathList.map((filepath,index)=>{
|
|
@@ -229,10 +237,13 @@ export async function downloadUrl(url,options) {
|
|
|
let fileName = num + "_" + outmd5 + path.extname(filepath);
|
|
|
|
|
|
let orderPath = path.join(fileDir,fileName)
|
|
|
+ // console.log(orderPath)
|
|
|
fs.cpSync(filepath,orderPath);
|
|
|
fs.readFileSync(filepath);
|
|
|
return orderPath
|
|
|
})
|
|
|
+ console.log(filePathList)
|
|
|
+
|
|
|
try {
|
|
|
|
|
|
let files = []
|
|
@@ -308,6 +319,7 @@ export async function downloadUrl(url,options) {
|
|
|
// console.log(convertOpts)
|
|
|
// pdfBuffer = await LibreOffice.convert(convertOpts);
|
|
|
}else{
|
|
|
+ console.log(convertOpts)
|
|
|
pdfBuffer = await LibreOffice.convert(convertOpts);
|
|
|
}
|
|
|
|