2024-10-25 13:52:33 +08:00
|
|
|
from collections.abc import Sequence
|
|
|
|
|
|
|
|
import requests
|
2024-10-11 02:00:02 +08:00
|
|
|
from yarl import URL
|
|
|
|
|
|
|
|
from configs import dify_config
|
|
|
|
from core.helper.download import download_with_size_limit
|
2024-10-25 13:52:33 +08:00
|
|
|
from core.plugin.entities.marketplace import MarketplacePluginDeclaration
|
2024-10-11 02:00:02 +08:00
|
|
|
|
|
|
|
|
|
|
|
def get_plugin_pkg_url(plugin_unique_identifier: str):
|
2024-10-17 18:44:16 +08:00
|
|
|
return (URL(str(dify_config.MARKETPLACE_API_URL)) / "api/v1/plugins/download").with_query(
|
|
|
|
unique_identifier=plugin_unique_identifier
|
|
|
|
)
|
2024-10-11 02:00:02 +08:00
|
|
|
|
|
|
|
|
|
|
|
def download_plugin_pkg(plugin_unique_identifier: str):
|
|
|
|
url = str(get_plugin_pkg_url(plugin_unique_identifier))
|
2024-10-17 18:44:16 +08:00
|
|
|
return download_with_size_limit(url, dify_config.PLUGIN_MAX_PACKAGE_SIZE)
|
2024-10-25 13:52:33 +08:00
|
|
|
|
|
|
|
|
|
|
|
def batch_fetch_plugin_manifests(plugin_ids: list[str]) -> Sequence[MarketplacePluginDeclaration]:
|
|
|
|
if len(plugin_ids) == 0:
|
|
|
|
return []
|
|
|
|
|
|
|
|
url = str(URL(str(dify_config.MARKETPLACE_API_URL)) / "api/v1/plugins/batch")
|
|
|
|
response = requests.get(url, json={"plugin_ids": plugin_ids})
|
|
|
|
response.raise_for_status()
|
|
|
|
return [MarketplacePluginDeclaration(**plugin) for plugin in response.json()["plugins"]]
|