From b78ab0bd6969fb1a89043ae46cf1df6b6ee6667e Mon Sep 17 00:00:00 2001 From: Joel Date: Fri, 29 Nov 2024 15:18:07 +0800 Subject: [PATCH] fix: other install error --- .../install-from-github/steps/loaded.tsx | 33 ++++++++++--------- .../steps/install.tsx | 8 +++-- .../update-plugin/from-market-place.tsx | 9 +++-- 3 files changed, 31 insertions(+), 19 deletions(-) diff --git a/web/app/components/plugins/install-plugin/install-from-github/steps/loaded.tsx b/web/app/components/plugins/install-plugin/install-from-github/steps/loaded.tsx index d4f15c0de4..195ff43d00 100644 --- a/web/app/components/plugins/install-plugin/install-from-github/steps/loaded.tsx +++ b/web/app/components/plugins/install-plugin/install-from-github/steps/loaded.tsx @@ -2,7 +2,7 @@ import React from 'react' import Button from '@/app/components/base/button' -import type { PluginDeclaration, PluginType, UpdateFromGitHubPayload } from '../../../types' +import { type PluginDeclaration, type PluginType, TaskStatus, type UpdateFromGitHubPayload } from '../../../types' import Card from '../../../card' import Badge, { BadgeState } from '@/app/components/base/badge/index' import { pluginManifestToCardPluginProps } from '../../utils' @@ -53,8 +53,9 @@ const Loaded: React.FC = ({ try { const { owner, repo } = parseGitHubUrl(repoUrl) + let taskId if (updatePayload) { - const { all_installed: isInstalled, task_id: taskId } = await updateFromGitHub( + const { all_installed: isInstalled, task_id } = await updateFromGitHub( `${owner}/${repo}`, selectedVersion, selectedPackage, @@ -62,40 +63,42 @@ const Loaded: React.FC = ({ uniqueIdentifier, ) + taskId = task_id + if (isInstalled) { onInstalled() return } handleRefetch() - await check({ - taskId, - pluginUniqueIdentifier: uniqueIdentifier, - }) - - onInstalled() } else { - const { all_installed: isInstalled, task_id: taskId } = await installPackageFromGitHub({ + const { all_installed: isInstalled, task_id } = await installPackageFromGitHub({ repoUrl: `${owner}/${repo}`, selectedVersion, selectedPackage, uniqueIdentifier, }) + taskId = task_id + if (isInstalled) { onInstalled() return } handleRefetch() - await check({ - taskId, - pluginUniqueIdentifier: uniqueIdentifier, - }) - - onInstalled() } + + const { status, error } = await check({ + taskId, + pluginUniqueIdentifier: uniqueIdentifier, + }) + if (status === TaskStatus.failed) { + onFailed(error) + return + } + onInstalled() } catch (e) { if (typeof e === 'string') { diff --git a/web/app/components/plugins/install-plugin/install-from-marketplace/steps/install.tsx b/web/app/components/plugins/install-plugin/install-from-marketplace/steps/install.tsx index 914c241c99..a3bb50076b 100644 --- a/web/app/components/plugins/install-plugin/install-from-marketplace/steps/install.tsx +++ b/web/app/components/plugins/install-plugin/install-from-marketplace/steps/install.tsx @@ -2,7 +2,7 @@ import type { FC } from 'react' import React, { useEffect } from 'react' // import { RiInformation2Line } from '@remixicon/react' -import type { Plugin, PluginManifestInMarket } from '../../../types' +import { type Plugin, type PluginManifestInMarket, TaskStatus } from '../../../types' import Card from '../../../card' import { pluginManifestInMarketToPluginProps } from '../../utils' import Button from '@/app/components/base/button' @@ -93,10 +93,14 @@ const Installed: FC = ({ onInstalled() return } - await check({ + const { status, error } = await check({ taskId, pluginUniqueIdentifier: uniqueIdentifier, }) + if (status === TaskStatus.failed) { + onFailed(error) + return + } onInstalled() } catch (e) { diff --git a/web/app/components/plugins/update-plugin/from-market-place.tsx b/web/app/components/plugins/update-plugin/from-market-place.tsx index e4abd32aff..6177ddce1a 100644 --- a/web/app/components/plugins/update-plugin/from-market-place.tsx +++ b/web/app/components/plugins/update-plugin/from-market-place.tsx @@ -7,12 +7,13 @@ import Card from '@/app/components/plugins/card' import Modal from '@/app/components/base/modal' import Button from '@/app/components/base/button' import Badge, { BadgeState } from '@/app/components/base/badge/index' -import type { UpdateFromMarketPlacePayload } from '../types' +import { TaskStatus, type UpdateFromMarketPlacePayload } from '../types' import { pluginManifestToCardPluginProps } from '@/app/components/plugins/install-plugin/utils' import useGetIcon from '../install-plugin/base/use-get-icon' import { updateFromMarketPlace } from '@/service/plugins' import checkTaskStatus from '@/app/components/plugins/install-plugin/base/check-task-status' import { usePluginTaskList } from '@/service/use-plugins' +import Toast from '../../base/toast' const i18nPrefix = 'plugin.upgrade' @@ -83,10 +84,14 @@ const UpdatePluginModal: FC = ({ return } handleRefetch() - await check({ + const { status, error } = await check({ taskId, pluginUniqueIdentifier: targetPackageInfo.id, }) + if (status === TaskStatus.failed) { + Toast.notify({ type: 'error', message: error! }) + return + } onSave() } // eslint-disable-next-line unused-imports/no-unused-vars