Skip to content

Commit

Permalink
[Fix] 🐛 BingAPI Image Return Error when Prompt blank #327
Browse files Browse the repository at this point in the history
  • Loading branch information
Harry-zklcdc committed Feb 2, 2024
1 parent c8062f4 commit b9f493b
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions api/v1/image.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,16 +65,27 @@ 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)
w.Write([]byte(err.Error()))
return
}

resp := imageResponse{
Created: time.Now().Unix(),
}
for _, img := range imgs {
resp.Data = append(resp.Data, imageData{
Url: img,
Expand Down

0 comments on commit b9f493b

Please sign in to comment.