|
@@ -7,7 +7,6 @@ import (
|
|
"mime/multipart"
|
|
"mime/multipart"
|
|
|
|
|
|
"github.com/gin-gonic/gin"
|
|
"github.com/gin-gonic/gin"
|
|
- "github.com/langgenius/dify-plugin-daemon/internal/core/plugin_manager"
|
|
|
|
"github.com/langgenius/dify-plugin-daemon/internal/core/plugin_packager/decoder"
|
|
"github.com/langgenius/dify-plugin-daemon/internal/core/plugin_packager/decoder"
|
|
"github.com/langgenius/dify-plugin-daemon/internal/core/plugin_packager/verifier"
|
|
"github.com/langgenius/dify-plugin-daemon/internal/core/plugin_packager/verifier"
|
|
"github.com/langgenius/dify-plugin-daemon/internal/db"
|
|
"github.com/langgenius/dify-plugin-daemon/internal/db"
|
|
@@ -16,49 +15,78 @@ import (
|
|
"github.com/langgenius/dify-plugin-daemon/internal/types/entities/plugin_entities"
|
|
"github.com/langgenius/dify-plugin-daemon/internal/types/entities/plugin_entities"
|
|
"github.com/langgenius/dify-plugin-daemon/internal/types/models"
|
|
"github.com/langgenius/dify-plugin-daemon/internal/types/models"
|
|
"github.com/langgenius/dify-plugin-daemon/internal/types/models/curd"
|
|
"github.com/langgenius/dify-plugin-daemon/internal/types/models/curd"
|
|
- "github.com/langgenius/dify-plugin-daemon/internal/utils/stream"
|
|
|
|
)
|
|
)
|
|
|
|
|
|
-func InstallPluginFromPkg(
|
|
|
|
|
|
+func UploadPluginFromPkg(
|
|
config *app.Config,
|
|
config *app.Config,
|
|
c *gin.Context,
|
|
c *gin.Context,
|
|
tenant_id string,
|
|
tenant_id string,
|
|
dify_pkg_file multipart.File,
|
|
dify_pkg_file multipart.File,
|
|
verify_signature bool,
|
|
verify_signature bool,
|
|
- source string,
|
|
|
|
- meta map[string]any,
|
|
|
|
-) {
|
|
|
|
- manager := plugin_manager.Manager()
|
|
|
|
-
|
|
|
|
|
|
+) *entities.Response {
|
|
plugin_file, err := io.ReadAll(dify_pkg_file)
|
|
plugin_file, err := io.ReadAll(dify_pkg_file)
|
|
if err != nil {
|
|
if err != nil {
|
|
- c.JSON(200, entities.NewErrorResponse(-500, err.Error()))
|
|
|
|
- return
|
|
|
|
|
|
+ return entities.NewErrorResponse(-500, err.Error())
|
|
}
|
|
}
|
|
|
|
|
|
decoder, err := decoder.NewZipPluginDecoder(plugin_file)
|
|
decoder, err := decoder.NewZipPluginDecoder(plugin_file)
|
|
if err != nil {
|
|
if err != nil {
|
|
- c.JSON(200, entities.NewErrorResponse(-500, err.Error()))
|
|
|
|
- return
|
|
|
|
|
|
+ return entities.NewErrorResponse(-500, err.Error())
|
|
}
|
|
}
|
|
|
|
|
|
if config.ForceVerifyingSignature || verify_signature {
|
|
if config.ForceVerifyingSignature || verify_signature {
|
|
err := verifier.VerifyPlugin(decoder)
|
|
err := verifier.VerifyPlugin(decoder)
|
|
if err != nil {
|
|
if err != nil {
|
|
- c.JSON(200, entities.NewErrorResponse(-500, errors.Join(err, errors.New(
|
|
|
|
|
|
+ return entities.NewErrorResponse(-500, errors.Join(err, errors.New(
|
|
"plugin verification has been enabled, and the plugin you want to install has a bad signature",
|
|
"plugin verification has been enabled, and the plugin you want to install has a bad signature",
|
|
- )).Error()))
|
|
|
|
- return
|
|
|
|
|
|
+ )).Error())
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- baseSSEService(
|
|
|
|
- func() (*stream.Stream[plugin_manager.PluginInstallResponse], error) {
|
|
|
|
- return manager.Install(tenant_id, decoder, source, meta)
|
|
|
|
- },
|
|
|
|
- c,
|
|
|
|
- 3600,
|
|
|
|
- )
|
|
|
|
|
|
+ manifest, err := decoder.Manifest()
|
|
|
|
+ if err != nil {
|
|
|
|
+ return entities.NewErrorResponse(-500, err.Error())
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return entities.NewSuccessResponse(manifest.Identity())
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+func InstallPluginFromIdentifiers(
|
|
|
|
+ tenant_id string,
|
|
|
|
+ plugin_unique_identifiers []plugin_entities.PluginUniqueIdentifier,
|
|
|
|
+ source string,
|
|
|
|
+ meta map[string]any,
|
|
|
|
+) *entities.Response {
|
|
|
|
+ // TODO: create installation task and dispatch to workers
|
|
|
|
+ for _, plugin_unique_identifier := range plugin_unique_identifiers {
|
|
|
|
+ if err := InstallPluginFromIdentifier(tenant_id, plugin_unique_identifier, source, meta); err != nil {
|
|
|
|
+ return entities.NewErrorResponse(-500, err.Error())
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return entities.NewSuccessResponse(true)
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+func FetchPluginInstallationTasks(
|
|
|
|
+ tenant_id string,
|
|
|
|
+ page int,
|
|
|
|
+ page_size int,
|
|
|
|
+) *entities.Response {
|
|
|
|
+ return nil
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+func FetchPluginInstallationTask(
|
|
|
|
+ tenant_id string,
|
|
|
|
+ task_id string,
|
|
|
|
+) *entities.Response {
|
|
|
|
+ return nil
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+func FetchPluginManifest(
|
|
|
|
+ tenant_id string,
|
|
|
|
+ plugin_unique_identifier plugin_entities.PluginUniqueIdentifier,
|
|
|
|
+) *entities.Response {
|
|
|
|
+ return nil
|
|
}
|
|
}
|
|
|
|
|
|
func InstallPluginFromIdentifier(
|
|
func InstallPluginFromIdentifier(
|
|
@@ -66,29 +94,30 @@ func InstallPluginFromIdentifier(
|
|
plugin_unique_identifier plugin_entities.PluginUniqueIdentifier,
|
|
plugin_unique_identifier plugin_entities.PluginUniqueIdentifier,
|
|
source string,
|
|
source string,
|
|
meta map[string]any,
|
|
meta map[string]any,
|
|
-) *entities.Response {
|
|
|
|
|
|
+) error {
|
|
|
|
+ // TODO: refactor
|
|
// check if identifier exists
|
|
// check if identifier exists
|
|
plugin, err := db.GetOne[models.Plugin](
|
|
plugin, err := db.GetOne[models.Plugin](
|
|
db.Equal("plugin_unique_identifier", plugin_unique_identifier.String()),
|
|
db.Equal("plugin_unique_identifier", plugin_unique_identifier.String()),
|
|
)
|
|
)
|
|
if err == db.ErrDatabaseNotFound {
|
|
if err == db.ErrDatabaseNotFound {
|
|
- return entities.NewErrorResponse(-404, "Plugin not found")
|
|
|
|
|
|
+ return errors.New("plugin not found")
|
|
}
|
|
}
|
|
if err != nil {
|
|
if err != nil {
|
|
- return entities.NewErrorResponse(-500, err.Error())
|
|
|
|
|
|
+ return err
|
|
}
|
|
}
|
|
|
|
|
|
if plugin.InstallType == plugin_entities.PLUGIN_RUNTIME_TYPE_REMOTE {
|
|
if plugin.InstallType == plugin_entities.PLUGIN_RUNTIME_TYPE_REMOTE {
|
|
- return entities.NewErrorResponse(-500, "remote plugin not supported")
|
|
|
|
|
|
+ return errors.New("remote plugin not supported")
|
|
}
|
|
}
|
|
|
|
|
|
declaration := plugin.Declaration
|
|
declaration := plugin.Declaration
|
|
// install to this workspace
|
|
// install to this workspace
|
|
if _, _, err := curd.InstallPlugin(tenant_id, plugin_unique_identifier, plugin.InstallType, &declaration, source, meta); err != nil {
|
|
if _, _, err := curd.InstallPlugin(tenant_id, plugin_unique_identifier, plugin.InstallType, &declaration, source, meta); err != nil {
|
|
- return entities.NewErrorResponse(-500, err.Error())
|
|
|
|
|
|
+ return err
|
|
}
|
|
}
|
|
|
|
|
|
- return entities.NewSuccessResponse(true)
|
|
|
|
|
|
+ return nil
|
|
}
|
|
}
|
|
|
|
|
|
func FetchPluginFromIdentifier(
|
|
func FetchPluginFromIdentifier(
|