| 1 | /* |
| 2 | * @Author: nevin |
| 3 | * @Date: 2025-01-20 22:02:54 |
| 4 | * @LastEditTime: 2025-03-24 09:34:03 |
| 5 | * @LastEditors: nevin |
| 6 | * @Description: reply Reply |
| 7 | */ |
| 8 | import windowOperate from '../../util/windowOperate'; |
| 9 | import { AutoRunModel, AutoRunType } from '../../db/models/autoRun'; |
| 10 | import { AccountService } from '../account/service'; |
| 11 | import { AutoRunService } from '../autoRun/service'; |
| 12 | import { Controller, Et, Icp, Inject } from '../core/decorators'; |
| 13 | import platController from '../plat'; |
| 14 | import { ReplyService } from './service'; |
| 15 | import { SendChannelEnum } from '../../../commont/UtilsEnum'; |
| 16 | import { AutorReplyCommentScheduleEvent } from '../../../commont/types/reply'; |
| 17 | import type { WorkData } from '../plat/plat.type'; |
| 18 | import { GlobleCache } from '../../global/cache'; |
| 19 | import { AutoReplyCache } from './cacheData'; |
| 20 | import type { CorrectQuery } from '../../global/table'; |
| 21 | import { PlatType } from '../../../commont/AccountEnum'; |
| 22 | import { getUserInfo } from '../user/comment'; |
| 23 | @Controller() |
| 24 | export class ReplyController { |
| 25 | @Inject(ReplyService) |
| 26 | private readonly replyService!: ReplyService; |
| 27 | |
| 28 | @Inject(AccountService) |
| 29 | private readonly accountService!: AccountService; |
| 30 | |
| 31 | @Inject(AutoRunService) |
| 32 | private readonly autoRunService!: AutoRunService; |
| 33 | |
| 34 | /** |
| 35 | * 作品点赞 |
| 36 | */ |
| 37 | @Icp('ICP_DIANZAN_DY_OTHER') |
| 38 | async dianzanDyOther( |
| 39 | event: Electron.IpcMainInvokeEvent, |
| 40 | accountId: number, |
| 41 | dataId: string, |
| 42 | option?: any, |
| 43 | ) { |
| 44 | const account = await this.accountService.getAccountById(accountId); |
| 45 | |
| 46 | if (!account) |
| 47 | return { |
| 48 | list: [], |
| 49 | count: 0, |
| 50 | }; |
| 51 | |
| 52 | const res = await platController.dianzanDyOther(account, dataId, option); |
| 53 | |
| 54 | return res; |
| 55 | } |
| 56 | |
| 57 | /** |
| 58 | * 作品收藏 |
| 59 | */ |
| 60 | @Icp('ICP_SHOUCANG_DY_OTHER') |
| 61 | async shoucangDyOther( |
| 62 | event: Electron.IpcMainInvokeEvent, |
| 63 | accountId: number, |
| 64 | pcursor?: string, |
| 65 | ) { |
| 66 | const account = await this.accountService.getAccountById(accountId); |
| 67 | |
| 68 | if (!account) |
| 69 | return { |
| 70 | list: [], |
| 71 | count: 0, |
| 72 | }; |
| 73 | |
| 74 | const res = await platController.shoucangDyOther(account, pcursor); |
| 75 | |
| 76 | return res; |
| 77 | } |
| 78 | |
| 79 | /** |
| 80 | * 作品列表 |
| 81 | */ |
| 82 | @Icp('ICP_CREATOR_LIST') |
| 83 | async getCreatorList( |
| 84 | event: Electron.IpcMainInvokeEvent, |
| 85 | accountId: number, |
| 86 | pcursor?: string, |
| 87 | ) { |
| 88 | const account = await this.accountService.getAccountById(accountId); |
| 89 | |
| 90 | if (!account) |
| 91 | return { |
| 92 | list: [], |
| 93 | count: 0, |
| 94 | }; |
| 95 | |
| 96 | const res = await platController.getWorkList(account, pcursor); |
| 97 | |
| 98 | return res; |
| 99 | } |
| 100 | |
| 101 | /** |
| 102 | * 搜索列表 |
| 103 | */ |
| 104 | @Icp('ICP_SEARCH_NODE_LIST') |
| 105 | async getSearchNodeList( |
| 106 | event: Electron.IpcMainInvokeEvent, |
| 107 | accountId: number, |
| 108 | qe?: string, // 搜索内容 |
| 109 | pageInfo?: any, |
| 110 | ) { |
| 111 | const account = await this.accountService.getAccountById(accountId); |
| 112 | |
| 113 | if (!account) |
| 114 | return { |
| 115 | list: [], |
| 116 | count: 0, |
| 117 | }; |
| 118 | |
| 119 | const res = await platController.getsearchNodeList(account, qe, pageInfo); |
| 120 | |
| 121 | return res; |
| 122 | } |
| 123 | |
| 124 | /** |
| 125 | * 获取评论列表 |
| 126 | */ |
| 127 | @Icp('ICP_COMMENT_LIST') |
| 128 | async getCommentList( |
| 129 | event: Electron.IpcMainInvokeEvent, |
| 130 | accountId: number, |
| 131 | data: WorkData, |
| 132 | pcursor?: string, |
| 133 | ): Promise<any> { |
| 134 | const account = await this.accountService.getAccountById(accountId); |
| 135 | if (!account) return null; |
| 136 | |
| 137 | console.log('------ 评论列表 start ------'); |
| 138 | |
| 139 | const res = await platController.getCommentList(account, data, pcursor); |
| 140 | console.log('------ 评论列表 end ------', res); |
| 141 | |
| 142 | return res; |
| 143 | } |
| 144 | |
| 145 | /** |
| 146 | * 获取其他人评论列表 |
| 147 | */ |
| 148 | @Icp('ICP_COMMENT_LIST_BY_OTHER') |
| 149 | async getCommentListByOther( |
| 150 | event: Electron.IpcMainInvokeEvent, |
| 151 | accountId: number, |
| 152 | data: WorkData, |
| 153 | pcursor?: string, |
| 154 | ): Promise<any> { |
| 155 | const account = await this.accountService.getAccountById(accountId); |
| 156 | if (!account) return null; |
| 157 | |
| 158 | const res = await platController.getCreatorCommentListByOther( |
| 159 | account, |
| 160 | data, |
| 161 | pcursor, |
| 162 | ); |
| 163 | return res; |
| 164 | } |
| 165 | |
| 166 | /** |
| 167 | * 获取二级评论列表 |
| 168 | */ |
| 169 | @Icp('ICP_SECOND_COMMENT_LIST_BY_OTHER') |
| 170 | async getSecondCommentListByOther( |
| 171 | event: Electron.IpcMainInvokeEvent, |
| 172 | accountId: number, |
| 173 | data: WorkData, |
| 174 | root_comment_id: string, |
| 175 | pcursor?: string, |
| 176 | ): Promise<any> { |
| 177 | const account = await this.accountService.getAccountById(accountId); |
| 178 | if (!account) return null; |
| 179 | |
| 180 | const res = await platController.getCreatorSecondCommentListByOther( |
| 181 | account, |
| 182 | data, |
| 183 | root_comment_id, |
| 184 | pcursor, |
| 185 | ); |
| 186 | return res; |
| 187 | } |
| 188 | |
| 189 | /** |
| 190 | * 创建评论 |
| 191 | */ |
| 192 | @Icp('ICP_CREATE_COMMENT') |
| 193 | async createComment( |
| 194 | event: Electron.IpcMainInvokeEvent, |
| 195 | accountId: number, |
| 196 | dataId: string, |
| 197 | content: string, |
| 198 | ): Promise<any> { |
| 199 | const account = await this.accountService.getAccountById(accountId); |
| 200 | if (!account) return null; |
| 201 | |
| 202 | const res = await platController.createComment(account, dataId, content); |
| 203 | return res; |
| 204 | } |
| 205 | |
| 206 | /** |
| 207 | * 创建评论 |
| 208 | */ |
| 209 | @Icp('ICP_CREATE_COMMENT_BY_OTHER') |
| 210 | async createCommentByOther( |
| 211 | event: Electron.IpcMainInvokeEvent, |
| 212 | accountId: number, |
| 213 | dataId: string, |
| 214 | content: string, |
| 215 | authorId?: string, |
| 216 | ): Promise<any> { |
| 217 | const account = await this.accountService.getAccountById(accountId); |
| 218 | if (!account) return null; |
| 219 | |
| 220 | const res = await platController.createCommentByOther( |
| 221 | account, |
| 222 | dataId, |
| 223 | content, |
| 224 | authorId, |
| 225 | ); |
| 226 | return res; |
| 227 | } |
| 228 | |
| 229 | /** |
| 230 | * 作品一键AI评论(该进程只同时进行一个) |
| 231 | */ |
| 232 | @Icp('ICP_REPLY_COMMENT_LIST_BY_AI') |
| 233 | async createCommentList( |
| 234 | event: Electron.IpcMainInvokeEvent, |
| 235 | accountId: number, |
| 236 | data: WorkData, |
| 237 | ): Promise<any> { |
| 238 | const account = await this.accountService.getAccountById(accountId); |
| 239 | if (!account) return null; |
| 240 | |
| 241 | if (GlobleCache.getCache('replyCommentListByAi')) return null; |
| 242 | |
| 243 | GlobleCache.setCache(`replyCommentListByAi`, true, 60 * 60); |
| 244 | |
| 245 | const res = await this.replyService.autorReplyComment( |
| 246 | account, |
| 247 | data, |
| 248 | (e: { |
| 249 | tag: AutorReplyCommentScheduleEvent; |
| 250 | status: -1 | 0 | 1; |
| 251 | data?: any; |
| 252 | error?: any; |
| 253 | }) => { |
| 254 | windowOperate.sendRenderMsg(SendChannelEnum.CommentRelyProgress, e); |
| 255 | }, |
| 256 | ); |
| 257 | |
| 258 | GlobleCache.delCache(`replyCommentListByAi`); |
| 259 | |
| 260 | return res; |
| 261 | } |
| 262 | |
| 263 | /** |
| 264 | * 回复二级评论 |
| 265 | */ |
| 266 | @Icp('ICP_REPLY_COMMENT_BY_OTHER') |
| 267 | async replyCommentByOther( |
| 268 | event: Electron.IpcMainInvokeEvent, |
| 269 | accountId: number, |
| 270 | commentId: string, |
| 271 | content: string, |
| 272 | option: { |
| 273 | dataId?: string; // 作品ID |
| 274 | comment: any; // 辅助数据,原数据 |
| 275 | videoAuthId?: string; // 视频作者ID |
| 276 | }, |
| 277 | ): Promise<any> { |
| 278 | const account = await this.accountService.getAccountById(accountId); |
| 279 | if (!account) return null; |
| 280 | |
| 281 | const res = await platController.replyCommentByOther( |
| 282 | account, |
| 283 | commentId, |
| 284 | content, |
| 285 | option, |
| 286 | ); |
| 287 | return res; |
| 288 | } |
| 289 | |
| 290 | /** |
| 291 | * 回复评论 |
| 292 | */ |
| 293 | @Icp('ICP_REPLY_COMMENT') |
| 294 | async replyComment( |
| 295 | event: Electron.IpcMainInvokeEvent, |
| 296 | accountId: number, |
| 297 | commentId: string, |
| 298 | content: string, |
| 299 | option: { |
| 300 | dataId?: string; // 作品ID |
| 301 | comment: any; // 辅助数据,原数据 |
| 302 | }, |
| 303 | ): Promise<any> { |
| 304 | const account = await this.accountService.getAccountById(accountId); |
| 305 | if (!account) return null; |
| 306 | |
| 307 | const res = await platController.replyComment( |
| 308 | account, |
| 309 | commentId, |
| 310 | content, |
| 311 | option, |
| 312 | ); |
| 313 | return res; |
| 314 | } |
| 315 | |
| 316 | /** |
| 317 | * 创建自动一键评论任务 |
| 318 | */ |
| 319 | @Icp('ICP_AUTO_RUN_CREATE_REPLY') |
| 320 | async createReplyCommentAutoRun( |
| 321 | event: Electron.IpcMainInvokeEvent, |
| 322 | accountId: number, |
| 323 | data: WorkData, |
| 324 | cycleType: string, |
| 325 | ): Promise<AutoRunModel | null> { |
| 326 | const account = await this.accountService.getAccountById(accountId); |
| 327 | if (!account) return null; |
| 328 | |
| 329 | const res = await this.autoRunService.createAutoRun( |
| 330 | { |
| 331 | accountId, |
| 332 | cycleType, |
| 333 | type: AutoRunType.ReplyComment, |
| 334 | userId: account.uid, |
| 335 | }, |
| 336 | data, |
| 337 | ); |
| 338 | |
| 339 | return res; |
| 340 | } |
| 341 | |
| 342 | // 运行自动评论任务 |
| 343 | @Et('ET_AUTO_RUN_REPLY_COMMENT') |
| 344 | async runAutoReplyComment(autoRunData: AutoRunModel): Promise<boolean> { |
| 345 | const { accountId, dataInfo } = autoRunData; |
| 346 | if (!dataInfo) return false; |
| 347 | |
| 348 | const account = await this.accountService.getAccountById(accountId); |
| 349 | if (!account) return false; |
| 350 | |
| 351 | const res = await this.replyService.addReplyQueue( |
| 352 | account, |
| 353 | dataInfo as WorkData, |
| 354 | autoRunData, |
| 355 | ); |
| 356 | |
| 357 | return res.status === 1; |
| 358 | } |
| 359 | |
| 360 | /** |
| 361 | * 获取一键回复评论的任务信息 |
| 362 | */ |
| 363 | @Icp('ICP_GET_AUTO_REPLY_INFO') |
| 364 | async getAutoReplyInfo( |
| 365 | event: Electron.IpcMainInvokeEvent, |
| 366 | ): Promise<any | null> { |
| 367 | return AutoReplyCache.getInfo(); |
| 368 | } |
| 369 | |
| 370 | /** |
| 371 | * 获取回复评论的记录列表 |
| 372 | */ |
| 373 | @Icp('ICP_GET_REPLAY_COMMENT_RECORD_LIST') |
| 374 | async getReplyCommentRecordList( |
| 375 | event: Electron.IpcMainInvokeEvent, |
| 376 | page: CorrectQuery, |
| 377 | query: { |
| 378 | accountId?: number; |
| 379 | type?: PlatType; |
| 380 | }, |
| 381 | ): Promise<any> { |
| 382 | const userInfo = getUserInfo(); |
| 383 | |
| 384 | return this.replyService.getReplyCommentRecordList( |
| 385 | userInfo.id, |
| 386 | page, |
| 387 | query, |
| 388 | ); |
| 389 | } |
| 390 | } |
| 391 |