feat(app): add clear cache button (#1909)

This commit is contained in:
YANG QIA 2023-05-22 17:16:12 +08:00 committed by GitHub
parent 5288cbb1cf
commit d35f67d2e1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 42 additions and 30 deletions

View File

@ -45,7 +45,7 @@ const SnippetCheckboxGroup = connect((props) => {
<Checkbox value="pm.*">{t('Allows to configure plugins')}</Checkbox>
</div>
<div style={{ marginTop: 8 }}>
<Checkbox value="app">{t('Allows to reboot application')}</Checkbox>
<Checkbox value="app">{t('Allows to clear cache, reboot application')}</Checkbox>
</div>
</Checkbox.Group>
);

View File

@ -782,7 +782,8 @@ export default {
'The application is reloading, please do not close the page.': '应用正在重新加载,请勿关闭页面。',
'Application reloading': '应用重新加载中',
'Reboot Application': '重启应用',
"Allows to reboot application": "允许重启应用",
"Allows to clear cache, reboot application": "允许清除缓存,重启应用",
'The will interrupt service, it may take a few seconds to restart. Are you sure to continue?': '重启将会中断当前服务,这个过程可能需要一点时间,确定要继续吗?',
'Reboot': '重启',
'Clear cache': '清除缓存',
}

View File

@ -29,7 +29,7 @@ export const CurrentUser = () => {
const [visible, setVisible] = useState(false);
const { data } = useCurrentUserContext();
const { allowAll, snippets } = useACLRoleContext();
const allowReboot = allowAll || snippets?.includes('app');
const appAllowed = allowAll || snippets?.includes('app');
const silenceApi = useAPIClient();
const check = async () => {
return await new Promise((resolve) => {
@ -71,31 +71,42 @@ export const CurrentUser = () => {
<LanguageSettings />
<ThemeSettings />
<Menu.Divider />
{allowReboot && (
<Menu.Item
key="reload"
onClick={async () => {
Modal.confirm({
title: t('Reboot Application'),
content: t(
'The will interrupt service, it may take a few seconds to restart. Are you sure to continue?',
),
okText: t('Reboot'),
okButtonProps: {
danger: true,
},
onOk: async () => {
await api.resource('app').reboot();
await check();
window.location.reload();
},
});
}}
>
{t('Reboot Application')}
</Menu.Item>
{appAllowed && (
<>
<Menu.Item
key="cache"
onClick={async () => {
await api.resource('app').clearCache();
window.location.reload();
}}
>
{t('Clear Cache')}
</Menu.Item>
<Menu.Item
key="reboot"
onClick={async () => {
Modal.confirm({
title: t('Reboot Application'),
content: t(
'The will interrupt service, it may take a few seconds to restart. Are you sure to continue?',
),
okText: t('Reboot'),
okButtonProps: {
danger: true,
},
onOk: async () => {
await api.resource('app').reboot();
await check();
window.location.reload();
},
});
}}
>
{t('Reboot Application')}
</Menu.Item>
<Menu.Divider />
</>
)}
<Menu.Divider />
<Menu.Item
key="signout"
onClick={async () => {

View File

@ -96,7 +96,7 @@ export class ClientPlugin extends Plugin {
this.app.acl.allow('plugins', '*', 'public');
this.app.acl.registerSnippet({
name: 'app',
actions: ['app:reload', 'app:reboot'],
actions: ['app:reboot', 'app:clearCache'],
});
const dialect = this.app.db.sequelize.getDialect();
const locales = require('./locale').default;
@ -171,8 +171,8 @@ export class ClientPlugin extends Plugin {
.map((item) => item.name);
await next();
},
async reload(ctx, next) {
await ctx.app.reload();
async clearCache(ctx, next) {
await ctx.cache.reset();
await next();
},
reboot(ctx) {