返回 AiToEarn
controller.ts
1 /*
2 * @Author: nevin
3 * @Date: 2025-01-20 22:02:54
4 * @LastEditTime: 2025-03-31 12:26:51
5 * @LastEditors: nevin
6 * @Description:
7 */
8 import { FileUtils } from '../../util/file';
9 import { FFmpegVideoUtil } from '../../util/ffmpeg/video';
10 import { Controller, Icp, Inject, Scheduled } from '../core/decorators';
11 import { ToolsService } from './service';
12 import { clearOldLogs } from '../../global/log';
13 import { toolsApi } from '../api/tools';
14
15 @Controller()
16 export class ToolsController {
17 @Inject(ToolsService)
18 private readonly toolsService!: ToolsService;
19
20 /**
21 * 视频截取指定时间点的帧
22 */
23 @Icp('ICP_GET_VIDEO_COVER')
24 async getVideoCover(
25 event: Electron.IpcMainInvokeEvent,
26 path: string,
27 time?: string, // 添加可选参数 time
28 ): Promise<string> {
29 return await FFmpegVideoUtil.getVideoCover(path, time);
30 }
31
32 /**
33 * 下载文件
34 */
35 @Icp('ICP_TOOL_DOWN_FILE')
36 async downFile(
37 event: Electron.IpcMainInvokeEvent,
38 url: string,
39 name?: string,
40 ): Promise<string> {
41 try {
42 const res = await FileUtils.downFile(url, name);
43 return res;
44 } catch (error) {
45 console.log('--- ICP_TOOL_DOWN_FILE error ---', error);
46 return '';
47 }
48 }
49
50 /**
51 * 下载文件
52 */
53 @Icp('ICP_TOOL_UP_FILE')
54 async upFile(
55 event: Electron.IpcMainInvokeEvent,
56 path: string,
57 secondPath?: string,
58 ): Promise<string> {
59 try {
60 const res = await toolsApi.upFile(path, secondPath);
61 console.log('----- ICP_TOOL_UP_FILE ---', res);
62
63 return res;
64 } catch (error) {
65 console.log('--- ICP_TOOL_UP_FILE error ---', error);
66 return '';
67 }
68 }
69
70 // 定时清理日志, 每小时进行
71 @Scheduled('0 0 * * * *', 'clearLog')
72 async clearLog() {
73 console.log('clear Log ing ...');
74 clearOldLogs();
75 }
76
77
78 }
79
79 lines TYPESCRIPT