Skip to content

Commit

Permalink
fix: check secret
Browse files Browse the repository at this point in the history
  • Loading branch information
xjd committed Jan 31, 2024
1 parent b775517 commit 9bef757
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,8 @@ services:
- BOT_TOKEN=MTE5OTk2xxxxxxxxxxxxxxrwUrUWNbG63w # 必须修改为我们主动发送消息的Bot-Token
- GUILD_ID=119xxxxxxxx796 # 必须修改为两个机器人所在的服务器ID
- COZE_BOT_ID=119xxxxxxxx7 # 必须修改为由coze托管的机器人ID
- CHANNEL_ID=119xxxxxx24 # 默认频道-在使用与openai对齐的接口时(/v1/chat/completions) 消息会默认发送到此频道
- PROXY_SECRET=123456 # [可选]接口密钥-修改此行为请求头校验的值(多个请以,分隔)
- CHANNEL_ID=119xxxxxx24 # [可选]默认频道-在使用与openai对齐的接口时(/v1/chat/completions) 消息会默认发送到此频道
- TZ=Asia/Shanghai
```

Expand Down
11 changes: 8 additions & 3 deletions controller/chat.go
Original file line number Diff line number Diff line change
Expand Up @@ -469,14 +469,19 @@ func ImagesForOpenAI(c *gin.Context) {
}

func getSendChannelIdAndCozeBotId(c *gin.Context, isOpenAIAPI bool, request model.ChannelIdentifier) (sendChannelId string, calledCozeBotId string, err error) {
var secret string
secret := ""
if isOpenAIAPI {
secret = c.Request.Header.Get("Authorization")
secret = strings.Replace(secret, "Bearer ", "", 1)
if secret = c.Request.Header.Get("Authorization"); secret != "" {
secret = strings.Replace(secret, "Bearer ", "", 1)
}
} else {
secret = c.Request.Header.Get("proxy-secret")
}

if secret == "" {
return discord.ChannelId, discord.CozeBotId, nil
}

// botConfigs不为空
if len(discord.BotConfigList) != 0 {

Expand Down

0 comments on commit 9bef757

Please sign in to comment.