|
|
@@ -13,6 +13,7 @@ import (
|
|
|
"github.com/QuantumNous/new-api/model"
|
|
|
"github.com/QuantumNous/new-api/service"
|
|
|
"github.com/QuantumNous/new-api/setting/ratio_setting"
|
|
|
+ "github.com/QuantumNous/new-api/types"
|
|
|
|
|
|
"github.com/gin-contrib/sessions"
|
|
|
"github.com/gin-gonic/gin"
|
|
|
@@ -195,7 +196,7 @@ func TokenAuth() func(c *gin.Context) {
|
|
|
}
|
|
|
c.Request.Header.Set("Authorization", "Bearer "+key)
|
|
|
}
|
|
|
- // 检查path包含/v1/messages 或 /v1/models
|
|
|
+ // 检查path包含/v1/messages 或 /v1/models
|
|
|
if strings.Contains(c.Request.URL.Path, "/v1/messages") || strings.Contains(c.Request.URL.Path, "/v1/models") {
|
|
|
anthropicKey := c.Request.Header.Get("x-api-key")
|
|
|
if anthropicKey != "" {
|
|
|
@@ -256,7 +257,7 @@ func TokenAuth() func(c *gin.Context) {
|
|
|
return
|
|
|
}
|
|
|
if common.IsIpInCIDRList(ip, allowIps) == false {
|
|
|
- abortWithOpenAiMessage(c, http.StatusForbidden, "您的 IP 不在令牌允许访问的列表中")
|
|
|
+ abortWithOpenAiMessage(c, http.StatusForbidden, "您的 IP 不在令牌允许访问的列表中", types.ErrorCodeAccessDenied)
|
|
|
return
|
|
|
}
|
|
|
logger.LogDebug(c, "Client IP %s passed the token IP restrictions check", clientIp)
|