mirror of https://github.com/msgbyte/tailchat
feat(admin-next): add cache manager
parent
4d6e85c849
commit
0d7d71d22f
@ -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';
|
@ -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…
Reference in New Issue