Browse Source

fix: downurl without pathlocal

ryanemax 5 months ago
parent
commit
e0390ccf3d

+ 4 - 2
server/cloud/aliyun/func-aliyun-oss.js

@@ -30,7 +30,9 @@ const ALI_OSS_BUCKET_SECRET = process.env.ALI_OSS_BUCKET || "hep-textbook"
 // AccessKey Secret: KLtQRdIW69KLP7jnzHNUf7eKmdptxH
 
 // 通过STS服务生成临时访问凭证。临时访问凭证包括临时访问密钥(AccessKeyId和AccessKeySecret)和安全令牌(SecurityToken)。
-const { STS,OSS } = require('ali-oss');
+const { STS } = require('ali-oss');
+const OSS = require("ali-oss");
+
 const sts = new STS({
     // 从环境变量中获取访问凭证。运行本代码示例之前,请确保已设置环境变量ALI_OSS_ACCESS_KEY_ID和ALI_OSS_ACCESS_KEY_SECRET。
     accessKeyId: ALI_OSS_ACCESS_KEY_ID,
@@ -44,7 +46,7 @@ const ossClient = new OSS({
     accessKeyId: ALI_OSS_ACCESS_KEY_ID,
     accessKeySecret: ALI_OSS_ACCESS_KEY_SECRET,
     // 填写Bucket名称。
-    bucket: result?.ALI_OSS_BUCKET || "hep-textbook",
+    bucket: ALI_OSS_BUCKET || "hep-textbook",
     timeout:5000*1000
 });
 

+ 9 - 3
server/cloud/tbook/func-tbook-export.js

@@ -350,7 +350,7 @@ function fixVolumeData(json,volumeData,index,totalJson,isChildren){
         if(!volumeData?.authorList?.[index]){
             if(!volumeData?.authorList){
                 // console.log(volumeData)
-                // volumeData.authorList = []
+                volumeData.authorList = []
             }
          volumeData.authorList.push({name:"",unit:"",birth:"",nationality:"",job:"",title:"",mobile:"",email:"",work:""})
         }
@@ -385,7 +385,10 @@ function fixVolumeData(json,volumeData,index,totalJson,isChildren){
     // 成果列表
     // aclist[index] = [json?.achievementOptions?.[index]?.name||" ",json?.achievementOptions?.[index]?.unit||" ",toYearMonth(json?.achievementOptions?.[index]?.date)||" "]
     for (let index = 0; index < 5; index++) { // 补充空值
-        if(!volumeData?.achievementOptions?.[index]){
+        if(!volumeData?.achievementOptions){
+            volumeData.achievementOptions = []
+        }
+            if(!volumeData?.achievementOptions?.[index]){
          volumeData.achievementOptions.push({name:"",unit:"",date:""})
         }
         volumeData.achievementOptions = volumeData?.achievementOptions?.map((item,index)=>{ // 转换格式
@@ -399,8 +402,11 @@ function fixVolumeData(json,volumeData,index,totalJson,isChildren){
     // 历程列表
     // clist[index] = [num,toYearMonth(json?.courses?.[index]?.date)||" ",json?.courses?.[index]?.wordage||" ",json?.courses?.[index]?.num||" ",json?.courses?.[index]?.sumNum||" ",json?.courses?.[index]?.accolade||" "]
     for (let index = 0; index < 5; index++) { // 补充空值
+        if(!volumeData?.courses){
+            volumeData.courses = []
+        }
         if(!volumeData?.courses?.[index]){
-         volumeData.courses.push({date:"",wordage:"",num:"",sumNum:"",accolade:""})
+         volumeData?.courses.push({date:"",wordage:"",num:"",sumNum:"",accolade:""})
         }
     }
     volumeData.courses = volumeData?.courses?.map((item,index)=>{ // 转换格式

+ 3 - 1
server/cloud/tbook/test/test-export.js

@@ -62,7 +62,9 @@ async function main(){
         // console.log(await exportProcessReportDocs(null,["cgTEtIvkK4"]))
         // console.log(await exportProcessReportDocs(null,["KvvN9lWhri"]))
         // console.log(await exportProcessReportDocs(null,["zVVwoy6ETT"],true))
-        console.log(await exportProcessReportDocs(null,["7PAU2PNcoB"],true))
+        // console.log(await exportProcessReportDocs(null,["7PAU2PNcoB"],true))
+        console.log(await exportProcessReportDocs(null,["v8DjfCGfrP"],true))
+        // console.log(await exportProcessReportDocs(null,["7sDvlq2w6Z"],true))
         
         // console.log(await exportProcessReportDocs(null,["Oa1yB6n64u","j4pt2MMTXM","jAMGxwrl1F","BwZpEoOtS8","X10kCktA0r"]))
         // console.log(await exportProcessReportDocs(null,["BwZpEoOtS8","X10kCktA0r"]))

+ 19 - 7
server/lib/docs/index.js

@@ -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);
         }