Skip to content

Let's use AI to Earn!

feat: 加入node-cache缓存包

牛文政491913002978
diff --git a/electron/global/cache.ts b/electron/global/cache.ts
new file mode 100644
index 00000000..797ef8e8
--- /dev/null
+++ b/electron/global/cache.ts
@@ -0,0 +1,40 @@
+import NodeCache from 'node-cache';
+const GlobleCache = new NodeCache();
+
+/**
+ * 缓存数据
+ * @param key 缓存key
+ * @param value 缓存值
+ * @param ttl 缓存时间 秒
+ */
+export const setCache = (key: string, value: any, ttl?: number) => {
+ if (ttl) {
+ GlobleCache.set(key, value, ttl);
+ } else {
+ GlobleCache.set(key, value);
+ }
+};
+
+export const getCache = (key: string) => {
+ return GlobleCache.get(key);
+};
+
+export const delCache = (key: string) => {
+ return GlobleCache.del(key);
+};
+
+export const clearCache = () => {
+ return GlobleCache.flushAll();
+};
+
+// 更改TTL
+export const updateCacheTTL = (key: string, ttl: number) => {
+ GlobleCache.ttl(key, ttl);
+};
+
+// 设置多个缓存
+export const setMultiCache = (
+ list: { key: string; val: any; ttl?: number }[],
+) => {
+ GlobleCache.mset(list);
+};
diff --git a/package-lock.json b/package-lock.json
index e8ad6cf7..84b33bb0 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -23,7 +23,6 @@
"dayjs": "^1.11.13",
"dotenv": "^16.4.7",
"echarts": "^5.6.0",
- "electron": "^35.0.3",
"electron-log": "^5.3.0",
"electron-serve": "^2.1.1",
"electron-store": "^10.0.0",
@@ -35,6 +34,7 @@
"image-size": "^1.2.0",
"lodash": "^4.17.21",
"mime-types": "^2.1.35",
+ "node-cache": "^5.1.2",
"node-schedule": "^2.1.1",
"os": "^0.1.2",
"p-queue": "^8.1.0",
@@ -8971,6 +8971,25 @@
"semver": "^7.3.5"
}
},
+ "node_modules/node-cache": {
+ "version": "5.1.2",
+ "resolved": "https://registry.npmmirror.com/node-cache/-/node-cache-5.1.2.tgz",
+ "integrity": "sha512-t1QzWwnk4sjLWaQAS8CHgOJ+RAfmHpxFWmc36IWTiWHQfs0w5JDMBS1b1ZxQteo0vVVuWJvIUKHDkkeK7vIGCg==",
+ "dependencies": {
+ "clone": "2.x"
+ },
+ "engines": {
+ "node": ">= 8.0.0"
+ }
+ },
+ "node_modules/node-cache/node_modules/clone": {
+ "version": "2.1.2",
+ "resolved": "https://registry.npmmirror.com/clone/-/clone-2.1.2.tgz",
+ "integrity": "sha512-3Pe/CF1Nn94hyhIYpjtiLhdCoEoz0DqQ+988E9gmeEdQZlojxnOb74wctFyuwWQHzqyf9X7C7MG8juUpqBJT8w==",
+ "engines": {
+ "node": ">=0.8"
+ }
+ },
"node_modules/node-releases": {
"version": "2.0.19",
"resolved": "https://registry.npmmirror.com/node-releases/-/node-releases-2.0.19.tgz",
diff --git a/package.json b/package.json
index c3c006d6..57152e75 100644
--- a/package.json
+++ b/package.json
@@ -55,6 +55,7 @@
"image-size": "^1.2.0",
"lodash": "^4.17.21",
"mime-types": "^2.1.35",
+ "node-cache": "^5.1.2",
"node-schedule": "^2.1.1",
"os": "^0.1.2",
"p-queue": "^8.1.0",
diff --git a/src/views/reply/components/oneKeyReply.tsx b/src/views/reply/components/oneKeyReply.tsx
index 4b122b17..32c4378d 100644
--- a/src/views/reply/components/oneKeyReply.tsx
+++ b/src/views/reply/components/oneKeyReply.tsx
@@ -6,7 +6,7 @@
* @Description: 一键评论
*/
import { icpReplyCommentList, WorkData } from '@/icp/reply';
-import { Modal } from 'antd';
+import { message, Modal } from 'antd';
import { forwardRef, useImperativeHandle, useState } from 'react';
import { SendChannelEnum } from '@@/UtilsEnum';
import {
@@ -39,6 +39,18 @@ const Com = forwardRef<OneKeyReplyRef>((props: any, ref) => {
console.log('------ res', res);
}
+ function closeShow() {
+ // 关闭界面
+ setTimeout(() => {
+ handleCancel();
+ }, 1000);
+
+ setTimeout(() => {
+ setErrorText('');
+ setInfoText('');
+ }, 2000);
+ }
+
/**
* 返回值处理
* @param e
@@ -62,9 +74,12 @@ const Com = forwardRef<OneKeyReplyRef>((props: any, ref) => {
break;
case AutorReplyCommentScheduleEvent.End:
setInfoText(`评论结束:${args.data?.aiContent || ''}`);
+ message.success(`部分平台评论需要审核,评论后的数据可能存在延时`);
+ closeShow();
break;
case AutorReplyCommentScheduleEvent.Error:
setErrorText(args.error?.message || '未知错误');
+ closeShow();
break;
default:
const tagStr =
diff --git a/src/views/reply/index.tsx b/src/views/reply/index.tsx
index dc6bbd3a..40341322 100644
--- a/src/views/reply/index.tsx
+++ b/src/views/reply/index.tsx
@@ -6,7 +6,7 @@
* @Description: 评论页面 reply
*/
import { icpCreatorList, WorkData } from '@/icp/reply';
-import { Button, Col, Row, Tabs, Tooltip } from 'antd';
+import { Button, Col, Popconfirm, Row, Tabs, Tooltip } from 'antd';
import { useCallback, useRef, useState } from 'react';
import AccountSidebar from '../account/components/AccountSidebar/AccountSidebar';
import ReplyWorks, { ReplyWorksRef } from './components/replyWorks';
@@ -132,14 +132,21 @@ export default function Page() {
<Row justify="space-evenly">
<Col span={8}>
<Tooltip title="一键评论">
- <AliwangwangOutlined
- onClick={() =>
+ <Popconfirm
+ title="确认进行一键评论"
+ onConfirm={(
+ e?: React.MouseEvent<HTMLElement>,
+ ) => {
Ref_OneKeyReply.current?.init(
activeAccountId,
item,
- )
- }
- />
+ );
+ }}
+ okText="是"
+ cancelText="否"
+ >
+ <AliwangwangOutlined />
+ </Popconfirm>
</Tooltip>
</Col>
<Col span={8}>