feat(admin-next): add cache manager

pull/90/head
moonrailgun 2 years ago
parent 4d6e85c849
commit 0d7d71d22f

@ -12,6 +12,7 @@ import {
IconFile,
IconMessage,
IconSettings,
IconStorage,
IconUser,
IconUserGroup,
IconWifi,
@ -22,6 +23,7 @@ import { fileFields, groupFields, mailFields, messageFields } from './fields';
import { i18n } from './i18n';
import { httpClient } from './request';
import { UserList } from './resources/user';
import { CacheManager } from './routes/cache';
import { TailchatNetwork } from './routes/network';
import { SocketIOAdmin } from './routes/socketio';
import { SystemConfig } from './routes/system';
@ -95,10 +97,6 @@ function App() {
list={<ListTable fields={mailFields} />}
/>
<CustomRoute name="system" icon={<IconSettings />}>
<SystemConfig />
</CustomRoute>
<CustomRoute name="network" icon={<IconWifi />}>
<TailchatNetwork />
</CustomRoute>
@ -106,6 +104,14 @@ function App() {
<CustomRoute name="socketio" icon={<IconDashboard />}>
<SocketIOAdmin />
</CustomRoute>
<CustomRoute name="cache" icon={<IconStorage />}>
<CacheManager />
</CustomRoute>
<CustomRoute name="system" icon={<IconSettings />}>
<SystemConfig />
</CustomRoute>
</Tushan>
);
}

@ -46,6 +46,12 @@ export const i18n: TushanContextProps['i18n'] = {
serverName: 'Server Name',
serverEntryImage: 'Server Entry Page Image',
},
cache: {
cleanTitle: 'Are you sure you want to clear the cache?',
cleanDesc:
'Please be cautious in the production environment, clearing the cache may lead to increased pressure on the database in a short period of time',
cleanBtn: 'Clean Cache',
},
},
},
},
@ -132,6 +138,9 @@ export const i18n: TushanContextProps['i18n'] = {
socketio: {
name: 'Socket.IO 长链接',
},
cache: {
name: '缓存管理',
},
},
custom: {
action: {
@ -170,6 +179,12 @@ export const i18n: TushanContextProps['i18n'] = {
serverName: '服务器名',
serverEntryImage: '服务器登录图',
},
cache: {
cleanTitle: '确定要清理缓存么?',
cleanDesc:
'生产环境请谨慎操作, 清理缓存可能会导致短时间内数据库压力增加',
cleanBtn: '清理缓存',
},
},
},
},

@ -0,0 +1,42 @@
import React from 'react';
import {
Button,
Card,
Message,
Popconfirm,
useAsyncRequest,
useTranslation,
} from 'tushan';
import { request } from '../request';
/**
*
*/
export const CacheManager: React.FC = React.memo(() => {
const { t } = useTranslation();
const [, cleanCache] = useAsyncRequest(async () => {
const { data } = await request.post('/cache/clean');
if (!data.success) {
Message.error(t('tushan.common.failed') + ':' + data.msg);
throw new Error(data.msg);
}
Message.success(t('tushan.common.success'));
});
return (
<Card>
<Popconfirm
title={t('custom.cache.cleanTitle')}
content={t('custom.cache.cleanDesc')}
onOk={cleanCache}
>
<Button type="primary" status="danger">
{t('custom.cache.cleanBtn')}
</Button>
</Popconfirm>
</Card>
);
});
CacheManager.displayName = 'CacheManager';

@ -9,6 +9,7 @@ import dayjs from 'dayjs';
import userModel from '../../../../models/user/user';
import messageModel from '../../../../models/chat/message';
import { raExpressMongoose } from '../middleware/express-mongoose-ra-json-server';
import { cacheRouter } from './cache';
const router = Router();
@ -46,6 +47,7 @@ router.post('/login', (req, res) => {
router.use('/network', networkRouter);
router.use('/config', configRouter);
router.use('/file', fileRouter);
router.use('/cache', cacheRouter);
router.get('/user/count/summary', auth(), async (req, res) => {
// 返回最近7天的用户数统计

@ -0,0 +1,29 @@
import { Router } from 'express';
import { broker } from '../broker';
import { auth } from '../middleware/auth';
const router = Router();
/**
*
*/
router.post('/clean', auth(), async (req, res, next) => {
try {
if (!broker.cacher) {
res.json({
success: false,
message: 'Not found cacher',
});
return;
}
await broker.cacher.clean();
res.json({
success: true,
});
} catch (err) {
next(err);
}
});
export { router as cacheRouter };
Loading…
Cancel
Save