chore: update the update plugin from GitHub

pull/12372/head
Yi 2 years ago
parent 13d3f67746
commit 327940a120

@ -7,7 +7,7 @@ import Card from '../../../card'
import Badge, { BadgeState } from '@/app/components/base/badge/index' import Badge, { BadgeState } from '@/app/components/base/badge/index'
import { pluginManifestToCardPluginProps } from '../../utils' import { pluginManifestToCardPluginProps } from '../../utils'
import { useTranslation } from 'react-i18next' import { useTranslation } from 'react-i18next'
import { installPackageFromGitHub, uninstallPlugin } from '@/service/plugins' import { installPackageFromGitHub, updateFromGitHub } from '@/service/plugins'
import { RiLoader2Line } from '@remixicon/react' import { RiLoader2Line } from '@remixicon/react'
import { usePluginTaskList } from '@/service/use-plugins' import { usePluginTaskList } from '@/service/use-plugins'
import checkTaskStatus from '../../base/check-task-status' import checkTaskStatus from '../../base/check-task-status'
@ -49,15 +49,35 @@ const Loaded: React.FC<LoadedProps> = ({
try { try {
const { owner, repo } = parseGitHubUrl(repoUrl) const { owner, repo } = parseGitHubUrl(repoUrl)
const { all_installed: isInstalled, task_id: taskId } = await installPackageFromGitHub( if (updatePayload) {
const { all_installed: isInstalled, task_id: taskId } = await updateFromGitHub(
`${owner}/${repo}`, `${owner}/${repo}`,
selectedVersion, selectedVersion,
selectedPackage, selectedPackage,
updatePayload.originalPackageInfo.id,
uniqueIdentifier, uniqueIdentifier,
) )
if (updatePayload && isInstalled) if (isInstalled) {
await uninstallPlugin(updatePayload.originalPackageInfo.id) onInstalled()
return
}
handleRefetch()
await check({
taskId,
pluginUniqueIdentifier: uniqueIdentifier,
})
onInstalled()
}
else {
const { all_installed: isInstalled, task_id: taskId } = await installPackageFromGitHub(
`${owner}/${repo}`,
selectedVersion,
selectedPackage,
uniqueIdentifier,
)
if (isInstalled) { if (isInstalled) {
onInstalled() onInstalled()
@ -72,6 +92,7 @@ const Loaded: React.FC<LoadedProps> = ({
onInstalled() onInstalled()
} }
}
catch (e) { catch (e) {
if (typeof e === 'string') { if (typeof e === 'string') {
onFailed(e) onFailed(e)

@ -21,6 +21,7 @@ const i18nPrefix = 'plugin.action'
type Props = { type Props = {
author: string author: string
installationId: string installationId: string
pluginUniqueIdentifier: string
pluginName: string pluginName: string
version: string version: string
usedInApps: number usedInApps: number
@ -33,6 +34,7 @@ type Props = {
const Action: FC<Props> = ({ const Action: FC<Props> = ({
author, author,
installationId, installationId,
pluginUniqueIdentifier,
pluginName, pluginName,
version, version,
isShowFetchNewVersion, isShowFetchNewVersion,
@ -70,7 +72,7 @@ const Action: FC<Props> = ({
type: PluginSource.github, type: PluginSource.github,
github: { github: {
originalPackageInfo: { originalPackageInfo: {
id: installationId, id: pluginUniqueIdentifier,
repo: meta!.repo, repo: meta!.repo,
version: meta!.version, version: meta!.version,
package: meta!.package, package: meta!.package,

@ -42,6 +42,7 @@ const PluginItem: FC<Props> = ({
source, source,
tenant_id, tenant_id,
installation_id, installation_id,
plugin_unique_identifier,
endpoints_active, endpoints_active,
meta, meta,
plugin_id, plugin_id,
@ -73,7 +74,7 @@ const PluginItem: FC<Props> = ({
<img <img
className='w-full h-full' className='w-full h-full'
src={`${API_PREFIX}/workspaces/current/plugin/icon?tenant_id=${tenant_id}&filename=${icon}`} src={`${API_PREFIX}/workspaces/current/plugin/icon?tenant_id=${tenant_id}&filename=${icon}`}
alt={`plugin-${installation_id}-logo`} alt={`plugin-${plugin_unique_identifier}-logo`}
/> />
</div> </div>
<div className="ml-3 w-0 grow"> <div className="ml-3 w-0 grow">
@ -86,6 +87,7 @@ const PluginItem: FC<Props> = ({
<Description text={description[locale]} descriptionLineRows={1}></Description> <Description text={description[locale]} descriptionLineRows={1}></Description>
<div onClick={e => e.stopPropagation()}> <div onClick={e => e.stopPropagation()}>
<Action <Action
pluginUniqueIdentifier={plugin_unique_identifier}
installationId={installation_id} installationId={installation_id}
author={author} author={author}
pluginName={name} pluginName={name}

@ -238,6 +238,11 @@ export type InstallPackageResponse = {
task_id: string task_id: string
} }
export type updatePackageResponse = {
all_installed: boolean
task_id: string
}
export type uploadGitHubResponse = { export type uploadGitHubResponse = {
unique_identifier: string unique_identifier: string
manifest: PluginDeclaration manifest: PluginDeclaration

@ -8,6 +8,7 @@ import type {
PluginTasksResponse, PluginTasksResponse,
TaskStatusResponse, TaskStatusResponse,
UninstallPluginResponse, UninstallPluginResponse,
updatePackageResponse,
uploadGitHubResponse, uploadGitHubResponse,
} from '@/app/components/plugins/types' } from '@/app/components/plugins/types'
import type { import type {
@ -30,6 +31,19 @@ export const updateFromMarketPlace = async (body: Record<string, string>) => {
}) })
} }
export const updateFromGitHub = async (repoUrl: string, selectedVersion: string, selectedPackage: string,
originalPlugin: string, newPlugin: string) => {
return post<updatePackageResponse>('/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) => { export const uploadGitHub = async (repoUrl: string, selectedVersion: string, selectedPackage: string) => {
return post<uploadGitHubResponse>('/workspaces/current/plugin/upload/github', { return post<uploadGitHubResponse>('/workspaces/current/plugin/upload/github', {
body: { body: {

Loading…
Cancel
Save