feat: download pkg from marketplace (#9184)

pull/12372/head
Junyan Qin 2 years ago committed by GitHub
parent 118fa66567
commit b58f8dd7b4
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -297,4 +297,7 @@ PLUGIN_API_KEY=lYkiYYT6owG+71oLerGzA7GXCgOT++6ovaezWAjpCjf+Sjc3ZtU+qUEi+vRjI/+Xb
PLUGIN_API_URL=http://127.0.0.1:5002 PLUGIN_API_URL=http://127.0.0.1:5002
PLUGIN_REMOTE_INSTALL_PORT=5003 PLUGIN_REMOTE_INSTALL_PORT=5003
PLUGIN_REMOTE_INSTALL_HOST=localhost 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

@ -137,6 +137,16 @@ class PluginConfig(BaseSettings):
default=5003, 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): class EndpointConfig(BaseSettings):
""" """
@ -636,6 +646,7 @@ class FeatureConfig(
BillingConfig, BillingConfig,
CodeExecutionSandboxConfig, CodeExecutionSandboxConfig,
PluginConfig, PluginConfig,
MarketplaceConfig,
DataSetConfig, DataSetConfig,
EndpointConfig, EndpointConfig,
FileAccessConfig, FileAccessConfig,

@ -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)

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

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

@ -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
Loading…
Cancel
Save