diff --git a/console/packages/api-client/src/.openapi-generator/FILES b/console/packages/api-client/src/.openapi-generator/FILES index 2f683a17ee..b77775a670 100644 --- a/console/packages/api-client/src/.openapi-generator/FILES +++ b/console/packages/api-client/src/.openapi-generator/FILES @@ -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 diff --git a/console/packages/api-client/src/api/api-console-halo-run-v1alpha1-plugin-api.ts b/console/packages/api-client/src/api/api-console-halo-run-v1alpha1-plugin-api.ts index 0372193067..12e8463ddf 100644 --- a/console/packages/api-client/src/api/api-console-halo-run-v1alpha1-plugin-api.ts +++ b/console/packages/api-client/src/api/api-console-halo-run-v1alpha1-plugin-api.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 => { + // 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 + > { + 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 { + 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. diff --git a/console/packages/api-client/src/models/contributor-vo.ts b/console/packages/api-client/src/models/contributor-vo.ts index bc02317f18..ad59631fb3 100644 --- a/console/packages/api-client/src/models/contributor-vo.ts +++ b/console/packages/api-client/src/models/contributor-vo.ts @@ -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} diff --git a/console/packages/api-client/src/models/index.ts b/console/packages/api-client/src/models/index.ts index 46e5a3e834..9307469393 100644 --- a/console/packages/api-client/src/models/index.ts +++ b/console/packages/api-client/src/models/index.ts @@ -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"; diff --git a/console/packages/api-client/src/models/plugin-running-state-request.ts b/console/packages/api-client/src/models/plugin-running-state-request.ts new file mode 100644 index 0000000000..1121d2122b --- /dev/null +++ b/console/packages/api-client/src/models/plugin-running-state-request.ts @@ -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; +} diff --git a/console/src/modules/system/plugins/composables/use-plugin.ts b/console/src/modules/system/plugins/composables/use-plugin.ts index 9408e7247e..6bb856d096 100644 --- a/console/src/modules/system/plugins/composables/use-plugin.ts +++ b/console/src/modules/system/plugins/composables/use-plugin.ts @@ -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) { 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, + }, }); } diff --git a/console/src/modules/system/plugins/tabs/Detail.vue b/console/src/modules/system/plugins/tabs/Detail.vue index 2e1e14af82..310e27bd65 100644 --- a/console/src/modules/system/plugins/tabs/Detail.vue +++ b/console/src/modules/system/plugins/tabs/Detail.vue @@ -16,7 +16,7 @@ import { formatDatetime } from "@/utils/date"; import { useQuery } from "@tanstack/vue-query"; const plugin = inject>("plugin"); -const { changeStatus } = usePluginLifeCycle(plugin); +const { changeStatus, changingStatus } = usePluginLifeCycle(plugin); interface RoleTemplateGroup { module: string | null | undefined; @@ -72,7 +72,11 @@ const pluginRoleTemplateGroups = computed(() => {
- +
{ - 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,