|
@@ -1,6 +1,7 @@
|
|
|
package service
|
|
|
|
|
|
import (
|
|
|
+ "errors"
|
|
|
"time"
|
|
|
|
|
|
"github.com/langgenius/dify-plugin-daemon/internal/db"
|
|
@@ -83,8 +84,16 @@ func ListPlugins(tenant_id string, page int, page_size int) *entities.Response {
|
|
|
|
|
|
// Using plugin_ids to fetch plugin installations
|
|
|
func BatchFetchPluginInstallationByIDs(tenant_id string, plugin_ids []string) *entities.Response {
|
|
|
+ type installation struct {
|
|
|
+ models.PluginInstallation
|
|
|
+
|
|
|
+ Version manifest_entities.Version `json:"version"`
|
|
|
+ Checksum string `json:"checksum"`
|
|
|
+ Declaration *plugin_entities.PluginDeclaration `json:"declaration"`
|
|
|
+ }
|
|
|
+
|
|
|
if len(plugin_ids) == 0 {
|
|
|
- return entities.NewSuccessResponse([]models.PluginInstallation{})
|
|
|
+ return entities.NewSuccessResponse([]installation{})
|
|
|
}
|
|
|
|
|
|
pluginInstallations, err := db.GetAll[models.PluginInstallation](
|
|
@@ -97,7 +106,35 @@ func BatchFetchPluginInstallationByIDs(tenant_id string, plugin_ids []string) *e
|
|
|
return entities.NewErrorResponse(-500, err.Error())
|
|
|
}
|
|
|
|
|
|
- return entities.NewSuccessResponse(pluginInstallations)
|
|
|
+ data := make([]installation, 0, len(pluginInstallations))
|
|
|
+
|
|
|
+ for _, plugin_installation := range pluginInstallations {
|
|
|
+ pluginUniqueIdentifier, err := plugin_entities.NewPluginUniqueIdentifier(
|
|
|
+ plugin_installation.PluginUniqueIdentifier,
|
|
|
+ )
|
|
|
+
|
|
|
+ if err != nil {
|
|
|
+ return entities.NewErrorResponse(-500, errors.Join(errors.New("invalid plugin unique identifier found"), err).Error())
|
|
|
+ }
|
|
|
+
|
|
|
+ pluginDeclaration, err := helper.CombinedGetPluginDeclaration(
|
|
|
+ pluginUniqueIdentifier,
|
|
|
+ tenant_id,
|
|
|
+ plugin_entities.PluginRuntimeType(plugin_installation.RuntimeType),
|
|
|
+ )
|
|
|
+ if err != nil {
|
|
|
+ return entities.NewErrorResponse(-500, errors.Join(errors.New("failed to get plugin declaration"), err).Error())
|
|
|
+ }
|
|
|
+
|
|
|
+ data = append(data, installation{
|
|
|
+ PluginInstallation: plugin_installation,
|
|
|
+ Version: pluginUniqueIdentifier.Version(),
|
|
|
+ Checksum: pluginUniqueIdentifier.Checksum(),
|
|
|
+ Declaration: pluginDeclaration,
|
|
|
+ })
|
|
|
+ }
|
|
|
+
|
|
|
+ return entities.NewSuccessResponse(data)
|
|
|
}
|
|
|
|
|
|
// check which plugin is missing
|