diff --git a/napcat.webui/src/controllers/webui_manager.ts b/napcat.webui/src/controllers/webui_manager.ts
index a57706f3..3adef92b 100644
--- a/napcat.webui/src/controllers/webui_manager.ts
+++ b/napcat.webui/src/controllers/webui_manager.ts
@@ -197,4 +197,12 @@ export default class WebUIManager {
)
return data.data
}
+
+ // 清理缓存
+ public static async cleanCache() {
+ const { data } = await serverRequest.post<
+ ServerResponse<{ result: boolean; message: string }>
+ >('/base/CleanCache')
+ return data.data
+ }
}
diff --git a/napcat.webui/src/pages/dashboard/config/server.tsx b/napcat.webui/src/pages/dashboard/config/server.tsx
index d8a858db..ea9a6036 100644
--- a/napcat.webui/src/pages/dashboard/config/server.tsx
+++ b/napcat.webui/src/pages/dashboard/config/server.tsx
@@ -1,16 +1,22 @@
+import { Button } from '@heroui/button'
import { Input } from '@heroui/input'
import { Switch } from '@heroui/switch'
import { useRequest } from 'ahooks'
-import { useEffect } from 'react'
+import { useEffect, useState } from 'react'
import { Controller, useForm } from 'react-hook-form'
import toast from 'react-hot-toast'
+import { MdDeleteSweep } from 'react-icons/md'
import SaveButtons from '@/components/button/save_buttons'
import PageLoading from '@/components/page_loading'
+import useDialog from '@/hooks/use-dialog'
+
import WebUIManager from '@/controllers/webui_manager'
const ServerConfigCard = () => {
+ const dialog = useDialog()
+ const [isCleaningCache, setIsCleaningCache] = useState(false)
const {
data: configData,
loading: configLoading,
@@ -69,6 +75,42 @@ const ServerConfigCard = () => {
}
}
+ const handleCleanCache = () => {
+ dialog.confirm({
+ title: '清理缓存',
+ content: (
+
+
确定要清理缓存吗?此操作将清理以下内容:
+
+ - 临时文件夹中的所有文件
+ - 图片缓存 (Pic)
+ - 语音缓存 (Ptt)
+ - 视频缓存 (Video)
+ - 文件缓存 (File)
+ - 日志文件 (log)
+
+
此操作不可撤销,请谨慎操作。
+
+ ),
+ onConfirm: async () => {
+ setIsCleaningCache(true)
+ try {
+ const result = await WebUIManager.cleanCache()
+ if (result.result) {
+ toast.success(result.message || '缓存清理成功')
+ } else {
+ toast.error(result.message || '缓存清理失败')
+ }
+ } catch (error) {
+ const msg = (error as Error).message
+ toast.error(`清理缓存失败: ${msg}`)
+ } finally {
+ setIsCleaningCache(false)
+ }
+ }
+ })
+ }
+
useEffect(() => {
reset()
}, [configData])
@@ -131,6 +173,30 @@ const ServerConfigCard = () => {
/>
+
+
维护操作
+
+
+
+
清理缓存
+
+ 清理临时文件、图片、语音、视频、文件缓存和日志文件
+
+
+
}
+ onPress={handleCleanCache}
+ isLoading={isCleaningCache}
+ isDisabled={!!configError}
+ >
+ 清理缓存
+
+
+
+
+
安全配置
${JSON.stringify(newConfig)}`);
await this.reloadNetwork(prev, newConfig);
});
+ WebUiDataRuntime.setCleanCacheCall(async () => {
+ try {
+ await this.actions.get('clean_cache')?.handle({});
+ return { result: true, message: '缓存清理成功' };
+ } catch (error) {
+ this.context.logger.logError('清理缓存失败:', error);
+ return { result: false, message: `清理缓存失败: ${(error as Error).message}` };
+ }
+ });
}
diff --git a/src/webui/src/api/BaseInfo.ts b/src/webui/src/api/BaseInfo.ts
index a7d3c514..61fd7cff 100644
--- a/src/webui/src/api/BaseInfo.ts
+++ b/src/webui/src/api/BaseInfo.ts
@@ -24,3 +24,8 @@ export const SetThemeConfigHandler: RequestHandler = async (req, res) => {
await WebUiConfig.UpdateTheme(theme);
sendSuccess(res, { message: '更新成功' });
};
+
+export const CleanCacheHandler: RequestHandler = async (_, res) => {
+ const result = await WebUiDataRuntime.requestCleanCache();
+ sendSuccess(res, result);
+};
diff --git a/src/webui/src/helper/Data.ts b/src/webui/src/helper/Data.ts
index ef52e0ab..bf389e93 100644
--- a/src/webui/src/helper/Data.ts
+++ b/src/webui/src/helper/Data.ts
@@ -27,6 +27,9 @@ const LoginRuntime: LoginRuntimeType = {
onQuickLoginRequested: async () => {
return { result: false, message: '' };
},
+ onCleanCacheRequested: async () => {
+ return { result: false, message: '' };
+ },
QQLoginList: [],
NewQQLoginList: [],
},
@@ -130,6 +133,14 @@ export const WebUiDataRuntime = {
return LoginRuntime.NapCatHelper.onOB11ConfigChanged(ob11);
} as LoginRuntimeType['NapCatHelper']['onOB11ConfigChanged'],
+ setCleanCacheCall(func: LoginRuntimeType['NapCatHelper']['onCleanCacheRequested']): void {
+ LoginRuntime.NapCatHelper.onCleanCacheRequested = func;
+ },
+
+ requestCleanCache: function () {
+ return LoginRuntime.NapCatHelper.onCleanCacheRequested();
+ } as LoginRuntimeType['NapCatHelper']['onCleanCacheRequested'],
+
getPackageJson() {
return LoginRuntime.packageJson;
},
diff --git a/src/webui/src/router/Base.ts b/src/webui/src/router/Base.ts
index f79975cf..225c7606 100644
--- a/src/webui/src/router/Base.ts
+++ b/src/webui/src/router/Base.ts
@@ -1,5 +1,5 @@
import { Router } from 'express';
-import { GetThemeConfigHandler, PackageInfoHandler, QQVersionHandler, SetThemeConfigHandler } from '../api/BaseInfo';
+import { CleanCacheHandler, GetThemeConfigHandler, PackageInfoHandler, QQVersionHandler, SetThemeConfigHandler } from '../api/BaseInfo';
import { StatusRealTimeHandler } from '@webapi/api/Status';
import { GetProxyHandler } from '../api/Proxy';
@@ -11,5 +11,6 @@ router.get('/GetSysStatusRealTime', StatusRealTimeHandler);
router.get('/proxy', GetProxyHandler);
router.get('/Theme', GetThemeConfigHandler);
router.post('/SetTheme', SetThemeConfigHandler);
+router.post('/CleanCache', CleanCacheHandler);
export { router as BaseRouter };
diff --git a/src/webui/src/types/data.d.ts b/src/webui/src/types/data.d.ts
index 118a95bb..4709ef60 100644
--- a/src/webui/src/types/data.d.ts
+++ b/src/webui/src/types/data.d.ts
@@ -15,6 +15,7 @@ interface LoginRuntimeType {
NapCatHelper: {
onQuickLoginRequested: (uin: string) => Promise<{ result: boolean; message: string }>;
onOB11ConfigChanged: (ob11: OneBotConfig) => Promise;
+ onCleanCacheRequested: () => Promise<{ result: boolean; message: string }>;
QQLoginList: string[];
NewQQLoginList: LoginListItem[];
};