Let's use AI to Earn!
TypeScript auto-publishdouyindouyin-apielectron-appelectron-reactkuaishoukwaipublishedshipinhaotoolxiaohongshu
style: 整理代码
牛文政6329a729e16e
diff --git a/electron/main/index.ts b/electron/main/index.tsindex 9729ab0e..f709920e 100644--- a/electron/main/index.ts+++ b/electron/main/index.ts@@ -144,6 +144,9 @@ app.whenReady().then(async () => {}});+/**+ * Quit when all windows are closed, except on macOS. There, it's common+ */app.on('window-all-closed', () => {win = null;if (process.platform !== 'darwin') app.quit();diff --git a/electron/main/interaction/controller.ts b/electron/main/interaction/controller.tsindex 60cd98ee..6fb831d4 100644--- a/electron/main/interaction/controller.ts+++ b/electron/main/interaction/controller.ts@@ -44,9 +44,9 @@ export class InteractionController {console.log('------ works', works);console.log('------ option', option);- const res = await this.interactionService.interactionOneData(+ const res = await this.interactionService.autorInteraction(account,- works,+ [works],option,(e: {tag: AutorWorksInteractionScheduleEvent;diff --git a/electron/main/interaction/service.ts b/electron/main/interaction/service.tsindex 74f2a34d..bb61442c 100644--- a/electron/main/interaction/service.ts+++ b/electron/main/interaction/service.ts@@ -33,11 +33,11 @@ function getCacheKey(account?: AccountModel) {@Injectable()export class InteractionService {- replyQueue: PQueue;+ interactionQueue: PQueue;private interactionRecordRepository: Repository<InteractionRecordModel>;constructor() {- this.replyQueue = new PQueue({ concurrency: 2 });+ this.interactionQueue = new PQueue({ concurrency: 1 });this.interactionRecordRepository = AppDataSource.getRepository(InteractionRecordModel,);@@ -88,163 +88,6 @@ export class InteractionService {});}- /**- * 互动:作品评论,收藏,点赞- */- async interactionOneData(- account: AccountModel,- works: WorkData,- option: {- commentContent: string; // 评论内容- },- scheduleEvent: (data: {- tag: AutorWorksInteractionScheduleEvent;- status: -1 | 0 | 1; // -1 错误 0 进行中 1 完成- data?: any; // 数据- error?: any;- }) => void,- ) {- const userInfo = getUserInfo();- if (GlobleCache.getCache(getCacheKey(account))) {- sysNotice('请勿重复执行', `该账户有正在执行的任务`);- return false;- }-- try {- scheduleEvent({- tag: AutorWorksInteractionScheduleEvent.Start,- status: 0,- });-- // 重设缓存时间- GlobleCache.updateCacheTTL(getCacheKey(account), 60 * 15);-- scheduleEvent({- tag: AutorWorksInteractionScheduleEvent.GetCommentListStart,- status: 0,- });-- // 历史记录- const oldRecord = await this.getInteractionRecord(- userInfo.id,- account,- works.dataId,- );- if (oldRecord) return false;-- if (!option.commentContent) {- const aiRes = await toolsApi.aiRecoverReview({- content: (works.desc || '') + (works.title || ''),- });-- // AI接口错误- if (!aiRes) {- scheduleEvent({- tag: AutorWorksInteractionScheduleEvent.Error,- status: -1,- error: '未获得AI产出内容',- });- return false;- }-- option.commentContent = aiRes;- }-- scheduleEvent({- tag: AutorWorksInteractionScheduleEvent.ReplyCommentStart,- data: {- aiContent: option.commentContent,- },- status: 0,- });-- // ----- 1-评论作品 ------ const commentWorksRes = await platController.createCommentByOther(- account,- works.dataId,- option.commentContent,- );-- // 错误处理- if (!commentWorksRes) {- scheduleEvent({- tag: AutorWorksInteractionScheduleEvent.ReplyCommentEnd,- status: -1,- error: '回复评论失败',- });- }-- scheduleEvent({- tag: AutorWorksInteractionScheduleEvent.ReplyCommentEnd,- status: 0,- });-- // ----- 2-点赞作品 ------ let isLike: 0 | 1 = 0;- try {- const isLikeRes = await platController.dianzanDyOther(- account,- works.dataId,- );- isLike = isLikeRes ? 1 : 0;- } catch (error) {- scheduleEvent({- tag: AutorWorksInteractionScheduleEvent.Error,- status: 0,- error,- data: {- isLike,- },- });- }-- // ----- 3-收藏作品 ------ let isCollect: 0 | 1 = 0;- try {- const isCollectRes = await platController.shoucangDyOther(- account,- works.dataId,- );- isCollect = isCollectRes ? 1 : 0;- } catch (error) {- scheduleEvent({- tag: AutorWorksInteractionScheduleEvent.Error,- status: 0,- error,- data: {- isLike,- },- });- }-- // 创建评论记录- this.createInteractionRecord(- userInfo.id,- account,- {- worksId: works.dataId,- worksTitle: works.title,- worksCover: works.coverUrl,- },- option.commentContent,- isLike,- isCollect,- );-- scheduleEvent({- tag: AutorWorksInteractionScheduleEvent.ReplyCommentEnd,- status: 0,- });- } catch (error) {- scheduleEvent({- tag: AutorWorksInteractionScheduleEvent.Error,- status: -1,- error,- });- return false;- }- }-/*** 自动一键互动:作品评论,收藏,点赞* 规则:评论作品,已经评论不评论@@ -264,7 +107,7 @@ export class InteractionService {) {const userInfo = getUserInfo();// 设置缓存- GlobleCache.setCache(getCacheKey(account), worksList, 60 * 15);+ GlobleCache.setCache(getCacheKey(), worksList, 60 * 15);try {scheduleEvent({@@ -273,7 +116,7 @@ export class InteractionService {});// 重设缓存时间- GlobleCache.updateCacheTTL(getCacheKey(account), 60 * 15);+ GlobleCache.updateCacheTTL(getCacheKey(), 60 * 15);scheduleEvent({tag: AutorWorksInteractionScheduleEvent.GetCommentListStart,@@ -405,7 +248,7 @@ export class InteractionService {}// 清除缓存- GlobleCache.delCache(getCacheKey(account));+ GlobleCache.delCache(getCacheKey());}/**@@ -425,7 +268,7 @@ export class InteractionService {message?: string;}> {// 查看缓存,有的就不执行- if (GlobleCache.getCache(getCacheKey(account))) {+ if (GlobleCache.getCache(getCacheKey())) {sysNotice('请勿重复执行', `该账户有正在执行的任务,任务ID:${autoRun.id}`);return {@@ -438,7 +281,7 @@ export class InteractionService {const recordData = await this.autoRunService.createAutoRunRecord(autoRun);// 添加到队列- this.replyQueue.add(() => {+ this.interactionQueue.add(() => {this.autorInteraction(account,worksList,diff --git a/electron/main/reply/service.ts b/electron/main/reply/service.tsindex 0d819125..9cb60d72 100644--- a/electron/main/reply/service.ts+++ b/electron/main/reply/service.ts@@ -37,7 +37,7 @@ export class ReplyService {private replyCommentRecordRepository: Repository<ReplyCommentRecordModel>;constructor() {- this.replyQueue = new PQueue({ concurrency: 2 });+ this.replyQueue = new PQueue({ concurrency: 1 });this.replyCommentRecordRepository = AppDataSource.getRepository(ReplyCommentRecordModel,);@@ -102,7 +102,7 @@ export class ReplyService {let thePcursor = undefined;// 设置缓存- GlobleCache.setCache(getCacheKey(account), data, 60 * 15);+ GlobleCache.setCache(getCacheKey(), data, 60 * 15);try {scheduleEvent({@@ -112,7 +112,7 @@ export class ReplyService {while (theHasMore) {// 重设缓存时间- GlobleCache.updateCacheTTL(getCacheKey(account), 60 * 15);+ GlobleCache.updateCacheTTL(getCacheKey(), 60 * 15);scheduleEvent({tag: AutorReplyCommentScheduleEvent.GetCommentListStart,@@ -237,13 +237,14 @@ export class ReplyService {}// 清除缓存- GlobleCache.delCache(getCacheKey(account));+ GlobleCache.delCache(getCacheKey());}/*** 添加作品回复评论的任务到队列* @param account- * @param dataId+ * @param data+ * @param autoRun*/async addReplyQueue(account: AccountModel,@@ -254,7 +255,7 @@ export class ReplyService {message?: string;}> {// 查看缓存,有的就不执行- if (GlobleCache.getCache(getCacheKey(account))) {+ if (GlobleCache.getCache(getCacheKey())) {sysNotice('请勿重复执行', `该账户有正在执行的任务,任务ID:${autoRun.id}`);return {diff --git a/src/views/interaction/index.tsx b/src/views/interaction/index.tsxindex 936d773e..cf34dc0f 100644--- a/src/views/interaction/index.tsx+++ b/src/views/interaction/index.tsx@@ -9,11 +9,7 @@ import { WorkData } from '@/icp/reply';import { Button, Col, Popconfirm, Row, Tabs, Tooltip } from 'antd';import { useCallback, useRef, useState } from 'react';import AccountSidebar from '../account/components/AccountSidebar/AccountSidebar';-import {- AliwangwangOutlined,- FieldTimeOutlined,- QuestionCircleOutlined,-} from '@ant-design/icons';+import { AliwangwangOutlined, QuestionCircleOutlined } from '@ant-design/icons';import InteractionOneKey, {InteractionOneKeyRef,} from './components/oneKeyInteraction';@@ -128,35 +124,26 @@ export default function Page() {</Col><Col span={12}><div className="flex flex-col h-full">- <p className="mb-2">{item.title || '无标题'}</p>- <div className="w-full mt-auto">- <Row justify="space-evenly">- <Col span={8}>- <Button onClick={() => commentWorks(item)}>- 评论作品- </Button>- </Col>- <Col span={8}>- <Button onClick={() => likeWorks(item)}>- 点赞作品- </Button>- </Col>- </Row>-- <Row justify="space-evenly">- <Col span={8}>- <Button onClick={() => collectWorks(item)}>- 收藏作品- </Button>- </Col>- <Col span={8}>- <Tooltip title="自动评论">- <FieldTimeOutlined- onClick={() => interactionOneData(item)}- />- </Tooltip>- </Col>- </Row>+ <p className="mb-2">+ {item.title && item.title.length > 20+ ? item.title.slice(0, 20) + '...'+ : item.title || '无标题'}+ </p>+ <div className="w-full p-2 mt-auto">+ <Button onClick={() => commentWorks(item)}>+ 评论作品+ </Button>+ <Button onClick={() => likeWorks(item)}>+ 点赞作品+ </Button>+ <Button onClick={() => collectWorks(item)}>+ 收藏作品+ </Button>+ <Tooltip title="自动评论">+ <Button onClick={() => interactionOneData(item)}>+ 自动评论+ </Button>+ </Tooltip></div></div></Col>