feat: Allow skip channel id

This commit is contained in:
Martial BE
2024-04-28 11:22:43 +08:00
parent 317e0a6370
commit bc11c65c78
3 changed files with 21 additions and 13 deletions

View File

@@ -108,16 +108,20 @@ func tokenAuth(c *gin.Context, key string) {
c.Set("chat_cache", token.ChatCache)
if len(parts) > 1 {
if model.IsAdmin(token.UserId) {
channelId := common.String2Int(parts[1])
if channelId == 0 {
abortWithMessage(c, http.StatusForbidden, "无效的渠道 Id")
return
if strings.HasPrefix(parts[1], "!") {
channelId := common.String2Int(parts[1][1:])
c.Set("skip_channel_id", channelId)
} else {
channelId := common.String2Int(parts[1])
if channelId == 0 {
abortWithMessage(c, http.StatusForbidden, "无效的渠道 Id")
return
}
c.Set("specific_channel_id", channelId)
if len(parts) == 3 && parts[2] == "ignore" {
c.Set("specific_channel_id_ignore", true)
}
}
c.Set("specific_channel_id", channelId)
if len(parts) == 3 && parts[2] == "ignore" {
c.Set("specific_channel_id_ignore", true)
}
} else {
abortWithMessage(c, http.StatusForbidden, "普通用户不支持指定渠道")
return