Преглед на файлове

fix: export func witk fileKey

ryanemax преди 1 месец
родител
ревизия
1378fc8a8b
променени са 2 файла, в които са добавени 7 реда и са изтрити 4 реда
  1. 4 2
      server/cloud/tbook/test/test-export.js
  2. 3 2
      server/lib/docs/index.js

+ 4 - 2
server/cloud/tbook/test/test-export.js

@@ -61,13 +61,15 @@ async function main(){
         // console.log(await exportProcessReportDocs(null,["tHhfIDBkhf"]))
         // console.log(await exportProcessReportDocs(null,["cgTEtIvkK4"]))
         // console.log(await exportProcessReportDocs(null,["KvvN9lWhri"]))
-        // console.log(await exportProcessReportDocs(null,["F8eiOAfuC3"]))
+        // console.log(await exportProcessReportDocs(null,["zVVwoy6ETT"],true))
         
         // console.log(await exportProcessReportDocs(null,["Oa1yB6n64u","j4pt2MMTXM","jAMGxwrl1F","BwZpEoOtS8","X10kCktA0r"]))
         // console.log(await exportProcessReportDocs(null,["BwZpEoOtS8","X10kCktA0r"]))
 
         // 单独上传
-        console.log(await uploadFileToOSS("/home/ryan/workspace/nova/edu-textbook/server/cloud/tbook/test/export/all/"+"申报书-多位专业代码修复导出.zip"))
+        // console.log(await uploadFileToOSS("/home/ryan/workspace/nova/edu-textbook/server/cloud/tbook/test/export/all/"+"申报书-多位专业代码修复导出.zip"))
+        // 单独上传 指定Key
+        // console.log(await uploadFileToOSS("/home/ryan/Downloads/1727678422495-《物流英语》人员政治审查表.pdf",null,"/dHqLe4hyyU/2024-9-30/1727678422495-《物流英语》人员政治审查表.pdf"))
 
         // 根据export.txt 导出全部
         // await exportAllFromTxt()

+ 3 - 2
server/lib/docs/index.js

@@ -47,7 +47,7 @@ export async function toBarCode(text){
     })
 }
 
-export async function uploadFileToOSS(filePath,uniqueId){
+export async function uploadFileToOSS(filePath,uniqueId,fileKey){
     uniqueId = uniqueId || ""
     let client = new OSS({
         // yourRegion填写Bucket所在地域。以华东1(杭州)为例,yourRegion填写为oss-cn-hangzhou。
@@ -61,7 +61,7 @@ export async function uploadFileToOSS(filePath,uniqueId){
 
     let now = new Date();
     let fileName = getFileName(filePath);
-    let fileKey = `export/report/${uniqueId}/${fileName}`;
+    fileKey = fileKey || `export/report/${uniqueId}/${fileName}`;
     const r1 = await client?.put(fileKey, filePath);
     console.log('put success: %j', r1);
     return r1
@@ -128,6 +128,7 @@ module.exports.createZip = createZip
 
 const download = require('download')
 export async function downloadUrl(url,options) {
+    // console.log(url)
     if(!fs.existsSync(options?.tempDir)) fs.mkdirSync(options?.tempDir);
     // console.log(url)
     if(url?.startsWith("/")) {return url};