mirror of https://github.com/halo-dev/halo
fix: failed to initialize the preset plugins (#3894)
#### 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 修复在初始化时,预设插件可能初始化失败的问题。 ```pull/3909/head
parent
a8250500fc
commit
3bfecd2b38
|
@ -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);
|
||||
|
|
Loading…
Reference in New Issue