test-export.js 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. const Parse = require("parse/node");
  2. Parse.initialize("edu-textbook");
  3. Parse.serverURL = "http://8.140.98.43/parse";
  4. global.Parse = Parse;
  5. import fs from "fs";
  6. import path from "path";
  7. import { downloadUrl, mergePdfListReduce, uploadFileToOSS } from "../../../lib/docs";
  8. /**
  9. *
  10. (npx vite build) -and (node temp/test-export.js)
  11. npx vite build && node temp/test-export.js
  12. npx vite build
  13. node temp/test-export.js
  14. @desc 本地合成测试指令
  15. sudo apt install poppler-utils
  16. libreoffice --headless --convert-to pdf *.jpg
  17. pdfunite 1*.pdf final.pdf
  18. libreoffice 更多用法可以在终端输入 libreoffice --help 或者 man libreoffice 。
  19. */
  20. import { exportProcessReportDocs } from "../func-tbook-export";
  21. async function main(){
  22. try{
  23. console.log("测试合集")
  24. // console.log(await exportProcessReportDocs("FR7KZtefyR"))
  25. // console.log("测试列表")
  26. // console.log(await exportProcessReportDocs(null,["9V575dapEM"]))
  27. // console.log(await exportProcessReportDocs(null,["c2WUE5PgCo"]))
  28. // console.log(await exportProcessReportDocs(null,["R9r0XtMsK3"])) // CIP顺序问题,后两个pdf到了最前面
  29. // console.log(await exportProcessReportDocs(null,["MU5YpUizfW"]))
  30. // console.log(await exportProcessReportDocs(null,["UUGgHPHsIC"]))
  31. // console.log(await exportProcessReportDocs(null,["KxhErArSbB"]))
  32. // console.log(await exportProcessReportDocs(null,["7cf69rSawD"]))
  33. // console.log(await exportProcessReportDocs(null,["kY6MbE1JXC"])) // 21个附件,超时
  34. // console.log(await exportProcessReportDocs(null,["O8kCxqdasp"])) // \u0002 乱码
  35. // console.log(await exportProcessReportDocs(null,["VK81UnQmkn"]))
  36. // console.log(await exportProcessReportDocs(null,["SD0NCAdscz"]))
  37. // console.log(await exportProcessReportDocs(null,["sbVgvo4qEk"]))
  38. // console.log(await exportProcessReportDocs(null,["4LnH46Mu03"]))
  39. // console.log(await exportProcessReportDocs(null,["xdIAG8BYnX"]))
  40. // console.log(await exportProcessReportDocs(null,["NJ2hWa17gi"]))
  41. // console.log(await exportProcessReportDocs(null,["tnEfUnTaQU"])) // C/C++ pathname error
  42. // console.log(await exportProcessReportDocs(null,["2s353GQBjk"]))
  43. // console.log(await exportProcessReportDocs(null,["KvvN9lWhri"]))
  44. // console.log(await exportProcessReportDocs(null,["orBBW42ZCn"])) // rar attach
  45. // console.log(await exportProcessReportDocs(null,["UwPtEptZTR"])) // pdf 七 八 加密
  46. // console.log(await exportProcessReportDocs(null,["TsjBrECA4m"])) // pdf 加密
  47. // console.log(await exportProcessReportDocs(null,["z7yhFusOns"]))
  48. // console.log(await exportProcessReportDocs(null,["ybzJWkXqQG"]))
  49. // console.log(await exportProcessReportDocs(null,["4UAwQ4nc5A"]))
  50. // console.log(await exportProcessReportDocs(null,["ybzJWkXqQG"]))
  51. // console.log(await exportProcessReportDocs(null,["yrmicQ8ZTR"]))
  52. // console.log(await exportProcessReportDocs(null,["pdo6maunud","iWBI0FMTAS","Faw2Hl4qTf","lAG4JpaAIW","1aRyDbVyUu","GVNtZWdm50","5dq8TYCGfu","YkLYd4rv2v","889gBLs62l","fWTphlIAZu","DrHtcRrgXe","n6TxQZ0aOp","oV9W7FbyPj","sY1jZXS5rF","uvmtqWdMlM","rPaRkc0S3I","ikQXhMJPw7","ll0kl2RCBk","QCdJfwlBCh","F7aE1ACEgd","CcMa620Q5J","tk4zR6RbQN","6GLa6Po9p8","TbwoGVrSlR","xNDkRbGDP5","qg1ITwStRR","xHfG3po2yC","Tg7ndNBZvz","Hi1C6G43TM","mwCcj1VDrc"]))
  53. // console.log(await exportProcessReportDocs(null,["nZy0XB9vHw"]))
  54. // console.log(await exportProcessReportDocs(null,["3wJSkW9HNV"]))
  55. // console.log(await exportProcessReportDocs(null,["tHhfIDBkhf"]))
  56. // console.log(await exportProcessReportDocs(null,["cgTEtIvkK4"]))
  57. // console.log(await exportProcessReportDocs(null,["KvvN9lWhri"]))
  58. // console.log(await exportProcessReportDocs(null,["F8eiOAfuC3"]))
  59. // console.log(await exportProcessReportDocs(null,["Oa1yB6n64u","j4pt2MMTXM","jAMGxwrl1F","BwZpEoOtS8","X10kCktA0r"]))
  60. // console.log(await exportProcessReportDocs(null,["BwZpEoOtS8","X10kCktA0r"]))
  61. // 单独上传
  62. console.log(await uploadFileToOSS("/home/ryan/workspace/nova/edu-textbook/server/cloud/tbook/test/export/all/"+"申报书-多位专业代码修复导出.zip"))
  63. // 根据export.txt 导出全部
  64. // await exportAllFromTxt()
  65. }catch(err){
  66. console.error(err)
  67. }
  68. }
  69. main()
  70. // mergePdfListReduce([
  71. // path.join("/home/ryan/workspace/nova/edu-textbook/server/cloud/tbook/template/模板-推荐申报表.docx"),
  72. // path.join("/home/ryan/workspace/nova/edu-textbook/server/cloud/tbook/template/模板-推荐申报表.docx")
  73. // ],{
  74. // files: [
  75. // '/home/ryan/workspace/nova/edu-textbook/server/cloud/tbook/test/temp/temp/112_1f15d43c0534288c61089099792e44e7.docx'
  76. // ],
  77. // properties: { pageSize: 'A4', margin: { top: 0, right: 0, bottom: 0, left: 0 } },
  78. // pdfa: false,
  79. // pdfUA: false,
  80. // merge: true
  81. // });
  82. async function exportAllFromTxt(){
  83. let txt = fs.readFileSync(path.join(__dirname,"../","export.txt")).toString();
  84. let list = txt.split("\n");
  85. list = list.filter(item=>{
  86. let tdir = path.join(__dirname,"../export",item);
  87. if(!fs.existsSync(tdir)){return true};
  88. let fileList = fs.readdirSync(tdir);
  89. if(!fileList?.length){
  90. return true;
  91. }
  92. if(fileList?.length&&fileList.join("")?.indexOf("pdf")==-1){
  93. return true
  94. }
  95. return false;
  96. });
  97. // list = list.slice(0,1);
  98. console.log(list?.length)
  99. for (let index = 0; index < list.length; index++) {
  100. let id = list[index];
  101. console.log(index+1,id)
  102. console.log(index+1,id)
  103. console.log(index+1,id)
  104. console.log(index+1,id)
  105. let docDir = path.join(__dirname,"../export",id)
  106. console.log(docDir)
  107. if(!fs.existsSync(docDir)) {fs.mkdirSync(docDir)};
  108. let data = await exportProcessReportDocs(null,[id],true)
  109. // console.log(data)
  110. let docList = data?.docsList || []
  111. // console.log(docList)
  112. for (let index = 0; index < docList.length; index++) {
  113. let doc = docList[index]
  114. let docDir = path.join(__dirname,"../export",doc.objectId);
  115. if(!fs.existsSync(docDir)) {fs.mkdirSync(docDir)};
  116. let urlPdf = doc.urlPdf;
  117. let pdfPath = doc.pdfPath
  118. console.log(doc)
  119. // let targetPath = path.join(docDir,path.basename(pdfPath));
  120. // fs.copyFileSync(pdfPath,targetPath)
  121. // console.log(targetPath)
  122. let filepath = await downloadUrl(urlPdf,{tempDir:docDir,keepFileName:true});
  123. console.log(filepath)
  124. if(!filepath || !fs.existsSync(filepath)){
  125. fs.rmdirSync(docDir,{recursive:true,force:true});
  126. }
  127. }
  128. }
  129. }