feat: download pkg from marketplace (#9184)

This commit is contained in:
Junyan Qin 2024-10-11 02:00:02 +08:00 committed by GitHub
parent 118fa66567
commit b58f8dd7b4
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 41 additions and 3 deletions

View File

@ -297,4 +297,7 @@ PLUGIN_API_KEY=lYkiYYT6owG+71oLerGzA7GXCgOT++6ovaezWAjpCjf+Sjc3ZtU+qUEi+vRjI/+Xb
PLUGIN_API_URL=http://127.0.0.1:5002
PLUGIN_REMOTE_INSTALL_PORT=5003
PLUGIN_REMOTE_INSTALL_HOST=localhost
INNER_API_KEY=QaHbTe77CtuXmsfyhR7+vRjI/+XbV1AaFy691iy+kGDv2Jvy0/eAh8Y1
INNER_API_KEY=QaHbTe77CtuXmsfyhR7+vRjI/+XbV1AaFy691iy+kGDv2Jvy0/eAh8Y1
# Marketplace configuration
MARKETPLACE_API_URL=https://marketplace.dify.ai

View File

@ -137,6 +137,16 @@ class PluginConfig(BaseSettings):
default=5003,
)
class MarketplaceConfig(BaseSettings):
"""
Configuration for marketplace
"""
MARKETPLACE_API_URL: HttpUrl = Field(
description="Marketplace API URL",
default="https://marketplace.dify.ai",
)
class EndpointConfig(BaseSettings):
"""
@ -636,6 +646,7 @@ class FeatureConfig(
BillingConfig,
CodeExecutionSandboxConfig,
PluginConfig,
MarketplaceConfig,
DataSetConfig,
EndpointConfig,
FileAccessConfig,

View File

@ -0,0 +1,13 @@
from yarl import URL
from configs import dify_config
from core.helper.download import download_with_size_limit
def get_plugin_pkg_url(plugin_unique_identifier: str):
return (URL(str(dify_config.MARKETPLACE_API_URL)) / "api/v1/plugins/download").with_query(unique_identifier=plugin_unique_identifier)
def download_plugin_pkg(plugin_unique_identifier: str):
url = str(get_plugin_pkg_url(plugin_unique_identifier))
return download_with_size_limit(url, 15 * 1024 * 1024)

View File

@ -2,6 +2,7 @@ from collections.abc import Generator
from mimetypes import guess_type
from core.helper.download import download_with_size_limit
from core.helper.marketplace import download_plugin_pkg
from core.plugin.entities.plugin import PluginEntity, PluginInstallationSource
from core.plugin.entities.plugin_daemon import InstallPluginMessage, PluginDaemonInnerError
from core.plugin.manager.asset import PluginAssetManager
@ -83,7 +84,7 @@ class PluginService:
"""
manager = PluginInstallationManager()
pkg = b""
pkg = download_plugin_pkg(plugin_unique_identifier)
try:
yield from manager.install_from_pkg(

View File

@ -87,4 +87,7 @@ ZHINAO_API_KEY=
# Plugin configuration
PLUGIN_API_KEY=
PLUGIN_API_URL=
INNER_API_KEY=
INNER_API_KEY=
# Marketplace configuration
MARKETPLACE_API_URL=

View File

@ -0,0 +1,7 @@
from core.helper.marketplace import download_plugin_pkg
def test_download_plugin_pkg():
pkg = download_plugin_pkg("yeuoly/google:0.0.1@4ff79ee644987e5b744d9c5b7a735d459fe66f26b28724326a7834d7e459e708")
assert pkg is not None
assert len(pkg) > 0