Skip to content

Commit

Permalink
fix: multi user channel del
Browse files Browse the repository at this point in the history
  • Loading branch information
deanxv committed Feb 22, 2024
1 parent e04045e commit 7ad9ee0
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 3 deletions.
2 changes: 1 addition & 1 deletion common/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ var StreamRequestOutTime = os.Getenv("STREAM_REQUEST_OUT_TIME")

var DebugEnabled = os.Getenv("DEBUG") == "true"

var Version = "v4.1.0" // this hard coding will be replaced automatically when building, no need to manually change
var Version = "v4.1.1" // this hard coding will be replaced automatically when building, no need to manually change

const (
RequestIdKey = "X-Request-Id"
Expand Down
26 changes: 26 additions & 0 deletions controller/chat.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,19 @@ import (
// @Router /v1/chat/completions [post]
func ChatForOpenAI(c *gin.Context) {

// 校验有效用户token
if len(discord.UserAuthorizations) == 0 {
common.LogError(c.Request.Context(), fmt.Sprintf("无可用的 user_auth"))
c.JSON(http.StatusOK, model.OpenAIErrorResponse{
OpenAIError: model.OpenAIError{
Message: "no_available_user_auth",
Type: "invalid_request_error",
Code: "invalid_parameter",
},
})
return
}

var request model.OpenAIChatCompletionRequest
err := json.NewDecoder(c.Request.Body).Decode(&request)
if err != nil {
Expand Down Expand Up @@ -349,6 +362,19 @@ func buildOpenAIGPT4VForImageContent(sendChannelId string, objs []interface{}) (
// @Router /v1/images/generations [post]
func ImagesForOpenAI(c *gin.Context) {

// 校验有效用户token
if len(discord.UserAuthorizations) == 0 {
common.LogError(c.Request.Context(), fmt.Sprintf("无可用的 user_auth"))
c.JSON(http.StatusOK, model.OpenAIErrorResponse{
OpenAIError: model.OpenAIError{
Message: "no_available_user_auth",
Type: "invalid_request_error",
Code: "invalid_parameter",
},
})
return
}

var request model.OpenAIImagesGenerationRequest
err := json.NewDecoder(c.Request.Body).Decode(&request)
if err != nil {
Expand Down
5 changes: 3 additions & 2 deletions discord/message.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,9 @@ func SendMsgByAuthorization(c *gin.Context, content, channelId string) (string,
common.LogWarn(c.Request.Context(), fmt.Sprintf("USER_AUTHORIZATION:%s 已失效", auth))
UserAuthorizations = common.FilterSlice(UserAuthorizations, auth)
if len(UserAuthorizations) == 0 {
common.FatalLog(fmt.Sprintf("USER_AUTHORIZATION 无效"))
//return "", fmt.Errorf("USER_AUTHORIZATION 无效")
//common.FatalLog(fmt.Sprintf("USER_AUTHORIZATION 无效"))
ChannelDel(channelId)
return "", fmt.Errorf("USER_AUTHORIZATION 无效")
}
return SendMsgByAuthorization(c, content, channelId)
}
Expand Down

0 comments on commit 7ad9ee0

Please sign in to comment.