Преглед изворни кода

fix: using validators to validate a map

Yeuoly пре 10 месеци
родитељ
комит
dd67f65a04

+ 3 - 1
internal/core/dify_invocation/real/encrypt_test.go

@@ -76,7 +76,9 @@ func TestInvokeEncrypt(t *testing.T) {
 		http_invoked = true
 
 		ctx.JSON(http.StatusOK, gin.H{
-			"key": "encrypted",
+			"data": map[string]any{
+				"key": "encrypted",
+			},
 		})
 	})
 

+ 3 - 2
internal/core/dify_invocation/real/http_request.go

@@ -11,6 +11,7 @@ import (
 	"github.com/langgenius/dify-plugin-daemon/internal/utils/stream"
 )
 
+// Send a request to dify inner api and validate the response
 func Request[T any](i *RealBackwardsInvocation, method string, path string, options ...http_requests.HttpOptions) (*T, error) {
 	options = append(options,
 		http_requests.HttpHeader(map[string]string{
@@ -89,10 +90,10 @@ func (i *RealBackwardsInvocation) InvokeEncrypt(payload *dify_invocation.InvokeE
 		return payload.Data, nil
 	}
 
-	data, err := Request[map[string]any](i, "POST", "invoke/encrypt", http_requests.HttpPayloadJson(payload))
+	data, err := Request[dify_invocation.InvokeEncryptionResponse](i, "POST", "invoke/encrypt", http_requests.HttpPayloadJson(payload))
 	if err != nil {
 		return nil, err
 	}
 
-	return *data, nil
+	return data.Data, nil
 }

+ 5 - 0
internal/core/dify_invocation/types.go

@@ -212,3 +212,8 @@ type InvokeNodeResponse struct {
 	Outputs     map[string]any `json:"outputs" validate:"required"`
 	Inputs      map[string]any `json:"inputs" validate:"required"`
 }
+
+type InvokeEncryptionResponse struct {
+	Error string         `json:"error"`
+	Data  map[string]any `json:"data" validate:"required"`
+}