Merge remote-tracking branch 'origin/upstream/main' into patch/images-edits

This commit is contained in:
Laisky.Cai
2024-07-24 02:42:16 +00:00
40 changed files with 1002 additions and 247 deletions

View File

@@ -140,6 +140,12 @@ func TokenAuth() func(c *gin.Context) {
return
}
}
// set channel id for proxy relay
if channelId := c.Param("channelid"); channelId != "" {
c.Set(ctxkey.SpecificChannelId, channelId)
}
c.Next()
}
}

View File

@@ -3,11 +3,12 @@ package middleware
import (
"context"
"fmt"
"net/http"
"time"
"github.com/gin-gonic/gin"
"github.com/songquanpeng/one-api/common"
"github.com/songquanpeng/one-api/common/config"
"net/http"
"time"
)
var timeFormat = "2006-01-02T15:04:05.000Z"
@@ -70,6 +71,11 @@ func memoryRateLimiter(c *gin.Context, maxRequestNum int, duration int64, mark s
}
func rateLimitFactory(maxRequestNum int, duration int64, mark string) func(c *gin.Context) {
if maxRequestNum == 0 {
return func(c *gin.Context) {
c.Next()
}
}
if common.RedisEnabled {
return func(c *gin.Context) {
redisRateLimiter(c, maxRequestNum, duration, mark)