From b9f493bb31067ed63be86133dbe2f7932b63ec95 Mon Sep 17 00:00:00 2001 From: Harry-zklcdc Date: Fri, 2 Feb 2024 22:50:31 +0800 Subject: [PATCH] =?UTF-8?q?[Fix]=20=F0=9F=90=9B=20BingAPI=20Image=20Return?= =?UTF-8?q?=20Error=20when=20Prompt=20blank=20#327?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api/v1/image.go | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/api/v1/image.go b/api/v1/image.go index 2b9ed7f1ac..6d47819c19 100644 --- a/api/v1/image.go +++ b/api/v1/image.go @@ -65,6 +65,20 @@ func ImageHandler(w http.ResponseWriter, r *http.Request) { var resq imageRequest json.Unmarshal(resqB, &resq) + resp := imageResponse{ + Created: time.Now().Unix(), + } + + if resq.Prompt == "" { + resData, err := json.Marshal(resp) + if err != nil { + w.WriteHeader(http.StatusInternalServerError) + w.Write([]byte(err.Error())) + return + } + w.Write(resData) + } + imgs, _, err := image.Image(resq.Prompt) if err != nil { w.WriteHeader(http.StatusInternalServerError) @@ -72,9 +86,6 @@ func ImageHandler(w http.ResponseWriter, r *http.Request) { return } - resp := imageResponse{ - Created: time.Now().Unix(), - } for _, img := range imgs { resp.Data = append(resp.Data, imageData{ Url: img,