From 3bfecd2b38ce182179604790a15de9a5e119a0e3 Mon Sep 17 00:00:00 2001 From: Ryan Wang Date: Thu, 4 May 2023 15:54:38 +0800 Subject: [PATCH] fix: failed to initialize the preset plugins (#3894) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit #### What type of PR is this? /kind bug /area console /milestone 2.6.x #### What this PR does / why we need it: 修复初始化时,预设插件安装失败的问题,目前的解决方案是重试安装操作。 #### Which issue(s) this PR fixes: Fixes #3893 #### Special notes for your reviewer: 测试方式: 1. 建议参考 https://docs.halo.run/developer-guide/core/build 构建成 Docker 镜像再测试。 2. 测试初始化完成之后,预设插件是否正确安装以及启动即可。 #### Does this PR introduce a user-facing change? ```release-note 修复在初始化时,预设插件可能初始化失败的问题。 ``` --- console/src/views/system/Setup.vue | 36 ++++++++++++++++++++---------- 1 file changed, 24 insertions(+), 12 deletions(-) diff --git a/console/src/views/system/Setup.vue b/console/src/views/system/Setup.vue index 3059bd82da..c153422200 100644 --- a/console/src/views/system/Setup.vue +++ b/console/src/views/system/Setup.vue @@ -36,6 +36,27 @@ const { const siteTitle = ref(""); const loading = ref(false); +const { mutate: pluginInstallMutate } = useMutation({ + mutationKey: ["plugin-install"], + mutationFn: async (plugin: Plugin) => { + const { data } = await apiClient.plugin.installPlugin( + { + source: "PRESET", + presetName: plugin.metadata.name as string, + }, + { + mute: true, + } + ); + return data; + }, + retry: 3, + retryDelay: 1000, + onSuccess(data) { + pluginStartMutate(data); + }, +}); + const { mutate: pluginStartMutate } = useMutation({ mutationKey: ["plugin-start"], mutationFn: async (plugin: Plugin) => { @@ -57,6 +78,7 @@ const { mutate: pluginStartMutate } = useMutation({ ); }, retry: 3, + retryDelay: 1000, }); const handleSubmit = async () => { @@ -104,18 +126,8 @@ const handleSubmit = async () => { // Install preset plugins const { data: presetPlugins } = await apiClient.plugin.listPluginPresets(); - const installPluginResponses = await Promise.all( - presetPlugins.map((plugin) => { - return apiClient.plugin.installPlugin({ - source: "PRESET", - presetName: plugin.metadata.name as string, - }); - }) - ); - - for (let i = 0; i < installPluginResponses.length; i++) { - const response = installPluginResponses[i]; - pluginStartMutate(response.data); + for (let i = 0; i < presetPlugins.length; i++) { + pluginInstallMutate(presetPlugins[i]); } } catch (error) { console.error("Failed to initialize preset data", error);