feat(provider): add status and banning mechanism

Introduce fields for managing provider status (active, auto_disabled,
manual_disabled) and banning logic.

- Add Status, AutoBan, BanReason, and BanUntil to Provider model and DTO
- Update CreateProvider handler to process new fields with defaults
- Extend sync service to propagate status and ban information in snapshots
- Serialize BanUntil as Unix timestamp for sync compatibility
This commit is contained in:
zenfun
2025-12-12 23:40:18 +08:00
parent eaf99e1582
commit 2407afe0e6
4 changed files with 96 additions and 39 deletions

View File

@@ -48,13 +48,29 @@ func (h *Handler) CreateProvider(c *gin.Context) {
group = "default"
}
status := strings.TrimSpace(req.Status)
if status == "" {
status = "active"
}
autoBan := true
if req.AutoBan != nil {
autoBan = *req.AutoBan
}
provider := model.Provider{
Name: req.Name,
Type: req.Type,
BaseURL: req.BaseURL,
APIKey: req.APIKey,
Group: group,
Models: strings.Join(req.Models, ","),
Name: req.Name,
Type: req.Type,
BaseURL: req.BaseURL,
APIKey: req.APIKey,
Group: group,
Models: strings.Join(req.Models, ","),
Status: status,
AutoBan: autoBan,
BanReason: req.BanReason,
}
if !req.BanUntil.IsZero() {
tu := req.BanUntil.UTC()
provider.BanUntil = &tu
}
if err := h.db.Create(&provider).Error; err != nil {