endpoint.go 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. package controllers
  2. import (
  3. "github.com/gin-gonic/gin"
  4. "github.com/langgenius/dify-plugin-daemon/internal/service"
  5. "github.com/langgenius/dify-plugin-daemon/internal/types/entities/plugin_entities"
  6. )
  7. func SetupEndpoint(ctx *gin.Context) {
  8. BindRequest(ctx, func(
  9. request struct {
  10. PluginUniqueIdentifier plugin_entities.PluginUniqueIdentifier `json:"plugin_unique_identifier" validate:"required,plugin_unique_identifier"`
  11. TenantID string `uri:"tenant_id" validate:"required"`
  12. UserID string `json:"user_id" validate:"required"`
  13. Settings map[string]any `json:"settings" validate:"omitempty"`
  14. },
  15. ) {
  16. tenant_id := request.TenantID
  17. user_id := request.UserID
  18. settings := request.Settings
  19. plugin_unique_identifier := request.PluginUniqueIdentifier
  20. ctx.JSON(200, service.SetupEndpoint(
  21. tenant_id, user_id, plugin_unique_identifier, settings,
  22. ))
  23. })
  24. }
  25. func ListEndpoints(ctx *gin.Context) {
  26. BindRequest(ctx, func(request struct {
  27. TenantID string `uri:"tenant_id" validate:"required"`
  28. Page int `form:"page" validate:"required"`
  29. PageSize int `form:"page_size" validate:"required,max=100"`
  30. }) {
  31. tenant_id := request.TenantID
  32. page := request.Page
  33. page_size := request.PageSize
  34. ctx.JSON(200, service.ListEndpoints(tenant_id, page, page_size))
  35. })
  36. }
  37. func ListPluginEndpoints(ctx *gin.Context) {
  38. BindRequest(ctx, func(request struct {
  39. TenantID string `uri:"tenant_id" validate:"required"`
  40. PluginUniqueIdentifier plugin_entities.PluginUniqueIdentifier `form:"plugin_unique_identifier" validate:"required,plugin_unique_identifier"`
  41. Page int `form:"page" validate:"required"`
  42. PageSize int `form:"page_size" validate:"required,max=100"`
  43. }) {
  44. tenant_id := request.TenantID
  45. plugin_unique_identifier := request.PluginUniqueIdentifier
  46. page := request.Page
  47. page_size := request.PageSize
  48. ctx.JSON(200, service.ListPluginEndpoints(tenant_id, plugin_unique_identifier, page, page_size))
  49. })
  50. }
  51. func RemoveEndpoint(ctx *gin.Context) {
  52. BindRequest(ctx, func(request struct {
  53. EndpointID string `json:"endpoint_id" validate:"required"`
  54. TenantID string `uri:"tenant_id" validate:"required"`
  55. }) {
  56. endpoint_id := request.EndpointID
  57. tenant_id := request.TenantID
  58. ctx.JSON(200, service.RemoveEndpoint(endpoint_id, tenant_id))
  59. })
  60. }
  61. func UpdateEndpoint(ctx *gin.Context) {
  62. BindRequest(ctx, func(request struct {
  63. EndpointID string `json:"endpoint_id" validate:"required"`
  64. TenantID string `uri:"tenant_id" validate:"required"`
  65. UserID string `json:"user_id" validate:"required"`
  66. Settings map[string]any `json:"settings" validate:"omitempty"`
  67. }) {
  68. tenant_id := request.TenantID
  69. user_id := request.UserID
  70. endpoint_id := request.EndpointID
  71. settings := request.Settings
  72. ctx.JSON(200, service.UpdateEndpoint(endpoint_id, tenant_id, user_id, settings))
  73. })
  74. }
  75. func EnableEndpoint(ctx *gin.Context) {
  76. BindRequest(ctx, func(request struct {
  77. EndpointID string `json:"endpoint_id" validate:"required"`
  78. TenantID string `uri:"tenant_id" validate:"required"`
  79. }) {
  80. tenant_id := request.TenantID
  81. endpoint_id := request.EndpointID
  82. ctx.JSON(200, service.EnableEndpoint(endpoint_id, tenant_id))
  83. })
  84. }
  85. func DisableEndpoint(ctx *gin.Context) {
  86. BindRequest(ctx, func(request struct {
  87. EndpointID string `json:"endpoint_id" validate:"required"`
  88. TenantID string `uri:"tenant_id" validate:"required"`
  89. }) {
  90. tenant_id := request.TenantID
  91. endpoint_id := request.EndpointID
  92. ctx.JSON(200, service.DisableEndpoint(endpoint_id, tenant_id))
  93. })
  94. }