main.js 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623
  1. import {app, BrowserWindow, ipcMain, dialog} from 'electron';
  2. import {exec, spawn} from 'child_process';
  3. import path from 'path';
  4. import {fileURLToPath} from 'url';
  5. import fs from 'fs';
  6. import axios from 'axios';
  7. import ProcessManager from './processManager.js'
  8. const processManager = new ProcessManager(); // 创建进程管理器实例
  9. const __filename = fileURLToPath(import.meta.url);
  10. const __dirname = path.dirname(__filename);
  11. function createWindow() {
  12. const win = new BrowserWindow({
  13. width: 800,
  14. height: 600,
  15. webPreferences: {
  16. preload: path.join(__dirname, 'preload.js'), // 确保路径正确
  17. contextIsolation: true,
  18. enableRemoteModule: false,
  19. nodeIntegration: false,
  20. }
  21. });
  22. win.webContents.openDevTools(); // 打开开发者工具进行调试
  23. win.loadURL('http://localhost:5173'); // 开发环境
  24. // win.loadURL('http://36.110.106.156:81'); // 生产环境
  25. console.log('Window created and URL loaded');
  26. }
  27. app.whenReady().then(createWindow);
  28. app.on('window-all-closed', () => {
  29. if (process.platform !== 'darwin') {
  30. app.quit();
  31. }
  32. });
  33. app.on('activate', () => {
  34. if (BrowserWindow.getAllWindows().length === 0) {
  35. createWindow();
  36. }
  37. });
  38. // ------------- 进程通信 -------------
  39. ipcMain.handle('dialog:open', async (event, options = {}) => {
  40. const result = await dialog.showOpenDialog(BrowserWindow.getFocusedWindow() || BrowserWindow.getAllWindows()[0], options);
  41. return result.canceled ? null : result.filePaths;
  42. });
  43. // 下载文件
  44. ipcMain.handle('download-file', async (event, { url, fileName, savePath, overwriteFlag, dialogFlag, requestType, data }) => {
  45. try {
  46. let filePath
  47. let getPath
  48. // console.log("url", url)
  49. // console.log("response", response)
  50. if (dialogFlag) { // 弹出保存文件对话框
  51. console.log("savePath", savePath)
  52. // 获取保存路径
  53. getPath = await dialog.showSaveDialog({
  54. defaultPath: path.join(app.getPath('downloads'), fileName)
  55. })
  56. filePath = getPath.filePath
  57. if (getPath.canceled || filePath === "") {
  58. return { success: false, message: 'File path does not exist' }
  59. }
  60. } else {
  61. filePath = path.join(savePath, fileName);
  62. }
  63. console.log("filePath", filePath)
  64. // 查找文件是否存在
  65. const fileExists = fs.existsSync(filePath)
  66. if (fileExists && !overwriteFlag) { // 已存在且不覆盖
  67. return {success: true, filePath}
  68. } else { // 不存在
  69. console.log("url", url)
  70. let response
  71. if (requestType === "get") {
  72. console.log("get...")
  73. response = await axios.get(url, {responseType: 'stream'});
  74. } else {
  75. response = await axios.post(url, data, {responseType: 'stream'});
  76. }
  77. console.log("response", response)
  78. // 写入文件
  79. const writer = fs.createWriteStream(filePath);
  80. return new Promise((resolve, reject) => {
  81. response.data.pipe(writer);
  82. let error = null;
  83. writer.on('error', err => {
  84. error = err;
  85. writer.close();
  86. reject(err);
  87. });
  88. writer.on('close', () => {
  89. if (!error) {
  90. resolve({success: true, filePath}); // 返回成功信息
  91. } else {
  92. reject({success: false, error: error.message}); // 返回错误信息
  93. }
  94. });
  95. });
  96. }
  97. } catch (error) {
  98. console.error('下载文件出错:', error);
  99. throw error;
  100. }
  101. });
  102. // 删除文件
  103. ipcMain.on('delete-file', (event, {fileName, savePath}) => {
  104. const filePath = path.join(savePath, fileName);
  105. // 检查文件是否存在
  106. if (fs.existsSync(filePath)) {
  107. // 文件存在,尝试删除
  108. fs.unlink(filePath, (err) => {
  109. if (err) {
  110. event.reply('delete-file-response', { success: false, message: err.message });
  111. } else {
  112. event.reply('delete-file-response', { success: true, message: 'File deleted successfully' });
  113. }
  114. });
  115. } else {
  116. // 文件不存在
  117. event.reply('delete-file-response', { success: false, message: 'File does not exist' });
  118. }
  119. });
  120. // 上传文件
  121. ipcMain.on('upload-file', async (event, {filePath, uploadUrl}) => {
  122. if (!fs.existsSync(filePath)) {
  123. console.log("File does not exist");
  124. event.reply('upload-file-response', {success: false, message: 'File does not exist'});
  125. return;
  126. }
  127. try {
  128. const result = await uploadFile(filePath, uploadUrl);
  129. console.log("result", result);
  130. if (result.status) {
  131. event.reply('upload-file-response', { success: true, message: 'File uploaded successfully', details: result.details });
  132. } else {
  133. event.reply('upload-file-response', { success: false, message: 'Error uploading file', details: '' });
  134. }
  135. } catch (err) {
  136. event.reply('upload-file-response', { success: false, message: err.message, details: '' });
  137. }
  138. });
  139. async function uploadFile(filePath, uploadUrl) {
  140. const data = fs.readFileSync(filePath)
  141. // 创建formData对象
  142. const formData = new FormData();
  143. formData.append('file', new Blob([data]), path.basename(filePath));
  144. try {
  145. // 使用axios上传文件
  146. const response = await axios.post(uploadUrl, formData, {
  147. headers: {
  148. 'Content-Type': 'multipart/form-data'
  149. }
  150. })
  151. // console.log('response', response.data)
  152. return response.data
  153. } catch (err) {
  154. console.log("Error uploading file:", err);
  155. return { status: false, code: '', message: '上传件失败', details: '' };
  156. }
  157. }
  158. async function uploadFileWithRetry(filePath, uploadUrl, maxRetries = 3) {
  159. let attempt = 1;
  160. while (attempt <= maxRetries) {
  161. console.log("Uploading file - attempt:", attempt);
  162. try {
  163. const response = await uploadFile(filePath, uploadUrl);
  164. console.log("response", response);
  165. if (response.status) { // 上传成功
  166. return response;
  167. } else { // 上传失败
  168. console.log("Fail to upload file - attempt:", attempt);
  169. attempt++
  170. }
  171. } catch (error) {
  172. console.log("Error uploading file - attempt:", attempt);
  173. console.log("Error:", error);
  174. attempt++
  175. }
  176. }
  177. return { status: false, code: '', message: '上传文件失败', details: '' };
  178. }
  179. // 导入算法镜像
  180. ipcMain.on('docker-import', (event, filePath, tag) => {
  181. const command = 'bash /home/cicv/work/pji_desktop/docker_import/run_docker_import.sh ' + filePath + ' pji_nav ' + tag
  182. console.log('Docker import command:', command);
  183. exec(command, (error, stdout, stderr) => {
  184. if (error) {
  185. console.error(`exec error: ${error}`);
  186. event.reply('docker-import-response', { success: false, message: error.message });
  187. return;
  188. } else {
  189. console.log(`stdout: ${stdout}`);
  190. console.error(`stderr: ${stderr}`);
  191. event.reply('docker-import-response', { success: true, message: 'Docker image imported successfully' });
  192. }
  193. });
  194. });
  195. // 更新地图
  196. ipcMain.on('update-map', (event, {container_name, file_path}) => {
  197. const command = 'bash /home/cicv/work/pji_desktop/map_update/run_map_update.sh ' + container_name + ' ' + file_path;
  198. console.log('command:', command);
  199. processManager.startProcess('update-map', command, (error, stdout, stderr) => {
  200. if (error) {
  201. console.error(`exec error: ${error}`);
  202. // event.reply('update-map-response', { success: false, message: error.message });
  203. } else {
  204. console.log(`stdout: ${stdout}`);
  205. console.error(`stderr: ${stderr}`);
  206. if (stdout.toString().includes('Result JSON file created')) { // 判断结束标志
  207. event.reply('update-map-response', { success: true, message: 'Update map successfully' });
  208. } else {
  209. event.reply('update-map-response', { success: false, message: 'Error updating map' });
  210. }
  211. }
  212. });
  213. });
  214. // 生成world
  215. ipcMain.on('generate-world', (event, {rosbag_path}) => {
  216. const command = 'bash /home/cicv/work/pji_desktop/simulation/generate_world.sh ' + rosbag_path
  217. console.log('World generation command:', command);
  218. exec(command, (error, stdout, stderr) => {
  219. if (error) {
  220. console.error(`exec error: ${error}`);
  221. event.reply('generate-world-response', { success: false, message: error.message });
  222. } else {
  223. console.log(`stdout: ${stdout}`);
  224. console.error(`stderr: ${stderr}`);
  225. event.reply('generate-world-response', { success: true, message: 'World generated successfully' });
  226. }
  227. });
  228. });
  229. // 启动仿真环境
  230. ipcMain.on('start-container', (event, {zip_file_path, image_name, container_name}) => {
  231. // 使用 spawn 启动脚本
  232. const serviceProcess = spawn('bash', ["/home/cicv/work/pji_desktop/simulation/data_preparation.sh", zip_file_path], { detached: true });
  233. // 设置为后台进程
  234. serviceProcess.unref();
  235. // 监听输出
  236. serviceProcess.stdout.on('data', (data) => {
  237. console.log(`第一个脚本的输出: ${data}`);
  238. // 根据第一个脚本的输出判断其是否准备好
  239. if (data.toString().includes('Data preparation done')) {
  240. startSecondScript();
  241. }
  242. });
  243. // 监听错误
  244. serviceProcess.stderr.on('data', (data) => {
  245. console.error(`执行第一个脚本时出错: ${data}`);
  246. });
  247. // 监听关闭
  248. serviceProcess.on('close', (data) => {
  249. console.log(`第一个脚本已关闭: ${data}`);
  250. });
  251. function startSecondScript() {
  252. let command = "bash /home/cicv/work/pji_desktop/simulation/start_container.sh " + image_name + " " + container_name
  253. // 启动第二个脚本
  254. const script2 = exec(command, (error, stdout, stderr) => {
  255. if (error) {
  256. console.error(`执行第二个脚本时出错: ${error}`);
  257. event.sender.send('start-container-response', { success: false, output: error });
  258. return;
  259. }
  260. console.log(`第二个脚本的输出: ${stdout}`);
  261. event.sender.send('start-container-response', { success: true, output: stdout });
  262. });
  263. script2.on('exit', (code) => {
  264. console.log(`第二个脚本已退出,退出码: ${code}`);
  265. });
  266. }
  267. });
  268. // 执行仿真
  269. ipcMain.on('run-simulation', (event, {random_flag, count, obstacle_flag, default_start_flag, default_end_flag, start_point, end_point}) => {
  270. const command = 'bash /home/cicv/work/pji_desktop/simulation/run_simulation.sh ' + random_flag + ' ' + count + ' ' + obstacle_flag + ' ' +
  271. default_start_flag + ' ' + default_end_flag + ' ' + start_point + ' ' + end_point;
  272. console.log('command:', command);
  273. // exec(command, (error, stdout, stderr) => {
  274. // if (error) {
  275. // console.error(`exec error: ${error}`);
  276. // event.reply('run-simulation-response', { success: false, message: error.message });
  277. // } else {
  278. // console.log(`stdout: ${stdout}`);
  279. // console.error(`stderr: ${stderr}`);
  280. // if (stdout.toString().includes('Evaluation finished')) { // 判断结束标志
  281. // event.reply('run-simulation-response', { success: true, message: 'Run simulation successfully' });
  282. // } else {
  283. // event.reply('run-simulation-response', { success: false, message: 'Error running simulation' });
  284. // }
  285. // }
  286. // });
  287. processManager.startProcess('run-simulation', command, (error, stdout, stderr) => {
  288. if (error) {
  289. console.error(`exec error: ${error}`);
  290. event.reply('run-simulation-response', { success: false, message: error.message });
  291. } else {
  292. console.log(`stdout: ${stdout}`);
  293. console.error(`stderr: ${stderr}`);
  294. if (stdout.toString().includes('Evaluation finished')) { // 判断结束标志
  295. event.reply('run-simulation-response', { success: true, message: 'Run simulation successfully' });
  296. } else {
  297. event.reply('run-simulation-response', { success: false, message: 'Error running simulation' });
  298. }
  299. }
  300. });
  301. // 设置超时机制(
  302. setTimeout(() => {
  303. processManager.killProcess('run-simulation');
  304. event.reply('run-simulation-response', { success: false, message: 'Script running timeout' });
  305. }, 3*60*1000); // 3 分钟
  306. });
  307. // 读取并上传算法评价结果
  308. ipcMain.handle('process-evaluation-files', async (event, {N, equipmentNo, sceneNo}) => {
  309. const result = []
  310. const evalDir = "/home/cicv/work/pji_desktop/simulation/data/evaluation";
  311. const bagDir = "/home/cicv/work/pji_desktop/simulation/data/record_bag";
  312. console.log('N', N)
  313. // 记录时间戳
  314. const timeStamp = Date.now()
  315. console.log("timeStamp", timeStamp);
  316. // 遍历评价结果文件夹,读取并上传相关数据
  317. for (let i = 1; i <= N; i++) {
  318. const subDir = path.join(evalDir, `${i}/result`);
  319. console.log("subDir", subDir);
  320. // 文件路径 - report.json
  321. const jsonFilePath = path.join(subDir, "report.json");
  322. console.log("jsonFilePath", jsonFilePath);
  323. // 文件路径 - report.pdf
  324. const pdfFilePath = path.join(subDir, "report.pdf");
  325. console.log("pdfFilePath", pdfFilePath);
  326. // 文件路径 - test-${i}.bag
  327. const bagFilePath = path.join(bagDir, `test-${i}.bag`);
  328. console.log("bagFilePath", bagFilePath);
  329. const uploadPdfUrl = "http://127.0.0.1:8888/simulation/upload/pdf?equipmentNo=" + equipmentNo + "&sceneNo=" + sceneNo +
  330. "&timeStamp=" + timeStamp + "&round=" + i;
  331. const uploadBagUrl = "http://127.0.0.1:8888/simulation/upload/bag?equipmentNo=" + equipmentNo + "&sceneNo=" + sceneNo +
  332. "&timeStamp=" + timeStamp + "&round=" + i;
  333. try {
  334. // 读取json文件
  335. const jsonData = fs.readFileSync(jsonFilePath, "utf-8");
  336. const parsedData = JSON.parse(jsonData);
  337. console.log("parsedData", parsedData);
  338. // 上传pdf文件
  339. // 查找pdf文件是否存在
  340. let pdfFileExists = fs.existsSync(pdfFilePath)
  341. // pdf文件不存在
  342. if (!pdfFileExists) break
  343. // pdf文件存在
  344. const uploadPdfResult = await uploadFileWithRetry(pdfFilePath, uploadPdfUrl);
  345. console.log("uploadPdfResult", uploadPdfResult);
  346. if (!uploadPdfResult.status) {
  347. break
  348. }
  349. // 上传bag文件
  350. // 查找bag文件是否存在
  351. let bagFileExists = fs.existsSync(bagFilePath)
  352. // bag文件不存在
  353. if (!bagFileExists) break
  354. // bag文件存在
  355. const uploadBagResult = await uploadFile(bagFilePath, uploadBagUrl);
  356. console.log("uploadBagResult", uploadBagResult);
  357. if (!uploadBagResult.status) { break}
  358. // 整合结果
  359. result.push({
  360. "round": i,
  361. "jsonData": parsedData,
  362. "uploadPdfKey": uploadPdfResult.details,
  363. "uploadBagKey": uploadBagResult.details,
  364. "timeStamp": timeStamp
  365. })
  366. } catch (error) {
  367. console.log("error", error);
  368. return { success: false, message: "Error uploading evaluation results", data: [] }
  369. }
  370. }
  371. // 判断数据上传是否完整
  372. if (result.length === N) {
  373. return { success: true, message: "Evaluation results uploaded successfully", data: result }
  374. } else {
  375. return { success: false, message: "Error uploading evaluation results", data: [] }
  376. }
  377. })
  378. async function uploadMapResult(filePath, uploadUrl) {
  379. // 查找文件是否存在
  380. let fileExists = fs.existsSync(filePath)
  381. let uploadResult = await uploadFileWithRetry(filePath, uploadUrl);
  382. if (!fileExists) return { success: false, message: "Error uploading map results", data: [] }
  383. // console.log("uploadResult", uploadResult);
  384. if (!uploadResult.status) {
  385. return { success: false, message: "Error uploading map results", data: [] }
  386. }
  387. return { success: true, message: "", data: uploadResult }
  388. }
  389. // 读取并上传地图更新结果
  390. ipcMain.handle('process-map-update-files', async (event, {equipmentNo, timeStamp}) => {
  391. let result = {}
  392. equipmentNo = "pji-test"
  393. timeStamp = Date.now()
  394. // 记录时间戳
  395. console.log("timeStamp", timeStamp);
  396. const dataDir = "/home/cicv/work/pji_desktop/map_update/data";
  397. const mapBufDir = "/home/cicv/work/pji_desktop/map_update/data/bag_folder/mapBuf";
  398. const resultDir = "/home/cicv/work/pji_desktop/map_update/data/bag_folder/result";
  399. const updateMapDir = "/home/cicv/work/pji_desktop/map_update/data/bag_folder/update_map";
  400. // 读取result*.json
  401. // 文件路径 - result*.json
  402. const jsonPrefix = "result";
  403. let files = fs.readdirSync(resultDir);
  404. let matchedFile = files.find(file => file.startsWith(jsonPrefix))
  405. let jsonFilePath = ""
  406. if (matchedFile) {
  407. // 如果找到匹配的文件
  408. jsonFilePath = path.join(resultDir, matchedFile);
  409. }
  410. console.log("jsonFilePath", jsonFilePath);
  411. // 文件路径 - 更新前pgm
  412. const prePgmPath = path.join(mapBufDir, "map.pgm");
  413. console.log("prePgmPath", prePgmPath);
  414. // 文件路径 - 更新后pgm
  415. const pgmSuffix = ".pgm";
  416. files = fs.readdirSync(updateMapDir);
  417. matchedFile = files.find(file => file.endsWith(pgmSuffix))
  418. let updatePgmPath = ""
  419. if (matchedFile) {
  420. // 如果找到匹配的文件
  421. updatePgmPath = path.join(updateMapDir, matchedFile);
  422. }
  423. console.log("updatePgmPath", updatePgmPath);
  424. // 文件路径 - 更新前png
  425. const prePngPath = path.join(mapBufDir, "map_pre.png");
  426. console.log("prePngPath", prePngPath);
  427. // 文件路径 - 更新后png
  428. const updatePngPath = path.join(mapBufDir, "map_update.png");
  429. console.log("updatePngPath", updatePngPath);
  430. // 文件路径 - 更新地图压缩包
  431. const updateMapPath = path.join(dataDir, "update.zip");
  432. console.log("updateMapPath", updateMapPath);
  433. try {
  434. // 读取json文件
  435. const jsonData = fs.readFileSync(jsonFilePath, "utf-8");
  436. const parsedData = JSON.parse(jsonData);
  437. console.log("parsedData", parsedData);
  438. const mapId = parsedData["origin_pgm_id"];
  439. // 上传 更新前pgm
  440. let uploadUrl = "http://127.0.0.1:8888/map/upload/map?equipmentNo=" + equipmentNo + "&mapId=" + mapId +
  441. "&timeStamp=" + timeStamp ;
  442. // 上传文件
  443. // 上传 更新前pgm
  444. let res = await uploadMapResult(prePgmPath, uploadUrl);
  445. if (!res.success) {
  446. return { success: false, message: "Error uploading map results", data: [] }
  447. }
  448. let prePgmUrl = res.data.details
  449. console.log("prePgmUrl", prePgmUrl);
  450. // 上传 更新前png
  451. res = await uploadMapResult(prePngPath, uploadUrl);
  452. if (!res.success) {
  453. return { success: false, message: "Error uploading map results", data: [] }
  454. }
  455. let prePngUrl = res.data.details
  456. console.log("prePngUrl", prePngUrl);
  457. // 上传 更新后pgm
  458. res = await uploadMapResult(updatePgmPath, uploadUrl);
  459. if (!res.success) {
  460. return { success: false, message: "Error uploading map results", data: [] }
  461. }
  462. let updatePgmUrl = res.data.details
  463. console.log("updatePgmUrl", updatePgmUrl);
  464. // 上传 更新后png
  465. res = await uploadMapResult(updatePngPath, uploadUrl);
  466. if (!res.success) {
  467. return { success: false, message: "Error uploading map results", data: [] }
  468. }
  469. let updatePngUrl = res.data.details
  470. console.log("updatePngUrl", updatePngUrl);
  471. // 上传 更新地图压缩包
  472. res = await uploadMapResult(updateMapPath, uploadUrl);
  473. if (!res.success) {
  474. return { success: false, message: "Error uploading map results", data: [] }
  475. }
  476. let updateMapUrl = res.data.details
  477. console.log("updateMapUrl", updateMapUrl);
  478. result = {
  479. "jsonData": parsedData,
  480. "prePgmUrl": prePgmUrl,
  481. "prePngUrl": prePngUrl,
  482. "updatePgmUrl": updatePgmUrl,
  483. "updatePngUrl": updatePngUrl,
  484. "updateMapUrl": updateMapUrl,
  485. }
  486. return { success: true, message: "Evaluation results uploaded successfully", data: result }
  487. } catch (error) {
  488. console.log("error", error);
  489. }
  490. // // 遍历评价结果文件夹,读取并上传相关数据
  491. // for (let i = 1; i <= N; i++) {
  492. // const subDir = path.join(evalDir, `${i}/result`);
  493. // console.log("subDir", subDir);
  494. // // 文件路径 - report.json
  495. // const jsonFilePath = path.join(subDir, "report.json");
  496. // console.log("jsonFilePath", jsonFilePath);
  497. // // 文件路径 - report.pdf
  498. // const pdfFilePath = path.join(subDir, "report.pdf");
  499. // console.log("pdfFilePath", pdfFilePath);
  500. // // 文件路径 - test-${i}.bag
  501. // const bagFilePath = path.join(bagDir, `test-${i}.bag`);
  502. // console.log("bagFilePath", bagFilePath);
  503. //
  504. // const uploadPdfUrl = "http://127.0.0.1:8888/simulation/upload/pdf?equipmentNo=" + equipmentNo + "&sceneNo=" + sceneNo +
  505. // "&timeStamp=" + timeStamp + "&round=" + i;
  506. //
  507. // const uploadBagUrl = "http://127.0.0.1:8888/simulation/upload/bag?equipmentNo=" + equipmentNo + "&sceneNo=" + sceneNo +
  508. // "&timeStamp=" + timeStamp + "&round=" + i;
  509. //
  510. // try {
  511. // // 读取json文件
  512. // const jsonData = fs.readFileSync(jsonFilePath, "utf-8");
  513. // const parsedData = JSON.parse(jsonData);
  514. // console.log("parsedData", parsedData);
  515. // // 上传pdf文件
  516. // // 查找pdf文件是否存在
  517. // let pdfFileExists = fs.existsSync(pdfFilePath)
  518. // // pdf文件不存在
  519. // if (!pdfFileExists) break
  520. // // pdf文件存在
  521. // const uploadPdfResult = await uploadFileWithRetry(pdfFilePath, uploadPdfUrl);
  522. // console.log("uploadPdfResult", uploadPdfResult);
  523. // if (!uploadPdfResult.status) {
  524. // break
  525. // }
  526. //
  527. // // 上传bag文件
  528. // // 查找bag文件是否存在
  529. // let bagFileExists = fs.existsSync(bagFilePath)
  530. // // bag文件不存在
  531. // if (!bagFileExists) break
  532. // // bag文件存在
  533. // const uploadBagResult = await uploadFile(bagFilePath, uploadBagUrl);
  534. // console.log("uploadBagResult", uploadBagResult);
  535. // if (!uploadBagResult.status) { break}
  536. // // 整合结果
  537. // result.push({
  538. // "round": i,
  539. // "jsonData": parsedData,
  540. // "uploadPdfKey": uploadPdfResult.details,
  541. // "uploadBagKey": uploadBagResult.details,
  542. // "timeStamp": timeStamp
  543. // })
  544. // } catch (error) {
  545. // console.log("error", error);
  546. // return { success: false, message: "Error uploading evaluation results", data: [] }
  547. // }
  548. // }
  549. // // 判断数据上传是否完整
  550. // if (result.length === N) {
  551. // return { success: true, message: "Evaluation results uploaded successfully", data: result }
  552. // } else {
  553. // return { success: false, message: "Error uploading evaluation results", data: [] }
  554. // }
  555. })