perf: improve plugin loading (#823)

#### What type of PR is this?

/kind improvement

#### What this PR does / why we need it:

优化 Console 端加载插件资源的逻辑。

1. 查询接口改为自定义接口,传入 enabled 参数进行筛选。
2. 修改符合 Console 插件的筛选判断。
3. 隐藏加载异常的提示。

#### Which issue(s) this PR fixes:

Fixes https://github.com/halo-dev/halo/issues/3156

#### Special notes for your reviewer:

测试方式:

1. 安装若干带有 Console 端拓展的插件,比如:https://github.com/halo-sigs/plugin-stackedit
2. 检查是否有加载成功。
3. 创建一个没有插件访问权限的角色。
4. 登录之后检查是否有无权限提示。

#### Does this PR introduce a user-facing change?


```release-note
优化 Console 端加载插件资源的逻辑。
```
pull/826/head
Ryan Wang 2023-01-16 16:40:14 +08:00 committed by GitHub
parent 9d5529b827
commit 04819c12a8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 12 additions and 5 deletions

View File

@ -119,13 +119,20 @@ function loadStyle(href: string) {
const pluginErrorMessages: Array<string> = [];
async function loadPluginModules() {
const { data } =
await apiClient.extension.plugin.listpluginHaloRunV1alpha1Plugin();
const { data } = await apiClient.plugin.listPlugins(
{
enabled: true,
page: 0,
size: 0,
},
{ mute: true }
);
// Get all started plugins
const plugins = data.items.filter(
(plugin) => plugin.status?.phase === "STARTED" && plugin.spec.enabled
);
const plugins = data.items.filter((plugin) => {
const { entry, stylesheet } = plugin.status || {};
return plugin.status?.phase === "STARTED" && (!!entry || !!stylesheet);
});
for (const plugin of plugins) {
const { entry, stylesheet } = plugin.status || {