mirror of https://github.com/halo-dev/halo
refactor: use new api to change plugin status (#4747)
#### What type of PR is this? /area console /kind improvement #### What this PR does / why we need it: 适配 https://github.com/halo-dev/halo/pull/4745 ,使用新的接口启动/停止插件。 #### Which issue(s) this PR fixes: Fixes #4744 #### Special notes for your reviewer: #### Does this PR introduce a user-facing change? ```release-note None ```pull/4772/head
parent
baca058bb3
commit
e20ab8f880
|
@ -187,6 +187,7 @@ models/personal-access-token-list.ts
|
|||
models/personal-access-token.ts
|
||||
models/plugin-author.ts
|
||||
models/plugin-list.ts
|
||||
models/plugin-running-state-request.ts
|
||||
models/plugin-spec.ts
|
||||
models/plugin-status.ts
|
||||
models/plugin.ts
|
||||
|
|
|
@ -46,6 +46,8 @@ import { Plugin } from "../models";
|
|||
// @ts-ignore
|
||||
import { PluginList } from "../models";
|
||||
// @ts-ignore
|
||||
import { PluginRunningStateRequest } from "../models";
|
||||
// @ts-ignore
|
||||
import { Setting } from "../models";
|
||||
// @ts-ignore
|
||||
import { UpgradeFromUriRequest } from "../models";
|
||||
|
@ -57,6 +59,75 @@ export const ApiConsoleHaloRunV1alpha1PluginApiAxiosParamCreator = function (
|
|||
configuration?: Configuration
|
||||
) {
|
||||
return {
|
||||
/**
|
||||
* Change the running state of a plugin by name.
|
||||
* @param {string} name
|
||||
* @param {PluginRunningStateRequest} pluginRunningStateRequest
|
||||
* @param {*} [options] Override http request option.
|
||||
* @throws {RequiredError}
|
||||
*/
|
||||
changePluginRunningState: async (
|
||||
name: string,
|
||||
pluginRunningStateRequest: PluginRunningStateRequest,
|
||||
options: AxiosRequestConfig = {}
|
||||
): Promise<RequestArgs> => {
|
||||
// verify required parameter 'name' is not null or undefined
|
||||
assertParamExists("changePluginRunningState", "name", name);
|
||||
// verify required parameter 'pluginRunningStateRequest' is not null or undefined
|
||||
assertParamExists(
|
||||
"changePluginRunningState",
|
||||
"pluginRunningStateRequest",
|
||||
pluginRunningStateRequest
|
||||
);
|
||||
const localVarPath =
|
||||
`/apis/api.console.halo.run/v1alpha1/plugins/{name}/plugin-state`.replace(
|
||||
`{${"name"}}`,
|
||||
encodeURIComponent(String(name))
|
||||
);
|
||||
// use dummy base URL string because the URL constructor only accepts absolute URLs.
|
||||
const localVarUrlObj = new URL(localVarPath, DUMMY_BASE_URL);
|
||||
let baseOptions;
|
||||
if (configuration) {
|
||||
baseOptions = configuration.baseOptions;
|
||||
}
|
||||
|
||||
const localVarRequestOptions = {
|
||||
method: "PUT",
|
||||
...baseOptions,
|
||||
...options,
|
||||
};
|
||||
const localVarHeaderParameter = {} as any;
|
||||
const localVarQueryParameter = {} as any;
|
||||
|
||||
// authentication BasicAuth required
|
||||
// http basic authentication required
|
||||
setBasicAuthToObject(localVarRequestOptions, configuration);
|
||||
|
||||
// authentication BearerAuth required
|
||||
// http bearer authentication required
|
||||
await setBearerAuthToObject(localVarHeaderParameter, configuration);
|
||||
|
||||
localVarHeaderParameter["Content-Type"] = "application/json";
|
||||
|
||||
setSearchParams(localVarUrlObj, localVarQueryParameter);
|
||||
let headersFromBaseOptions =
|
||||
baseOptions && baseOptions.headers ? baseOptions.headers : {};
|
||||
localVarRequestOptions.headers = {
|
||||
...localVarHeaderParameter,
|
||||
...headersFromBaseOptions,
|
||||
...options.headers,
|
||||
};
|
||||
localVarRequestOptions.data = serializeDataIfNeeded(
|
||||
pluginRunningStateRequest,
|
||||
localVarRequestOptions,
|
||||
configuration
|
||||
);
|
||||
|
||||
return {
|
||||
url: toPathString(localVarUrlObj),
|
||||
options: localVarRequestOptions,
|
||||
};
|
||||
},
|
||||
/**
|
||||
* Merge all CSS bundles of enabled plugins into one.
|
||||
* @param {*} [options] Override http request option.
|
||||
|
@ -855,6 +926,33 @@ export const ApiConsoleHaloRunV1alpha1PluginApiFp = function (
|
|||
const localVarAxiosParamCreator =
|
||||
ApiConsoleHaloRunV1alpha1PluginApiAxiosParamCreator(configuration);
|
||||
return {
|
||||
/**
|
||||
* Change the running state of a plugin by name.
|
||||
* @param {string} name
|
||||
* @param {PluginRunningStateRequest} pluginRunningStateRequest
|
||||
* @param {*} [options] Override http request option.
|
||||
* @throws {RequiredError}
|
||||
*/
|
||||
async changePluginRunningState(
|
||||
name: string,
|
||||
pluginRunningStateRequest: PluginRunningStateRequest,
|
||||
options?: AxiosRequestConfig
|
||||
): Promise<
|
||||
(axios?: AxiosInstance, basePath?: string) => AxiosPromise<Plugin>
|
||||
> {
|
||||
const localVarAxiosArgs =
|
||||
await localVarAxiosParamCreator.changePluginRunningState(
|
||||
name,
|
||||
pluginRunningStateRequest,
|
||||
options
|
||||
);
|
||||
return createRequestFunction(
|
||||
localVarAxiosArgs,
|
||||
globalAxios,
|
||||
BASE_PATH,
|
||||
configuration
|
||||
);
|
||||
},
|
||||
/**
|
||||
* Merge all CSS bundles of enabled plugins into one.
|
||||
* @param {*} [options] Override http request option.
|
||||
|
@ -1194,6 +1292,24 @@ export const ApiConsoleHaloRunV1alpha1PluginApiFactory = function (
|
|||
) {
|
||||
const localVarFp = ApiConsoleHaloRunV1alpha1PluginApiFp(configuration);
|
||||
return {
|
||||
/**
|
||||
* Change the running state of a plugin by name.
|
||||
* @param {ApiConsoleHaloRunV1alpha1PluginApiChangePluginRunningStateRequest} requestParameters Request parameters.
|
||||
* @param {*} [options] Override http request option.
|
||||
* @throws {RequiredError}
|
||||
*/
|
||||
changePluginRunningState(
|
||||
requestParameters: ApiConsoleHaloRunV1alpha1PluginApiChangePluginRunningStateRequest,
|
||||
options?: AxiosRequestConfig
|
||||
): AxiosPromise<Plugin> {
|
||||
return localVarFp
|
||||
.changePluginRunningState(
|
||||
requestParameters.name,
|
||||
requestParameters.pluginRunningStateRequest,
|
||||
options
|
||||
)
|
||||
.then((request) => request(axios, basePath));
|
||||
},
|
||||
/**
|
||||
* Merge all CSS bundles of enabled plugins into one.
|
||||
* @param {*} [options] Override http request option.
|
||||
|
@ -1397,6 +1513,27 @@ export const ApiConsoleHaloRunV1alpha1PluginApiFactory = function (
|
|||
};
|
||||
};
|
||||
|
||||
/**
|
||||
* Request parameters for changePluginRunningState operation in ApiConsoleHaloRunV1alpha1PluginApi.
|
||||
* @export
|
||||
* @interface ApiConsoleHaloRunV1alpha1PluginApiChangePluginRunningStateRequest
|
||||
*/
|
||||
export interface ApiConsoleHaloRunV1alpha1PluginApiChangePluginRunningStateRequest {
|
||||
/**
|
||||
*
|
||||
* @type {string}
|
||||
* @memberof ApiConsoleHaloRunV1alpha1PluginApiChangePluginRunningState
|
||||
*/
|
||||
readonly name: string;
|
||||
|
||||
/**
|
||||
*
|
||||
* @type {PluginRunningStateRequest}
|
||||
* @memberof ApiConsoleHaloRunV1alpha1PluginApiChangePluginRunningState
|
||||
*/
|
||||
readonly pluginRunningStateRequest: PluginRunningStateRequest;
|
||||
}
|
||||
|
||||
/**
|
||||
* Request parameters for fetchPluginConfig operation in ApiConsoleHaloRunV1alpha1PluginApi.
|
||||
* @export
|
||||
|
@ -1635,6 +1772,26 @@ export interface ApiConsoleHaloRunV1alpha1PluginApiUpgradePluginFromUriRequest {
|
|||
* @extends {BaseAPI}
|
||||
*/
|
||||
export class ApiConsoleHaloRunV1alpha1PluginApi extends BaseAPI {
|
||||
/**
|
||||
* Change the running state of a plugin by name.
|
||||
* @param {ApiConsoleHaloRunV1alpha1PluginApiChangePluginRunningStateRequest} requestParameters Request parameters.
|
||||
* @param {*} [options] Override http request option.
|
||||
* @throws {RequiredError}
|
||||
* @memberof ApiConsoleHaloRunV1alpha1PluginApi
|
||||
*/
|
||||
public changePluginRunningState(
|
||||
requestParameters: ApiConsoleHaloRunV1alpha1PluginApiChangePluginRunningStateRequest,
|
||||
options?: AxiosRequestConfig
|
||||
) {
|
||||
return ApiConsoleHaloRunV1alpha1PluginApiFp(this.configuration)
|
||||
.changePluginRunningState(
|
||||
requestParameters.name,
|
||||
requestParameters.pluginRunningStateRequest,
|
||||
options
|
||||
)
|
||||
.then((request) => request(this.axios, this.basePath));
|
||||
}
|
||||
|
||||
/**
|
||||
* Merge all CSS bundles of enabled plugins into one.
|
||||
* @param {*} [options] Override http request option.
|
||||
|
|
|
@ -12,6 +12,10 @@
|
|||
* Do not edit the class manually.
|
||||
*/
|
||||
|
||||
// May contain unused imports in some cases
|
||||
// @ts-ignore
|
||||
import { Metadata } from "./metadata";
|
||||
|
||||
/**
|
||||
*
|
||||
* @export
|
||||
|
@ -36,6 +40,12 @@ export interface ContributorVo {
|
|||
* @memberof ContributorVo
|
||||
*/
|
||||
displayName?: string;
|
||||
/**
|
||||
*
|
||||
* @type {Metadata}
|
||||
* @memberof ContributorVo
|
||||
*/
|
||||
metadata: Metadata;
|
||||
/**
|
||||
*
|
||||
* @type {string}
|
||||
|
|
|
@ -111,6 +111,7 @@ export * from "./personal-access-token-list";
|
|||
export * from "./plugin";
|
||||
export * from "./plugin-author";
|
||||
export * from "./plugin-list";
|
||||
export * from "./plugin-running-state-request";
|
||||
export * from "./plugin-spec";
|
||||
export * from "./plugin-status";
|
||||
export * from "./policy";
|
||||
|
|
|
@ -0,0 +1,33 @@
|
|||
/* tslint:disable */
|
||||
/* eslint-disable */
|
||||
/**
|
||||
* Halo Next API
|
||||
* No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
|
||||
*
|
||||
* The version of the OpenAPI document: 2.0.0
|
||||
*
|
||||
*
|
||||
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
|
||||
* https://openapi-generator.tech
|
||||
* Do not edit the class manually.
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
* @export
|
||||
* @interface PluginRunningStateRequest
|
||||
*/
|
||||
export interface PluginRunningStateRequest {
|
||||
/**
|
||||
*
|
||||
* @type {boolean}
|
||||
* @memberof PluginRunningStateRequest
|
||||
*/
|
||||
async?: boolean;
|
||||
/**
|
||||
*
|
||||
* @type {boolean}
|
||||
* @memberof PluginRunningStateRequest
|
||||
*/
|
||||
enable?: boolean;
|
||||
}
|
|
@ -1,6 +1,6 @@
|
|||
import type { ComputedRef, Ref } from "vue";
|
||||
import { computed } from "vue";
|
||||
import type { Plugin } from "@halo-dev/api-client";
|
||||
import { type Plugin } from "@halo-dev/api-client";
|
||||
import cloneDeep from "lodash.clonedeep";
|
||||
import { apiClient } from "@/utils/api-client";
|
||||
import { Dialog, Toast } from "@halo-dev/components";
|
||||
|
@ -43,22 +43,14 @@ export function usePluginLifeCycle(
|
|||
mutationFn: async () => {
|
||||
if (!plugin?.value) return;
|
||||
|
||||
const { data: pluginToUpdate } =
|
||||
await apiClient.extension.plugin.getpluginHaloRunV1alpha1Plugin({
|
||||
name: plugin.value.metadata.name,
|
||||
});
|
||||
const { enabled } = plugin.value.spec;
|
||||
|
||||
pluginToUpdate.spec.enabled = !pluginToUpdate.spec.enabled;
|
||||
|
||||
const { data: newPlugin } =
|
||||
await apiClient.extension.plugin.updatepluginHaloRunV1alpha1Plugin({
|
||||
name: pluginToUpdate.metadata.name,
|
||||
plugin: pluginToUpdate,
|
||||
});
|
||||
|
||||
await checkStatus(newPlugin);
|
||||
|
||||
return newPlugin;
|
||||
return await apiClient.plugin.changePluginRunningState({
|
||||
name: plugin.value.metadata.name,
|
||||
pluginRunningStateRequest: {
|
||||
enable: !enabled,
|
||||
},
|
||||
});
|
||||
},
|
||||
retry: 3,
|
||||
retryDelay: 1000,
|
||||
|
@ -67,38 +59,6 @@ export function usePluginLifeCycle(
|
|||
},
|
||||
});
|
||||
|
||||
function checkStatus(plugin: Plugin) {
|
||||
const maxRetry = 5;
|
||||
let retryCount = 0;
|
||||
return new Promise((resolve, reject) => {
|
||||
const check = () => {
|
||||
if (retryCount >= maxRetry) {
|
||||
reject(false);
|
||||
return;
|
||||
}
|
||||
apiClient.extension.plugin
|
||||
.getpluginHaloRunV1alpha1Plugin({ name: plugin.metadata.name })
|
||||
.then((response) => {
|
||||
const { enabled } = response.data.spec;
|
||||
const { phase } = response.data.status || {};
|
||||
if (
|
||||
(enabled && phase === "STARTED") ||
|
||||
(!enabled && phase !== "STARTED")
|
||||
) {
|
||||
resolve(true);
|
||||
} else {
|
||||
setTimeout(check, 1000);
|
||||
retryCount++;
|
||||
}
|
||||
})
|
||||
.catch(() => {
|
||||
reject(false);
|
||||
});
|
||||
};
|
||||
check();
|
||||
});
|
||||
}
|
||||
|
||||
const uninstall = (deleteExtensions?: boolean) => {
|
||||
if (!plugin?.value) return;
|
||||
|
||||
|
@ -260,15 +220,11 @@ export function usePluginBatchOperations(names: Ref<string[]>) {
|
|||
onConfirm: async () => {
|
||||
try {
|
||||
for (let i = 0; i < names.value.length; i++) {
|
||||
const { data: pluginToUpdate } =
|
||||
await apiClient.extension.plugin.getpluginHaloRunV1alpha1Plugin({
|
||||
name: names.value[i],
|
||||
});
|
||||
|
||||
pluginToUpdate.spec.enabled = enabled;
|
||||
await apiClient.extension.plugin.updatepluginHaloRunV1alpha1Plugin({
|
||||
name: pluginToUpdate.metadata.name,
|
||||
plugin: pluginToUpdate,
|
||||
await apiClient.plugin.changePluginRunningState({
|
||||
name: names.value[i],
|
||||
pluginRunningStateRequest: {
|
||||
enable: enabled,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
@ -16,7 +16,7 @@ import { formatDatetime } from "@/utils/date";
|
|||
import { useQuery } from "@tanstack/vue-query";
|
||||
|
||||
const plugin = inject<Ref<Plugin | undefined>>("plugin");
|
||||
const { changeStatus } = usePluginLifeCycle(plugin);
|
||||
const { changeStatus, changingStatus } = usePluginLifeCycle(plugin);
|
||||
|
||||
interface RoleTemplateGroup {
|
||||
module: string | null | undefined;
|
||||
|
@ -72,7 +72,11 @@ const pluginRoleTemplateGroups = computed<RoleTemplateGroup[]>(() => {
|
|||
</h3>
|
||||
</div>
|
||||
<div v-permission="['system:plugins:manage']">
|
||||
<VSwitch :model-value="plugin?.spec.enabled" @change="changeStatus" />
|
||||
<VSwitch
|
||||
:loading="changingStatus"
|
||||
:model-value="plugin?.spec.enabled"
|
||||
@change="changeStatus"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
<div
|
||||
|
|
|
@ -2,12 +2,12 @@
|
|||
import { apiClient } from "@/utils/api-client";
|
||||
import { VLoading } from "@halo-dev/components";
|
||||
import { useMutation } from "@tanstack/vue-query";
|
||||
import type {
|
||||
Category,
|
||||
Plugin,
|
||||
PostRequest,
|
||||
SinglePageRequest,
|
||||
Tag,
|
||||
import {
|
||||
type Category,
|
||||
type Plugin,
|
||||
type PostRequest,
|
||||
type SinglePageRequest,
|
||||
type Tag,
|
||||
} from "@halo-dev/api-client";
|
||||
import { onMounted } from "vue";
|
||||
import category from "./setup-data/category.json";
|
||||
|
@ -48,22 +48,12 @@ const { mutate: pluginInstallMutate } = useMutation({
|
|||
const { mutate: pluginStartMutate } = useMutation({
|
||||
mutationKey: ["plugin-start"],
|
||||
mutationFn: async (plugin: Plugin) => {
|
||||
const { data: pluginToUpdate } =
|
||||
await apiClient.extension.plugin.getpluginHaloRunV1alpha1Plugin({
|
||||
name: plugin.metadata.name,
|
||||
});
|
||||
|
||||
pluginToUpdate.spec.enabled = true;
|
||||
|
||||
return apiClient.extension.plugin.updatepluginHaloRunV1alpha1Plugin(
|
||||
{
|
||||
name: plugin.metadata.name,
|
||||
plugin: pluginToUpdate,
|
||||
return await apiClient.plugin.changePluginRunningState({
|
||||
name: plugin.metadata.name,
|
||||
pluginRunningStateRequest: {
|
||||
enable: true,
|
||||
},
|
||||
{
|
||||
mute: true,
|
||||
}
|
||||
);
|
||||
});
|
||||
},
|
||||
retry: 3,
|
||||
retryDelay: 1000,
|
||||
|
|
Loading…
Reference in New Issue