plugins.go 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. package controllers
  2. import (
  3. "net/http"
  4. "github.com/gin-gonic/gin"
  5. "github.com/langgenius/dify-plugin-daemon/internal/core/plugin_manager"
  6. "github.com/langgenius/dify-plugin-daemon/internal/service"
  7. "github.com/langgenius/dify-plugin-daemon/internal/types/app"
  8. )
  9. func GetAsset(c *gin.Context) {
  10. plugin_manager := plugin_manager.Manager()
  11. asset, err := plugin_manager.GetAsset(c.Param("id"))
  12. if err != nil {
  13. c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
  14. return
  15. }
  16. c.Data(http.StatusOK, "application/octet-stream", asset)
  17. }
  18. func InstallPlugin(app *app.Config) gin.HandlerFunc {
  19. return func(c *gin.Context) {
  20. dify_pkg_file_header, err := c.FormFile("dify_pkg")
  21. if err != nil {
  22. c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
  23. return
  24. }
  25. if dify_pkg_file_header.Size > app.MaxPluginPackageSize {
  26. c.JSON(http.StatusRequestEntityTooLarge, gin.H{"error": "File size exceeds the maximum limit"})
  27. return
  28. }
  29. dify_pkg_file, err := dify_pkg_file_header.Open()
  30. if err != nil {
  31. c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
  32. return
  33. }
  34. defer dify_pkg_file.Close()
  35. service.InstallPlugin(c, dify_pkg_file)
  36. }
  37. }
  38. func UninstallPlugin(c *gin.Context) {
  39. }
  40. func ListPlugins(c *gin.Context) {
  41. }