|
@@ -6,6 +6,7 @@ import fs from 'fs';
|
|
|
import axios from 'axios';
|
|
|
import {resolve} from "node:dns";
|
|
|
import {execSync} from "node:child_process";
|
|
|
+import * as url from "node:url";
|
|
|
|
|
|
|
|
|
const __filename = fileURLToPath(import.meta.url);
|
|
@@ -124,7 +125,7 @@ ipcMain.handle('dialog:open', async (event, options = {}) => {
|
|
|
|
|
|
ipcMain.on('docker-import', (event, filePath, tag) => {
|
|
|
const command = 'bash /home/cicv/work/pji_desktop/docker_import/run_docker_import.sh ' + filePath + ' pji_nav ' + tag
|
|
|
- console.log('导入算法镜像文件:', command);
|
|
|
+ console.log('Docker import command:', command);
|
|
|
exec(command, (error, stdout, stderr) => {
|
|
|
if (error) {
|
|
|
console.error(`exec error: ${error}`);
|
|
@@ -261,7 +262,7 @@ ipcMain.handle('download-file', async (event, { url, fileName, savePath, overwri
|
|
|
});
|
|
|
|
|
|
|
|
|
-// 监听从渲染进程传来的删除文件请求
|
|
|
+// 删除文件
|
|
|
ipcMain.on('delete-file', (event, {fileName, savePath}) => {
|
|
|
const filePath = path.join(savePath, fileName);
|
|
|
// 检查文件是否存在
|
|
@@ -280,4 +281,37 @@ ipcMain.on('delete-file', (event, {fileName, savePath}) => {
|
|
|
}
|
|
|
});
|
|
|
|
|
|
+// 上传文件
|
|
|
+ipcMain.on('upload-file', (event, {filePath, uploadUrl}) => {
|
|
|
+ if (!fs.existsSync(filePath)) {
|
|
|
+ console.log("File does not exist");
|
|
|
+ event.reply('upload-file-response', { success: false, message: 'File does not exist' });
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ // 读取文件
|
|
|
+ fs.readFile(filePath, async (err, data) => {
|
|
|
+ if(err) {
|
|
|
+ console.log("Error reading file:", err);
|
|
|
+ event.reply('upload-file-response', { success: false, message: err.message });
|
|
|
+ return;
|
|
|
+ }
|
|
|
|
|
|
+ // 创建formData对象
|
|
|
+ const formData = new FormData();
|
|
|
+ formData.append('file', new Blob([data]), path.basename(filePath));
|
|
|
+
|
|
|
+ try {
|
|
|
+ // 使用axios上传文件
|
|
|
+ const response = await axios.post(uploadUrl, formData, {
|
|
|
+ headers: {
|
|
|
+ 'Content-Type': 'multipart/form-data'
|
|
|
+ }
|
|
|
+ })
|
|
|
+ console.log('response', response)
|
|
|
+ event.reply('upload-file-response', { success: true, message: 'File uploaded successfully' });
|
|
|
+ } catch (err) {
|
|
|
+ console.log("Error uploading file:", err);
|
|
|
+ event.reply('upload-file-response', { success: false, message: err.message });
|
|
|
+ }
|
|
|
+ })
|
|
|
+});
|