Skip to content

Let's use AI to Earn!

feat: 一键AI回复

牛文政df587cb3b9f7
diff --git a/electron/main/api/index.ts b/electron/main/api/index.ts
index d8869d26..507360e1 100644
--- a/electron/main/api/index.ts
+++ b/electron/main/api/index.ts
@@ -14,7 +14,7 @@ export interface IRequestNetParams {
isFile?: boolean;
}
-const requestNet = <T = any>({
+const netRequest = <T = any>({
headers,
body,
method,
@@ -24,7 +24,7 @@ const requestNet = <T = any>({
return new Promise((resolve, reject) => {
const req = net.request({
method: method || 'GET',
- url,
+ url: `${process.env.VITE_APP_URL}/${url}`,
});
// 设置请求头
@@ -78,4 +78,4 @@ const requestNet = <T = any>({
});
};
-export default requestNet;
+export default netRequest;
diff --git a/electron/main/api/tools.ts b/electron/main/api/tools.ts
index 055692d2..7dd7650f 100644
--- a/electron/main/api/tools.ts
+++ b/electron/main/api/tools.ts
@@ -1,56 +1,23 @@
-import { net } from 'electron';
+import netRequest from '.';
class ToolsApi {
- private async request<T>(
- method: string,
- path: string,
- data?: any,
- token?: string,
- ): Promise<any> {
- return new Promise((resolve, reject) => {
- const request = net.request({
- method,
- url: `http://127.0.0.1:3000/api/`,
- headers: token
- ? {
- Authorization: `Bearer ${token}`,
- }
- : {},
- });
-
- request.on('response', (response) => {
- let data = '';
- response.on('data', (chunk) => {
- data += chunk;
- });
- response.on('end', () => {
- try {
- resolve(JSON.parse(data));
- } catch (e) {
- reject(e);
- }
- });
- });
-
- request.on('error', reject);
-
- if (data) {
- request.write(JSON.stringify(data));
- }
- request.end();
+ // 获取AI的评论回复
+ async aiRecoverReview(data: {
+ content: string;
+ title?: string;
+ desc?: string;
+ max?: number;
+ }): Promise<any> {
+ const res = await netRequest<any>({
+ method: 'POST',
+ url: 'tools/ai/recover/review',
+ body: data,
});
- }
- // 获取AI的评论回复
- async createRanking(data: any, token: string): Promise<any> {
- const response = await this.request<any>(
- 'POST',
- 'tools/ai/recover/review',
- data,
- token,
- );
- return response.data;
+ console.log('------ res', res);
+
+ return res;
}
}
-export const rankingApi = new ToolsApi();
+export const toolsApi = new ToolsApi();
diff --git a/electron/main/index.ts b/electron/main/index.ts
index f2f13a28..2fb3f296 100644
--- a/electron/main/index.ts
+++ b/electron/main/index.ts
@@ -10,6 +10,8 @@ import { getAssetPath } from '../util/index';
import windowOperate from '../util/windowOperate';
import { logger } from '../global/log';
import { SplashWindow } from './splash';
+import dotenv from 'dotenv';
+dotenv.config();
const __dirname = path.dirname(fileURLToPath(import.meta.url));
diff --git a/electron/main/reply/controller.ts b/electron/main/reply/controller.ts
index e5bb2ced..b936eb58 100644
--- a/electron/main/reply/controller.ts
+++ b/electron/main/reply/controller.ts
@@ -6,6 +6,7 @@
* @Description: reply Reply
*/
import { AccountService } from '../account/service';
+import { toolsApi } from '../api/tools';
import { Controller, Icp, Inject } from '../core/decorators';
import platController from '../plat';
import type { CommentData, PageInfo } from '../plat/plat.type';
@@ -84,6 +85,12 @@ export class ReplyController {
accountId: number,
dataId: string,
): Promise<any> {
+ const res1 = await toolsApi.aiRecoverReview({
+ content: '今天天气真好',
+ });
+
+ console.log('------ res1', res1);
+
const account = await this.accountService.getAccountById(accountId);
if (!account) return null;
diff --git a/src/icp/reply.ts b/src/icp/reply.ts
index 7b4c3458..2cff2690 100644
--- a/src/icp/reply.ts
+++ b/src/icp/reply.ts
@@ -120,3 +120,15 @@ export async function icpReplyComment(
);
return res;
}
+
+/**
+ * 一键作品回复评论
+ */
+export async function icpCreateCommentList(accountId: number, dataId: string) {
+ const res: boolean = await window.ipcRenderer.invoke(
+ 'ICP_REPLY_COMMENT_LIST_BY_AI',
+ accountId,
+ dataId,
+ );
+ return res;
+}
diff --git a/src/views/reply/index.tsx b/src/views/reply/index.tsx
index dd2a5bfa..4caba8bd 100644
--- a/src/views/reply/index.tsx
+++ b/src/views/reply/index.tsx
@@ -10,6 +10,7 @@ import {
icpGetCommentList,
WorkData,
CommentData,
+ icpCreateCommentList,
} from '@/icp/reply';
import { Avatar, Button, Card, Col, Row } from 'antd';
import { useCallback, useRef, useState } from 'react';
@@ -49,6 +50,14 @@ export default function Page() {
setCommentList(res.list);
}
+ /**
+ * 一键AI评论
+ */
+ async function createCommentList(data: WorkData) {
+ const res = await icpCreateCommentList(activeAccountId, data.dataId);
+ console.log('------ res', res);
+ }
+
/**
* 打开作品评论
* @param data
@@ -85,7 +94,7 @@ export default function Page() {
{wordList.map((item) => (
<Card
key={item.dataId}
- style={{ width: 200 }}
+ style={{ width: 300 }}
cover={<img alt="example" src={item.coverUrl} />}
actions={[
<Button
@@ -102,6 +111,14 @@ export default function Page() {
>
评论作品
</Button>,
+ <Button
+ type="primary"
+ onClick={() => {
+ createCommentList(item);
+ }}
+ >
+ 一键AI评论
+ </Button>,
]}
>
<Meta title={item.title} />