From 634cb6233ea6823e5cf56b849f8bcdd231550bc2 Mon Sep 17 00:00:00 2001 From: Yeuoly Date: Fri, 15 Nov 2024 00:47:25 +0800 Subject: [PATCH] feat: sypport batch fetch plugin installations --- api/controllers/console/workspace/plugin.py | 16 ++++++++++++++++ api/core/plugin/entities/plugin.py | 4 +++- api/core/plugin/manager/plugin.py | 4 +++- api/services/plugin/plugin_service.py | 10 +++++++++- 4 files changed, 31 insertions(+), 3 deletions(-) diff --git a/api/controllers/console/workspace/plugin.py b/api/controllers/console/workspace/plugin.py index b2cbe0ce3b..099c193e47 100644 --- a/api/controllers/console/workspace/plugin.py +++ b/api/controllers/console/workspace/plugin.py @@ -41,6 +41,21 @@ class PluginListApi(Resource): return jsonable_encoder({"plugins": plugins}) +class PluginListInstallationsFromIdsApi(Resource): + @setup_required + @login_required + @account_initialization_required + def post(self): + tenant_id = current_user.current_tenant_id + + parser = reqparse.RequestParser() + parser.add_argument("plugin_ids", type=list, required=True, location="json") + args = parser.parse_args() + + plugins = PluginService.list_installations_from_ids(tenant_id, args["plugin_ids"]) + return jsonable_encoder({"plugins": plugins}) + + class PluginIconApi(Resource): @setup_required def get(self): @@ -363,6 +378,7 @@ class PluginFetchPermissionApi(Resource): api.add_resource(PluginDebuggingKeyApi, "/workspaces/current/plugin/debugging-key") api.add_resource(PluginListApi, "/workspaces/current/plugin/list") +api.add_resource(PluginListInstallationsFromIdsApi, "/workspaces/current/plugin/list/installations/ids") api.add_resource(PluginIconApi, "/workspaces/current/plugin/icon") api.add_resource(PluginUploadFromPkgApi, "/workspaces/current/plugin/upload/pkg") api.add_resource(PluginUploadFromGithubApi, "/workspaces/current/plugin/upload/github") diff --git a/api/core/plugin/entities/plugin.py b/api/core/plugin/entities/plugin.py index b2fad58fc4..a374e647c7 100644 --- a/api/core/plugin/entities/plugin.py +++ b/api/core/plugin/entities/plugin.py @@ -105,11 +105,13 @@ class PluginInstallation(BasePluginEntity): meta: Mapping[str, Any] plugin_id: str plugin_unique_identifier: str + version: str + checksum: str + declaration: PluginDeclaration class PluginEntity(PluginInstallation): name: str - declaration: PluginDeclaration installation_id: str version: str latest_version: Optional[str] = None diff --git a/api/core/plugin/manager/plugin.py b/api/core/plugin/manager/plugin.py index a3592c0c9e..2ae3004281 100644 --- a/api/core/plugin/manager/plugin.py +++ b/api/core/plugin/manager/plugin.py @@ -151,7 +151,9 @@ class PluginInstallationManager(BasePluginManager): params={"plugin_unique_identifier": plugin_unique_identifier}, ).declaration - def fetch_plugin_installation_by_ids(self, tenant_id: str, plugin_ids: Sequence[str]) -> list[PluginInstallation]: + def fetch_plugin_installation_by_ids( + self, tenant_id: str, plugin_ids: Sequence[str] + ) -> Sequence[PluginInstallation]: """ Fetch plugin installations by ids. """ diff --git a/api/services/plugin/plugin_service.py b/api/services/plugin/plugin_service.py index 8519d06acc..64687ef69c 100644 --- a/api/services/plugin/plugin_service.py +++ b/api/services/plugin/plugin_service.py @@ -7,7 +7,7 @@ from core.helper import marketplace from core.helper.download import download_with_size_limit from core.helper.marketplace import download_plugin_pkg from core.plugin.entities.bundle import PluginBundleDependency -from core.plugin.entities.plugin import PluginDeclaration, PluginEntity, PluginInstallationSource +from core.plugin.entities.plugin import PluginDeclaration, PluginEntity, PluginInstallation, PluginInstallationSource from core.plugin.entities.plugin_daemon import PluginInstallTask, PluginUploadResponse from core.plugin.manager.asset import PluginAssetManager from core.plugin.manager.debugging import PluginDebuggingManager @@ -50,6 +50,14 @@ class PluginService: return plugins + @staticmethod + def list_installations_from_ids(tenant_id: str, ids: Sequence[str]) -> Sequence[PluginInstallation]: + """ + List plugin installations from ids + """ + manager = PluginInstallationManager() + return manager.fetch_plugin_installation_by_ids(tenant_id, ids) + @staticmethod def get_asset(tenant_id: str, asset_file: str) -> tuple[bytes, str]: """