From dd67f65a041cf022bbe09ad2cf30b8ceca940ee8 Mon Sep 17 00:00:00 2001 From: Yeuoly Date: Thu, 26 Sep 2024 14:48:53 +0800 Subject: [PATCH] fix: using validators to validate a map --- internal/core/dify_invocation/real/encrypt_test.go | 4 +++- internal/core/dify_invocation/real/http_request.go | 5 +++-- internal/core/dify_invocation/types.go | 5 +++++ 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/internal/core/dify_invocation/real/encrypt_test.go b/internal/core/dify_invocation/real/encrypt_test.go index 7ce9b0b9..af066972 100644 --- a/internal/core/dify_invocation/real/encrypt_test.go +++ b/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", + }, }) }) diff --git a/internal/core/dify_invocation/real/http_request.go b/internal/core/dify_invocation/real/http_request.go index e2be348e..47de15fd 100644 --- a/internal/core/dify_invocation/real/http_request.go +++ b/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 } diff --git a/internal/core/dify_invocation/types.go b/internal/core/dify_invocation/types.go index 330b26c8..a54b0fc8 100644 --- a/internal/core/dify_invocation/types.go +++ b/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"` +}