install.go 934 B

12345678910111213141516171819202122232425262728293031323334353637
  1. package service
  2. import (
  3. "io"
  4. "mime/multipart"
  5. "github.com/gin-gonic/gin"
  6. "github.com/langgenius/dify-plugin-daemon/internal/core/plugin_manager"
  7. "github.com/langgenius/dify-plugin-daemon/internal/core/plugin_packager/decoder"
  8. "github.com/langgenius/dify-plugin-daemon/internal/types/entities"
  9. "github.com/langgenius/dify-plugin-daemon/internal/utils/stream"
  10. )
  11. func InstallPluginFromPkg(c *gin.Context, tenant_id string, dify_pkg_file multipart.File) {
  12. manager := plugin_manager.Manager()
  13. plugin_file, err := io.ReadAll(dify_pkg_file)
  14. if err != nil {
  15. c.JSON(200, entities.NewErrorResponse(-500, err.Error()))
  16. return
  17. }
  18. decoder, err := decoder.NewZipPluginDecoder(plugin_file)
  19. if err != nil {
  20. c.JSON(200, entities.NewErrorResponse(-500, err.Error()))
  21. return
  22. }
  23. baseSSEService(
  24. func() (*stream.Stream[plugin_manager.PluginInstallResponse], error) {
  25. return manager.Install(decoder)
  26. },
  27. c,
  28. 3600,
  29. )
  30. }