install.go 1001 B

1234567891011121314151617181920212223242526272829303132333435363738
  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_manager/installer"
  8. "github.com/langgenius/dify-plugin-daemon/internal/core/plugin_packager/decoder"
  9. "github.com/langgenius/dify-plugin-daemon/internal/types/entities"
  10. "github.com/langgenius/dify-plugin-daemon/internal/utils/stream"
  11. )
  12. func InstallPlugin(c *gin.Context, dify_pkg_file multipart.File) {
  13. plugin_manager := plugin_manager.Manager()
  14. plugin_file, err := io.ReadAll(dify_pkg_file)
  15. if err != nil {
  16. c.JSON(200, entities.NewErrorResponse(-500, err.Error()))
  17. return
  18. }
  19. decoder, err := decoder.NewZipPluginDecoder(plugin_file)
  20. if err != nil {
  21. c.JSON(200, entities.NewErrorResponse(-500, err.Error()))
  22. return
  23. }
  24. baseSSEService(
  25. func() (*stream.Stream[installer.PluginInstallResponse], error) {
  26. return plugin_manager.Install(decoder)
  27. },
  28. c,
  29. 3600,
  30. )
  31. }