feat: can install

This commit is contained in:
Joel 2024-10-24 17:24:46 +08:00
parent 606fc7be0c
commit 9a9d90ad7f
4 changed files with 23 additions and 4 deletions

View File

@ -83,6 +83,7 @@ const InstallFromLocalPackage: React.FC<InstallFromLocalPackageProps> = ({
{
step === InstallStep.readyToInstall && (
<Install
uniqueIdentifier={uniqueIdentifier!}
payload={manifest!}
onCancel={onClose}
onInstalled={handleInstalled}

View File

@ -9,10 +9,12 @@ import { sleep } from '@/utils'
import { Trans, useTranslation } from 'react-i18next'
import { RiLoader2Line } from '@remixicon/react'
import Badge, { BadgeState } from '@/app/components/base/badge/index'
import { installPackageFromLocal } from '@/service/plugins'
const i18nPrefix = 'plugin.installModal'
type Props = {
uniqueIdentifier: string
payload: PluginDeclaration
onCancel: () => void
onInstalled: () => void
@ -20,6 +22,7 @@ type Props = {
}
const Installed: FC<Props> = ({
uniqueIdentifier,
payload,
onCancel,
onInstalled,
@ -31,9 +34,14 @@ const Installed: FC<Props> = ({
const handleInstall = async () => {
if (isInstalling) return
setIsInstalling(true)
try {
await installPackageFromLocal(uniqueIdentifier)
onInstalled()
}
catch (e) {
onFailed()
}
await sleep(1500)
// onInstalled()
onFailed()
}
return (

View File

@ -30,14 +30,18 @@ const Uploading: FC<Props> = ({
const handleUpload = async () => {
try {
const res = await uploadPackageFile(file)
onUploaded(res)
// onUploaded(res)
}
catch (e: any) {
if (e.response?.message) {
onFailed(e.response?.message)
}
else { // Why it would into this branch?
onUploaded(e.response)
const res = e.response
onUploaded({
uniqueIdentifier: res.unique_identifier,
manifest: res.manifest,
})
}
}
}

View File

@ -58,3 +58,9 @@ export const uploadPackageFile = async (file: File) => {
data: formData,
}, false, '/workspaces/current/plugin/upload/pkg')
}
export const installPackageFromLocal = async (uniqueIdentifier: string) => {
return post<InstallPackageResponse>('/workspaces/current/plugin/install/pkg', {
body: { plugin_unique_identifiers: [uniqueIdentifier] },
})
}