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 2311cb781e..6338e387f7 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 @@ -7,7 +7,7 @@ import Card from '../../../card' import Badge, { BadgeState } from '@/app/components/base/badge/index' import { pluginManifestToCardPluginProps } from '../../utils' import { useTranslation } from 'react-i18next' -import { installPackageFromGitHub, uninstallPlugin } from '@/service/plugins' +import { installPackageFromGitHub, updateFromGitHub } from '@/service/plugins' import { RiLoader2Line } from '@remixicon/react' import { usePluginTaskList } from '@/service/use-plugins' import checkTaskStatus from '../../base/check-task-status' @@ -49,28 +49,49 @@ const Loaded: React.FC = ({ try { const { owner, repo } = parseGitHubUrl(repoUrl) - const { all_installed: isInstalled, task_id: taskId } = await installPackageFromGitHub( - `${owner}/${repo}`, - selectedVersion, - selectedPackage, - uniqueIdentifier, - ) + if (updatePayload) { + const { all_installed: isInstalled, task_id: taskId } = await updateFromGitHub( + `${owner}/${repo}`, + selectedVersion, + selectedPackage, + updatePayload.originalPackageInfo.id, + uniqueIdentifier, + ) - if (updatePayload && isInstalled) - await uninstallPlugin(updatePayload.originalPackageInfo.id) + if (isInstalled) { + onInstalled() + return + } + + handleRefetch() + await check({ + taskId, + pluginUniqueIdentifier: uniqueIdentifier, + }) - if (isInstalled) { onInstalled() - return } + else { + const { all_installed: isInstalled, task_id: taskId } = await installPackageFromGitHub( + `${owner}/${repo}`, + selectedVersion, + selectedPackage, + uniqueIdentifier, + ) - handleRefetch() - await check({ - taskId, - pluginUniqueIdentifier: uniqueIdentifier, - }) + if (isInstalled) { + onInstalled() + return + } - onInstalled() + handleRefetch() + await check({ + taskId, + pluginUniqueIdentifier: uniqueIdentifier, + }) + + onInstalled() + } } catch (e) { if (typeof e === 'string') { diff --git a/web/app/components/plugins/plugin-item/action.tsx b/web/app/components/plugins/plugin-item/action.tsx index 540c234407..80c5c5e78a 100644 --- a/web/app/components/plugins/plugin-item/action.tsx +++ b/web/app/components/plugins/plugin-item/action.tsx @@ -21,6 +21,7 @@ const i18nPrefix = 'plugin.action' type Props = { author: string installationId: string + pluginUniqueIdentifier: string pluginName: string version: string usedInApps: number @@ -33,6 +34,7 @@ type Props = { const Action: FC = ({ author, installationId, + pluginUniqueIdentifier, pluginName, version, isShowFetchNewVersion, @@ -70,7 +72,7 @@ const Action: FC = ({ type: PluginSource.github, github: { originalPackageInfo: { - id: installationId, + id: pluginUniqueIdentifier, repo: meta!.repo, version: meta!.version, package: meta!.package, diff --git a/web/app/components/plugins/plugin-item/index.tsx b/web/app/components/plugins/plugin-item/index.tsx index 4ef0340641..3569ed856c 100644 --- a/web/app/components/plugins/plugin-item/index.tsx +++ b/web/app/components/plugins/plugin-item/index.tsx @@ -42,6 +42,7 @@ const PluginItem: FC = ({ source, tenant_id, installation_id, + plugin_unique_identifier, endpoints_active, meta, plugin_id, @@ -73,7 +74,7 @@ const PluginItem: FC = ({ {`plugin-${installation_id}-logo`}
@@ -86,6 +87,7 @@ const PluginItem: FC = ({
e.stopPropagation()}> ) => { }) } +export const updateFromGitHub = async (repoUrl: string, selectedVersion: string, selectedPackage: string, + originalPlugin: string, newPlugin: string) => { + return post('/workspaces/current/plugin/upgrade/github', { + body: { + repo: repoUrl, + version: selectedVersion, + package: selectedPackage, + original_plugin_unique_identifier: originalPlugin, + new_plugin_unique_identifier: newPlugin, + }, + }) +} + export const uploadGitHub = async (repoUrl: string, selectedVersion: string, selectedPackage: string) => { return post('/workspaces/current/plugin/upload/github', { body: {