From 9a9d90ad7f1c1ed73a5d281f678d63cf611699de Mon Sep 17 00:00:00 2001 From: Joel Date: Thu, 24 Oct 2024 17:24:46 +0800 Subject: [PATCH] feat: can install --- .../install-from-local-package/index.tsx | 1 + .../install-from-local-package/steps/install.tsx | 12 ++++++++++-- .../install-from-local-package/steps/uploading.tsx | 8 ++++++-- web/service/plugins.ts | 6 ++++++ 4 files changed, 23 insertions(+), 4 deletions(-) diff --git a/web/app/components/plugins/install-plugin/install-from-local-package/index.tsx b/web/app/components/plugins/install-plugin/install-from-local-package/index.tsx index e71f5f7e2f..bbfc195a4d 100644 --- a/web/app/components/plugins/install-plugin/install-from-local-package/index.tsx +++ b/web/app/components/plugins/install-plugin/install-from-local-package/index.tsx @@ -83,6 +83,7 @@ const InstallFromLocalPackage: React.FC = ({ { step === InstallStep.readyToInstall && ( void onInstalled: () => void @@ -20,6 +22,7 @@ type Props = { } const Installed: FC = ({ + uniqueIdentifier, payload, onCancel, onInstalled, @@ -31,9 +34,14 @@ const Installed: FC = ({ const handleInstall = async () => { if (isInstalling) return setIsInstalling(true) + try { + await installPackageFromLocal(uniqueIdentifier) + onInstalled() + } + catch (e) { + onFailed() + } await sleep(1500) - // onInstalled() - onFailed() } return ( diff --git a/web/app/components/plugins/install-plugin/install-from-local-package/steps/uploading.tsx b/web/app/components/plugins/install-plugin/install-from-local-package/steps/uploading.tsx index 50b23ca9f0..d9fa05ff21 100644 --- a/web/app/components/plugins/install-plugin/install-from-local-package/steps/uploading.tsx +++ b/web/app/components/plugins/install-plugin/install-from-local-package/steps/uploading.tsx @@ -30,14 +30,18 @@ const Uploading: FC = ({ 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, + }) } } } diff --git a/web/service/plugins.ts b/web/service/plugins.ts index dfee63009b..f1d6f8e223 100644 --- a/web/service/plugins.ts +++ b/web/service/plugins.ts @@ -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('/workspaces/current/plugin/install/pkg', { + body: { plugin_unique_identifiers: [uniqueIdentifier] }, + }) +}