test-export.js 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  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,["zVVwoy6ETT"],true))
  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. // 单独上传 指定Key
  64. // console.log(await uploadFileToOSS("/home/ryan/Downloads/1727678422495-《物流英语》人员政治审查表.pdf",null,"/dHqLe4hyyU/2024-9-30/1727678422495-《物流英语》人员政治审查表.pdf"))
  65. // 根据export.txt 导出全部
  66. // await exportAllFromTxt()
  67. }catch(err){
  68. console.error(err)
  69. }
  70. }
  71. main()
  72. // mergePdfListReduce([
  73. // path.join("/home/ryan/workspace/nova/edu-textbook/server/cloud/tbook/template/模板-推荐申报表.docx"),
  74. // path.join("/home/ryan/workspace/nova/edu-textbook/server/cloud/tbook/template/模板-推荐申报表.docx")
  75. // ],{
  76. // files: [
  77. // '/home/ryan/workspace/nova/edu-textbook/server/cloud/tbook/test/temp/temp/112_1f15d43c0534288c61089099792e44e7.docx'
  78. // ],
  79. // properties: { pageSize: 'A4', margin: { top: 0, right: 0, bottom: 0, left: 0 } },
  80. // pdfa: false,
  81. // pdfUA: false,
  82. // merge: true
  83. // });
  84. async function exportAllFromTxt(){
  85. let txt = fs.readFileSync(path.join(__dirname,"../","export.txt")).toString();
  86. let list = txt.split("\n");
  87. list = list.filter(item=>{
  88. let tdir = path.join(__dirname,"../export",item);
  89. if(!fs.existsSync(tdir)){return true};
  90. let fileList = fs.readdirSync(tdir);
  91. if(!fileList?.length){
  92. return true;
  93. }
  94. if(fileList?.length&&fileList.join("")?.indexOf("pdf")==-1){
  95. return true
  96. }
  97. return false;
  98. });
  99. // list = list.slice(0,1);
  100. console.log(list?.length)
  101. for (let index = 0; index < list.length; index++) {
  102. let id = list[index];
  103. console.log(index+1,id)
  104. console.log(index+1,id)
  105. console.log(index+1,id)
  106. console.log(index+1,id)
  107. let docDir = path.join(__dirname,"../export",id)
  108. console.log(docDir)
  109. if(!fs.existsSync(docDir)) {fs.mkdirSync(docDir)};
  110. let data = await exportProcessReportDocs(null,[id],true)
  111. // console.log(data)
  112. let docList = data?.docsList || []
  113. // console.log(docList)
  114. for (let index = 0; index < docList.length; index++) {
  115. let doc = docList[index]
  116. let docDir = path.join(__dirname,"../export",doc.objectId);
  117. if(!fs.existsSync(docDir)) {fs.mkdirSync(docDir)};
  118. let urlPdf = doc.urlPdf;
  119. let pdfPath = doc.pdfPath
  120. console.log(doc)
  121. // let targetPath = path.join(docDir,path.basename(pdfPath));
  122. // fs.copyFileSync(pdfPath,targetPath)
  123. // console.log(targetPath)
  124. let filepath = await downloadUrl(urlPdf,{tempDir:docDir,keepFileName:true});
  125. console.log(filepath)
  126. if(!filepath || !fs.existsSync(filepath)){
  127. fs.rmdirSync(docDir,{recursive:true,force:true});
  128. }
  129. }
  130. }
  131. }