Add projects
This commit is contained in:
parent
2d3a9ad623
commit
8b607dd700
1802 changed files with 503346 additions and 2 deletions
69
backend/internal/api/handlers/management/quota.go
Normal file
69
backend/internal/api/handlers/management/quota.go
Normal file
|
|
@ -0,0 +1,69 @@
|
|||
package management
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
"strings"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
// Quota exceeded toggles
|
||||
func (h *Handler) GetSwitchProject(c *gin.Context) {
|
||||
c.JSON(200, gin.H{"switch-project": h.cfg.QuotaExceeded.SwitchProject})
|
||||
}
|
||||
func (h *Handler) PutSwitchProject(c *gin.Context) {
|
||||
h.updateBoolField(c, func(v bool) { h.cfg.QuotaExceeded.SwitchProject = v })
|
||||
}
|
||||
|
||||
func (h *Handler) GetSwitchPreviewModel(c *gin.Context) {
|
||||
c.JSON(200, gin.H{"switch-preview-model": h.cfg.QuotaExceeded.SwitchPreviewModel})
|
||||
}
|
||||
func (h *Handler) PutSwitchPreviewModel(c *gin.Context) {
|
||||
h.updateBoolField(c, func(v bool) { h.cfg.QuotaExceeded.SwitchPreviewModel = v })
|
||||
}
|
||||
|
||||
// ResetQuota clears quota/cooldown routing state for one auth index.
|
||||
func (h *Handler) ResetQuota(c *gin.Context) {
|
||||
if h.authManager == nil {
|
||||
c.JSON(http.StatusServiceUnavailable, gin.H{"error": "core auth manager unavailable"})
|
||||
return
|
||||
}
|
||||
|
||||
var req struct {
|
||||
AuthIndex string `json:"auth_index"`
|
||||
}
|
||||
if errBindJSON := c.ShouldBindJSON(&req); errBindJSON != nil {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"error": "invalid request body"})
|
||||
return
|
||||
}
|
||||
|
||||
authIndex := strings.TrimSpace(req.AuthIndex)
|
||||
if authIndex == "" {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"error": "auth_index is required"})
|
||||
return
|
||||
}
|
||||
|
||||
auth := h.authByIndex(authIndex)
|
||||
if auth == nil {
|
||||
c.JSON(http.StatusNotFound, gin.H{"error": "auth not found"})
|
||||
return
|
||||
}
|
||||
|
||||
updated, models, errReset := h.authManager.ResetQuota(c.Request.Context(), auth.ID)
|
||||
if errReset != nil {
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"error": fmt.Sprintf("failed to reset quota: %v", errReset)})
|
||||
return
|
||||
}
|
||||
if updated == nil {
|
||||
c.JSON(http.StatusNotFound, gin.H{"error": "auth not found"})
|
||||
return
|
||||
}
|
||||
updated.EnsureIndex()
|
||||
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"status": "ok",
|
||||
"auth_index": updated.Index,
|
||||
"models": models,
|
||||
})
|
||||
}
|
||||
Loading…
Reference in a new issue