Skip to content

Let's use AI to Earn!

feat: 日志文件上传

牛文政4437df98792a
diff --git a/electron/main/api/tools.ts b/electron/main/api/tools.ts
index 12e3f203..3d7ed58f 100644
--- a/electron/main/api/tools.ts
+++ b/electron/main/api/tools.ts
@@ -9,7 +9,7 @@ export enum FeedbackType {
msgFeedback = 'msgFeedback', // 消息反馈
}
-class ToolsApi {
+export class ToolsApi {
// 获取AI的评论回复
async aiRecoverReview(inData: {
content: string;
diff --git a/electron/main/tools/controller.ts b/electron/main/tools/controller.ts
index f0b27137..4cd1f40a 100644
--- a/electron/main/tools/controller.ts
+++ b/electron/main/tools/controller.ts
@@ -10,6 +10,7 @@ import { FFmpegVideoUtil } from '../../util/ffmpeg/video';
import { Controller, Icp, Inject, Scheduled } from '../core/decorators';
import { ToolsService } from './service';
import { clearOldLogs } from '../../global/log';
+import { toolsApi } from '../api/tools';
@Controller()
export class ToolsController {
@@ -46,6 +47,26 @@ export class ToolsController {
}
}
+ /**
+ * 下载文件
+ */
+ @Icp('ICP_TOOL_UP_FILE')
+ async upFile(
+ event: Electron.IpcMainInvokeEvent,
+ path: string,
+ secondPath?: string,
+ ): Promise<string> {
+ try {
+ const res = await toolsApi.upFile(path, secondPath);
+ console.log('----- ICP_TOOL_UP_FILE ---', res);
+
+ return res;
+ } catch (error) {
+ console.log('--- ICP_TOOL_UP_FILE error ---', error);
+ return '';
+ }
+ }
+
// 定时清理日志, 每小时进行
@Scheduled('0 0 * * * *', 'clearLog')
async clearLog() {
diff --git a/src/icp/tools.ts b/src/icp/tools.ts
index 5abfffb7..4d975cb2 100644
--- a/src/icp/tools.ts
+++ b/src/icp/tools.ts
@@ -35,10 +35,22 @@ export async function ipcDownFile(url: string, name?: string) {
}
/**
- * 日志获取
+ * 日志路径获取
* @param log
*/
export async function ipcGetLogFlies() {
const res: string[] = await window.ipcRenderer.invoke('GLOBAL_LOG_GET_FLIES');
return res;
}
+
+/**
+ * 本地文件上传
+ * @param path
+ */
+export async function ipcUpFlie(path: string) {
+ const res: string[] = await window.ipcRenderer.invoke(
+ 'ICP_TOOL_UP_FILE',
+ path,
+ );
+ return res;
+}
diff --git a/src/views/test/index.tsx b/src/views/test/index.tsx
index dbb4cb48..c18e994d 100644
--- a/src/views/test/index.tsx
+++ b/src/views/test/index.tsx
@@ -7,17 +7,17 @@
*/
import { useState } from 'react';
import { Button } from 'antd';
-import { ipcGetLogFlies } from '@/icp/tools';
+import { ipcGetLogFlies, ipcUpFlie } from '@/icp/tools';
import log from 'electron-log/renderer';
export default function Test() {
const [filePathList, setFilePathList] = useState<string[]>([]);
+ const [filePath, setFilePath] = useState<string>('');
function addLog() {
log.info('------3333333-----');
}
async function getLogFilePathList() {
const res = await ipcGetLogFlies();
- console.log('--------upLog-- res', res);
setFilePathList(res);
}
@@ -39,11 +39,24 @@ export default function Test() {
前端产生日志
</Button>
+ <Button
+ onClick={() => {
+ ipcUpFlie(filePath);
+ }}
+ >
+ 上传日志文件
+ </Button>
+
<div>
{filePathList.map((item) => (
- <div key={item}>{item}</div>
+ <div onClick={() => setFilePath(item)} key={item}>
+ {item}
+ </div>
))}
</div>
+
+ <br />
+ <div>当前:{filePath}</div>
</div>
);
}