mirror of
https://github.com/router-for-me/CLIProxyAPI.git
synced 2026-02-18 20:30:51 +08:00
feat(management): 支持管理接口调整日志大小/强制前缀/路由策略
This commit is contained in:
@@ -202,6 +202,26 @@ func (h *Handler) PutLoggingToFile(c *gin.Context) {
|
|||||||
h.updateBoolField(c, func(v bool) { h.cfg.LoggingToFile = v })
|
h.updateBoolField(c, func(v bool) { h.cfg.LoggingToFile = v })
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// LogsMaxTotalSizeMB
|
||||||
|
func (h *Handler) GetLogsMaxTotalSizeMB(c *gin.Context) {
|
||||||
|
c.JSON(200, gin.H{"logs-max-total-size-mb": h.cfg.LogsMaxTotalSizeMB})
|
||||||
|
}
|
||||||
|
func (h *Handler) PutLogsMaxTotalSizeMB(c *gin.Context) {
|
||||||
|
var body struct {
|
||||||
|
Value *int `json:"value"`
|
||||||
|
}
|
||||||
|
if errBindJSON := c.ShouldBindJSON(&body); errBindJSON != nil || body.Value == nil {
|
||||||
|
c.JSON(http.StatusBadRequest, gin.H{"error": "invalid body"})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
value := *body.Value
|
||||||
|
if value < 0 {
|
||||||
|
value = 0
|
||||||
|
}
|
||||||
|
h.cfg.LogsMaxTotalSizeMB = value
|
||||||
|
h.persist(c)
|
||||||
|
}
|
||||||
|
|
||||||
// Request log
|
// Request log
|
||||||
func (h *Handler) GetRequestLog(c *gin.Context) { c.JSON(200, gin.H{"request-log": h.cfg.RequestLog}) }
|
func (h *Handler) GetRequestLog(c *gin.Context) { c.JSON(200, gin.H{"request-log": h.cfg.RequestLog}) }
|
||||||
func (h *Handler) PutRequestLog(c *gin.Context) {
|
func (h *Handler) PutRequestLog(c *gin.Context) {
|
||||||
@@ -232,6 +252,52 @@ func (h *Handler) PutMaxRetryInterval(c *gin.Context) {
|
|||||||
h.updateIntField(c, func(v int) { h.cfg.MaxRetryInterval = v })
|
h.updateIntField(c, func(v int) { h.cfg.MaxRetryInterval = v })
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ForceModelPrefix
|
||||||
|
func (h *Handler) GetForceModelPrefix(c *gin.Context) {
|
||||||
|
c.JSON(200, gin.H{"force-model-prefix": h.cfg.ForceModelPrefix})
|
||||||
|
}
|
||||||
|
func (h *Handler) PutForceModelPrefix(c *gin.Context) {
|
||||||
|
h.updateBoolField(c, func(v bool) { h.cfg.ForceModelPrefix = v })
|
||||||
|
}
|
||||||
|
|
||||||
|
func normalizeRoutingStrategy(strategy string) (string, bool) {
|
||||||
|
normalized := strings.ToLower(strings.TrimSpace(strategy))
|
||||||
|
switch normalized {
|
||||||
|
case "", "round-robin", "roundrobin", "rr":
|
||||||
|
return "round-robin", true
|
||||||
|
case "fill-first", "fillfirst", "ff":
|
||||||
|
return "fill-first", true
|
||||||
|
default:
|
||||||
|
return "", false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// RoutingStrategy
|
||||||
|
func (h *Handler) GetRoutingStrategy(c *gin.Context) {
|
||||||
|
strategy, ok := normalizeRoutingStrategy(h.cfg.Routing.Strategy)
|
||||||
|
if !ok {
|
||||||
|
c.JSON(200, gin.H{"strategy": strings.TrimSpace(h.cfg.Routing.Strategy)})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
c.JSON(200, gin.H{"strategy": strategy})
|
||||||
|
}
|
||||||
|
func (h *Handler) PutRoutingStrategy(c *gin.Context) {
|
||||||
|
var body struct {
|
||||||
|
Value *string `json:"value"`
|
||||||
|
}
|
||||||
|
if errBindJSON := c.ShouldBindJSON(&body); errBindJSON != nil || body.Value == nil {
|
||||||
|
c.JSON(http.StatusBadRequest, gin.H{"error": "invalid body"})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
normalized, ok := normalizeRoutingStrategy(*body.Value)
|
||||||
|
if !ok {
|
||||||
|
c.JSON(http.StatusBadRequest, gin.H{"error": "invalid strategy"})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
h.cfg.Routing.Strategy = normalized
|
||||||
|
h.persist(c)
|
||||||
|
}
|
||||||
|
|
||||||
// Proxy URL
|
// Proxy URL
|
||||||
func (h *Handler) GetProxyURL(c *gin.Context) { c.JSON(200, gin.H{"proxy-url": h.cfg.ProxyURL}) }
|
func (h *Handler) GetProxyURL(c *gin.Context) { c.JSON(200, gin.H{"proxy-url": h.cfg.ProxyURL}) }
|
||||||
func (h *Handler) PutProxyURL(c *gin.Context) {
|
func (h *Handler) PutProxyURL(c *gin.Context) {
|
||||||
|
|||||||
@@ -492,6 +492,10 @@ func (s *Server) registerManagementRoutes() {
|
|||||||
mgmt.PUT("/logging-to-file", s.mgmt.PutLoggingToFile)
|
mgmt.PUT("/logging-to-file", s.mgmt.PutLoggingToFile)
|
||||||
mgmt.PATCH("/logging-to-file", s.mgmt.PutLoggingToFile)
|
mgmt.PATCH("/logging-to-file", s.mgmt.PutLoggingToFile)
|
||||||
|
|
||||||
|
mgmt.GET("/logs-max-total-size-mb", s.mgmt.GetLogsMaxTotalSizeMB)
|
||||||
|
mgmt.PUT("/logs-max-total-size-mb", s.mgmt.PutLogsMaxTotalSizeMB)
|
||||||
|
mgmt.PATCH("/logs-max-total-size-mb", s.mgmt.PutLogsMaxTotalSizeMB)
|
||||||
|
|
||||||
mgmt.GET("/usage-statistics-enabled", s.mgmt.GetUsageStatisticsEnabled)
|
mgmt.GET("/usage-statistics-enabled", s.mgmt.GetUsageStatisticsEnabled)
|
||||||
mgmt.PUT("/usage-statistics-enabled", s.mgmt.PutUsageStatisticsEnabled)
|
mgmt.PUT("/usage-statistics-enabled", s.mgmt.PutUsageStatisticsEnabled)
|
||||||
mgmt.PATCH("/usage-statistics-enabled", s.mgmt.PutUsageStatisticsEnabled)
|
mgmt.PATCH("/usage-statistics-enabled", s.mgmt.PutUsageStatisticsEnabled)
|
||||||
@@ -564,6 +568,14 @@ func (s *Server) registerManagementRoutes() {
|
|||||||
mgmt.PUT("/max-retry-interval", s.mgmt.PutMaxRetryInterval)
|
mgmt.PUT("/max-retry-interval", s.mgmt.PutMaxRetryInterval)
|
||||||
mgmt.PATCH("/max-retry-interval", s.mgmt.PutMaxRetryInterval)
|
mgmt.PATCH("/max-retry-interval", s.mgmt.PutMaxRetryInterval)
|
||||||
|
|
||||||
|
mgmt.GET("/force-model-prefix", s.mgmt.GetForceModelPrefix)
|
||||||
|
mgmt.PUT("/force-model-prefix", s.mgmt.PutForceModelPrefix)
|
||||||
|
mgmt.PATCH("/force-model-prefix", s.mgmt.PutForceModelPrefix)
|
||||||
|
|
||||||
|
mgmt.GET("/routing/strategy", s.mgmt.GetRoutingStrategy)
|
||||||
|
mgmt.PUT("/routing/strategy", s.mgmt.PutRoutingStrategy)
|
||||||
|
mgmt.PATCH("/routing/strategy", s.mgmt.PutRoutingStrategy)
|
||||||
|
|
||||||
mgmt.GET("/claude-api-key", s.mgmt.GetClaudeKeys)
|
mgmt.GET("/claude-api-key", s.mgmt.GetClaudeKeys)
|
||||||
mgmt.PUT("/claude-api-key", s.mgmt.PutClaudeKeys)
|
mgmt.PUT("/claude-api-key", s.mgmt.PutClaudeKeys)
|
||||||
mgmt.PATCH("/claude-api-key", s.mgmt.PatchClaudeKey)
|
mgmt.PATCH("/claude-api-key", s.mgmt.PatchClaudeKey)
|
||||||
|
|||||||
Reference in New Issue
Block a user