refactor: plugin enable/disable api

Signed-off-by: Ryan Wang <i@ryanc.cc>
pull/588/head
Ryan Wang 2022-07-07 17:05:46 +08:00
parent d15c1636bd
commit 70f7b522f1
2 changed files with 8 additions and 10 deletions

View File

@ -14,7 +14,7 @@ import type { Plugin } from "@/types/extension";
import { axiosInstance } from "@halo-dev/admin-shared";
const pluginActiveId = ref("detail");
const plugin = ref<Plugin>();
const plugin = ref<Plugin>({} as Plugin);
const { params } = useRoute();
@ -30,17 +30,15 @@ const handleFetchPlugin = async () => {
};
const isStarted = computed(() => {
return (
plugin.value?.status?.phase === "STARTED" && plugin.value?.spec.enabled
);
return plugin.value.status?.phase === "STARTED" && plugin.value.spec.enabled;
});
const handleChangePluginStatus = async () => {
try {
plugin.value.spec.enabled = !plugin.value.spec.enabled;
await axiosInstance.put(
`/apis/plugin.halo.run/v1alpha1/plugins/${plugin.value?.metadata.name}/${
isStarted.value ? "stop" : "startup"
}`
`/apis/plugin.halo.run/v1alpha1/plugins/${plugin.value.metadata.name}`,
plugin.value
);
} catch (e) {
console.error(e);

View File

@ -45,10 +45,10 @@ const handleFetchPlugins = async () => {
const handleChangePluginStatus = async (plugin: Plugin) => {
try {
plugin.spec.enabled = !plugin.spec.enabled;
await axiosInstance.put(
`/apis/plugin.halo.run/v1alpha1/plugins/${plugin.metadata.name}/${
isStarted(plugin) ? "stop" : "startup"
}`
`/apis/plugin.halo.run/v1alpha1/plugins/${plugin.metadata.name}`,
plugin
);
} catch (e) {
console.error(e);