mirror of
				https://github.com/songquanpeng/one-api.git
				synced 2025-11-04 07:43:41 +08:00 
			
		
		
		
	feat: support cloudflare now
This commit is contained in:
		@@ -1,13 +0,0 @@
 | 
			
		||||
package ctxkey
 | 
			
		||||
 | 
			
		||||
const (
 | 
			
		||||
	ConfigPrefix = "cfg_"
 | 
			
		||||
 | 
			
		||||
	ConfigAPIVersion = ConfigPrefix + "api_version"
 | 
			
		||||
	ConfigLibraryID  = ConfigPrefix + "library_id"
 | 
			
		||||
	ConfigPlugin     = ConfigPrefix + "plugin"
 | 
			
		||||
	ConfigSK         = ConfigPrefix + "sk"
 | 
			
		||||
	ConfigAK         = ConfigPrefix + "ak"
 | 
			
		||||
	ConfigRegion     = ConfigPrefix + "region"
 | 
			
		||||
	ConfigUserID     = ConfigPrefix + "user_id"
 | 
			
		||||
)
 | 
			
		||||
@@ -1,6 +1,7 @@
 | 
			
		||||
package ctxkey
 | 
			
		||||
 | 
			
		||||
const (
 | 
			
		||||
	Config            = "config"
 | 
			
		||||
	Id                = "id"
 | 
			
		||||
	Username          = "username"
 | 
			
		||||
	Role              = "role"
 | 
			
		||||
 
 | 
			
		||||
@@ -2,6 +2,7 @@ package helper
 | 
			
		||||
 | 
			
		||||
import (
 | 
			
		||||
	"fmt"
 | 
			
		||||
	"github.com/gin-gonic/gin"
 | 
			
		||||
	"github.com/songquanpeng/one-api/common/random"
 | 
			
		||||
	"html/template"
 | 
			
		||||
	"log"
 | 
			
		||||
@@ -105,6 +106,11 @@ func GenRequestID() string {
 | 
			
		||||
	return GetTimeString() + random.GetRandomNumberString(8)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func GetResponseID(c *gin.Context) string {
 | 
			
		||||
	logID := c.GetString(RequestIdKey)
 | 
			
		||||
	return fmt.Sprintf("chatcmpl-%s", logID)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func Max(a int, b int) int {
 | 
			
		||||
	if a >= b {
 | 
			
		||||
		return a
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										5
									
								
								common/helper/key.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										5
									
								
								common/helper/key.go
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,5 @@
 | 
			
		||||
package helper
 | 
			
		||||
 | 
			
		||||
const (
 | 
			
		||||
	RequestIdKey = "X-Oneapi-Request-Id"
 | 
			
		||||
)
 | 
			
		||||
@@ -1,7 +1,3 @@
 | 
			
		||||
package logger
 | 
			
		||||
 | 
			
		||||
const (
 | 
			
		||||
	RequestIdKey = "X-Oneapi-Request-Id"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
var LogDir string
 | 
			
		||||
 
 | 
			
		||||
@@ -87,7 +87,7 @@ func logHelper(ctx context.Context, level string, msg string) {
 | 
			
		||||
	if level == loggerINFO {
 | 
			
		||||
		writer = gin.DefaultWriter
 | 
			
		||||
	}
 | 
			
		||||
	id := ctx.Value(RequestIdKey)
 | 
			
		||||
	id := ctx.Value(helper.RequestIdKey)
 | 
			
		||||
	if id == nil {
 | 
			
		||||
		id = helper.GenRequestID()
 | 
			
		||||
	}
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user