mirror of
https://github.com/langgenius/dify.git
synced 2026-05-06 01:26:33 +08:00
feat: adapt to plugin_daemon endpoint
This commit is contained in:
parent
07d067d828
commit
ba76312248
@ -643,8 +643,30 @@ class PluginAutoUpgradeExcludePluginApi(Resource):
|
|||||||
return jsonable_encoder({"success": PluginAutoUpgradeService.exclude_plugin(tenant_id, args["plugin_id"])})
|
return jsonable_encoder({"success": PluginAutoUpgradeService.exclude_plugin(tenant_id, args["plugin_id"])})
|
||||||
|
|
||||||
|
|
||||||
|
class PluginReadmeApi(Resource):
|
||||||
|
@setup_required
|
||||||
|
@login_required
|
||||||
|
@account_initialization_required
|
||||||
|
def get(self):
|
||||||
|
tenant_id = current_user.current_tenant_id
|
||||||
|
parser = reqparse.RequestParser()
|
||||||
|
parser.add_argument("plugin_unique_identifier", type=str, required=True, location="args")
|
||||||
|
parser.add_argument("language", type=str, required=False, location="args")
|
||||||
|
args = parser.parse_args()
|
||||||
|
return jsonable_encoder(
|
||||||
|
{
|
||||||
|
"readme": PluginService.fetch_plugin_readme(
|
||||||
|
tenant_id,
|
||||||
|
args["plugin_unique_identifier"],
|
||||||
|
args.get("language", "en-US")
|
||||||
|
)
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
api.add_resource(PluginDebuggingKeyApi, "/workspaces/current/plugin/debugging-key")
|
api.add_resource(PluginDebuggingKeyApi, "/workspaces/current/plugin/debugging-key")
|
||||||
api.add_resource(PluginListApi, "/workspaces/current/plugin/list")
|
api.add_resource(PluginListApi, "/workspaces/current/plugin/list")
|
||||||
|
api.add_resource(PluginReadmeApi, "/workspaces/current/plugin/readme")
|
||||||
api.add_resource(PluginListLatestVersionsApi, "/workspaces/current/plugin/list/latest-versions")
|
api.add_resource(PluginListLatestVersionsApi, "/workspaces/current/plugin/list/latest-versions")
|
||||||
api.add_resource(PluginListInstallationsFromIdsApi, "/workspaces/current/plugin/list/installations/ids")
|
api.add_resource(PluginListInstallationsFromIdsApi, "/workspaces/current/plugin/list/installations/ids")
|
||||||
api.add_resource(PluginIconApi, "/workspaces/current/plugin/icon")
|
api.add_resource(PluginIconApi, "/workspaces/current/plugin/icon")
|
||||||
|
|||||||
@ -196,3 +196,7 @@ class PluginListResponse(BaseModel):
|
|||||||
|
|
||||||
class PluginDynamicSelectOptionsResponse(BaseModel):
|
class PluginDynamicSelectOptionsResponse(BaseModel):
|
||||||
options: Sequence[PluginParameterOption] = Field(description="The options of the dynamic select.")
|
options: Sequence[PluginParameterOption] = Field(description="The options of the dynamic select.")
|
||||||
|
|
||||||
|
class PluginReadmeResponse(BaseModel):
|
||||||
|
content: str = Field(description="The readme of the plugin.")
|
||||||
|
language: str = Field(description="The language of the readme.")
|
||||||
|
|||||||
@ -1,5 +1,7 @@
|
|||||||
from collections.abc import Sequence
|
from collections.abc import Sequence
|
||||||
|
|
||||||
|
from requests import HTTPError
|
||||||
|
|
||||||
from core.plugin.entities.bundle import PluginBundleDependency
|
from core.plugin.entities.bundle import PluginBundleDependency
|
||||||
from core.plugin.entities.plugin import (
|
from core.plugin.entities.plugin import (
|
||||||
GenericProviderID,
|
GenericProviderID,
|
||||||
@ -14,11 +16,34 @@ from core.plugin.entities.plugin_daemon import (
|
|||||||
PluginInstallTask,
|
PluginInstallTask,
|
||||||
PluginInstallTaskStartResponse,
|
PluginInstallTaskStartResponse,
|
||||||
PluginListResponse,
|
PluginListResponse,
|
||||||
|
PluginReadmeResponse,
|
||||||
)
|
)
|
||||||
from core.plugin.impl.base import BasePluginClient
|
from core.plugin.impl.base import BasePluginClient
|
||||||
|
|
||||||
|
|
||||||
class PluginInstaller(BasePluginClient):
|
class PluginInstaller(BasePluginClient):
|
||||||
|
def fetch_plugin_readme(self, tenant_id: str, plugin_unique_identifier: str, language: str) -> str:
|
||||||
|
"""
|
||||||
|
Fetch plugin readme
|
||||||
|
"""
|
||||||
|
try:
|
||||||
|
response = self._request_with_plugin_daemon_response(
|
||||||
|
"GET",
|
||||||
|
f"plugin/{tenant_id}/management/fetch/readme",
|
||||||
|
PluginReadmeResponse,
|
||||||
|
params={
|
||||||
|
"tenant_id":tenant_id,
|
||||||
|
"plugin_unique_identifier": plugin_unique_identifier,
|
||||||
|
"language": language
|
||||||
|
}
|
||||||
|
)
|
||||||
|
return response.content
|
||||||
|
except HTTPError as e:
|
||||||
|
message = e.args[0]
|
||||||
|
if "404" in message:
|
||||||
|
return ""
|
||||||
|
raise e
|
||||||
|
|
||||||
def fetch_plugin_by_identifier(
|
def fetch_plugin_by_identifier(
|
||||||
self,
|
self,
|
||||||
tenant_id: str,
|
tenant_id: str,
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user