返回 AiToEarn
autoRun.ts
根目录 / project / aitoearn-electron / src / icp / autoRun.ts
1 /*
2 * @Author: nevin
3 * @Date: 2025-01-23 15:48:14
4 * @LastEditTime: 2025-03-28 13:35:19
5 * @LastEditors: nevin
6 * @Description: 自动进程
7 */
8
9 export enum AutoRunType {
10 ReplyComment = 1, // 回复评论
11 }
12
13 // 状态 进行中 暂停 删除
14 export enum AutoRunStatus {
15 DOING = 2, // 进行中
16 PAUSE = 3, // 暂停
17 DELETE = 4, // 删除
18 }
19
20 export interface AutoRun {
21 id: number;
22 userId: string;
23 accountId: number;
24 runCount: number;
25 status: AutoRunStatus;
26 type: AutoRunType;
27 cycleType: string;
28 createTime: string;
29 updateTime: string;
30 }
31
32 export enum AutoRunRecordStatus {
33 DOING = 1, // 进行中
34 FAIL = 2, // 失败
35 SUCCESS = 3, // 完成
36 }
37
38 export interface AutoRunRecord {
39 id: number;
40 autoRunId: number;
41 userId: string;
42 status: AutoRunRecordStatus;
43 type: AutoRunType;
44 cycleType: string;
45 createTime: string;
46 updateTime: string;
47 }
48
49 /**
50 * 创建自动进程
51 * @param data
52 */
53 export async function ipcCreateAutoRun(
54 info: {
55 accountId: number;
56 type: AutoRunType;
57 cycleType: string;
58 },
59 data: Record<string, any>,
60 ) {
61 data.data = JSON.stringify(data.data);
62 const res: string = await window.ipcRenderer.invoke(
63 'ICP_AUTO_RUN_CREATE',
64 info,
65 data,
66 );
67 return res;
68 }
69
70 /**
71 * 获取进程列表
72 * @param query
73 */
74 export async function ipcGetAutoRunList(
75 pageInfo: {
76 page: number;
77 pageSize: number;
78 },
79 query: {
80 type?: AutoRunType;
81 status?: AutoRunStatus;
82 cycleType?: string;
83 accountId?: number;
84 dataId?: string;
85 },
86 ): Promise<{
87 list: AutoRun[];
88 count: number;
89 }> {
90 const res = await window.ipcRenderer.invoke(
91 'ICP_AUTO_RUN_LIST',
92 pageInfo,
93 query,
94 );
95 return res;
96 }
97
98 /**
99 * 更新自动进程状态
100 * @param data
101 */
102 export async function ipcUpdateAutoRunStatus(
103 id: number,
104 status: AutoRunStatus,
105 ) {
106 const res: string = await window.ipcRenderer.invoke(
107 'ICP_AUTO_RUN_STATUS',
108 id,
109 status,
110 );
111 return res;
112 }
113
114 /**
115 * 获取进运行记录列表
116 * @param data
117 */
118 export async function ipcGetAutoRunRecordList(
119 pageInfo: {
120 page: number;
121 pageSize: number;
122 },
123 query: {
124 autoRunId: number;
125 type?: AutoRunType;
126 status?: AutoRunRecordStatus;
127 cycleType?: string;
128 },
129 ): Promise<{
130 list: AutoRunRecord[];
131 total: number;
132 }> {
133 const res = await window.ipcRenderer.invoke(
134 'ICP_AUTO_RUN_RECORD_LIST',
135 pageInfo,
136 query,
137 );
138 return res;
139 }
140
141 /**
142 * 创建自动进程
143 * @param data
144 */
145 export async function ipcCreateAutoRunRecord(autoRunId: number) {
146 const res: string = await window.ipcRenderer.invoke(
147 'ICP_AUTO_RUN_RECORD_CREATE',
148 autoRunId,
149 );
150 return res;
151 }
152
153 /**
154 * 立即执行进程
155 * @param id
156 */
157 export async function ipcRunNowAutoRun(id: number) {
158 const res: boolean = await window.ipcRenderer.invoke(
159 'ICP_RUN_NOW_AUTO_RUN',
160 id,
161 );
162 return res;
163 }
164
164 lines TYPESCRIPT