From 557aa3381e99235113e6400f9481c8d8f7be9c49 Mon Sep 17 00:00:00 2001 From: Abirdcfly Date: Wed, 27 Mar 2024 15:16:15 +0800 Subject: [PATCH] fix: app enableUploadFile cant set to false Signed-off-by: Abirdcfly --- api/base/v1alpha1/application_types.go | 2 +- api/base/v1alpha1/zz_generated.deepcopy.go | 7 ++++++- apiserver/pkg/application/application.go | 6 ++++-- apiserver/service/chat.go | 2 +- 4 files changed, 12 insertions(+), 5 deletions(-) diff --git a/api/base/v1alpha1/application_types.go b/api/base/v1alpha1/application_types.go index d9c031f03..7ecd13ca2 100644 --- a/api/base/v1alpha1/application_types.go +++ b/api/base/v1alpha1/application_types.go @@ -58,7 +58,7 @@ type WebConfig struct { ShowRetrievalInfo bool `json:"showRetrievalInfo,omitempty"` ShowNextGuide bool `json:"showNextGuide,omitempty"` // +kubebuilder:default:=true - EnableUploadFile bool `json:"enableUploadFile,omitempty"` + EnableUploadFile *bool `json:"enableUploadFile,omitempty"` } type Node struct { diff --git a/api/base/v1alpha1/zz_generated.deepcopy.go b/api/base/v1alpha1/zz_generated.deepcopy.go index a1e00dcfa..8979844a7 100644 --- a/api/base/v1alpha1/zz_generated.deepcopy.go +++ b/api/base/v1alpha1/zz_generated.deepcopy.go @@ -90,7 +90,7 @@ func (in *ApplicationList) DeepCopyObject() runtime.Object { func (in *ApplicationSpec) DeepCopyInto(out *ApplicationSpec) { *out = *in out.CommonSpec = in.CommonSpec - out.WebConfig = in.WebConfig + in.WebConfig.DeepCopyInto(&out.WebConfig) if in.Nodes != nil { in, out := &in.Nodes, &out.Nodes *out = make([]Node, len(*in)) @@ -1452,6 +1452,11 @@ func (in *Web) DeepCopy() *Web { // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *WebConfig) DeepCopyInto(out *WebConfig) { *out = *in + if in.EnableUploadFile != nil { + in, out := &in.EnableUploadFile, &out.EnableUploadFile + *out = new(bool) + **out = **in + } } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new WebConfig. diff --git a/apiserver/pkg/application/application.go b/apiserver/pkg/application/application.go index 3d9d5c956..fc5801de5 100644 --- a/apiserver/pkg/application/application.go +++ b/apiserver/pkg/application/application.go @@ -101,7 +101,7 @@ func cr2app(prompt *apiprompt.Prompt, chainConfig *apichain.CommonChainConfig, r ShowRetrievalInfo: pointer.Bool(app.Spec.ShowRetrievalInfo), DocNullReturn: pointer.String(app.Spec.DocNullReturn), ChatTimeout: pointer.Float64(app.Spec.ChatTimeoutSecond), - EnableUploadFile: pointer.Bool(app.Spec.EnableUploadFile), + EnableUploadFile: app.Spec.EnableUploadFile, } if prompt != nil { gApp.UserPrompt = pointer.String(prompt.Spec.UserMessage) @@ -741,7 +741,9 @@ func mutateApp(app *v1alpha1.Application, input generated.UpdateApplicationConfi app.Spec.ShowNextGuide = pointer.BoolDeref(input.ShowNextGuide, app.Spec.ShowNextGuide) app.Spec.DocNullReturn = pointer.StringDeref(input.DocNullReturn, app.Spec.DocNullReturn) app.Spec.ChatTimeoutSecond = pointer.Float64Deref(input.ChatTimeout, v1alpha1.DefaultChatTimeoutSeconds) - app.Spec.EnableUploadFile = pointer.BoolDeref(input.EnableUploadFile, app.Spec.EnableUploadFile) + if input.EnableUploadFile != nil { + app.Spec.EnableUploadFile = input.EnableUploadFile + } return nil } diff --git a/apiserver/service/chat.go b/apiserver/service/chat.go index fdfa05baa..33ca00d08 100644 --- a/apiserver/service/chat.go +++ b/apiserver/service/chat.go @@ -226,7 +226,7 @@ func (cs *ChatService) ChatFile() gin.HandlerFunc { c.JSON(http.StatusBadRequest, chat.ErrorResp{Err: err.Error()}) return } - if !app.Spec.EnableUploadFile { + if pointer.BoolDeref(app.Spec.EnableUploadFile, false) { c.JSON(http.StatusForbidden, chat.ErrorResp{Err: "file upload is not enabled"}) return }