feat(provider): add update endpoint and enforce status checks

Add `PUT /admin/providers/{id}` endpoint to allow updating provider
configurations, including status and ban details. Update synchronization
logic to exclude inactive or banned providers from routing tables to
ensure traffic is not routed to them.
This commit is contained in:
zenfun
2025-12-12 23:44:52 +08:00
parent 2407afe0e6
commit 305f2ebf18
3 changed files with 116 additions and 0 deletions

View File

@@ -4,6 +4,7 @@ import (
"context"
"fmt"
"strings"
"time"
"github.com/bytedance/sonic"
"github.com/ez-api/ez-api/internal/model"
@@ -93,6 +94,12 @@ func (s *SyncService) SyncProvider(provider *model.Provider) error {
if m == "" {
continue
}
if snap.Status != "active" {
continue
}
if snap.BanUntil > 0 && time.Now().Unix() < snap.BanUntil {
continue
}
routeKey := fmt.Sprintf("route:group:%s:%s", group, m)
pipe.SAdd(ctx, routeKey, provider.ID)
}
@@ -217,6 +224,12 @@ func (s *SyncService) SyncAll(db *gorm.DB) error {
if m == "" {
continue
}
if snap.Status != "active" {
continue
}
if snap.BanUntil > 0 && time.Now().Unix() < snap.BanUntil {
continue
}
routeKey := fmt.Sprintf("route:group:%s:%s", group, m)
pipe.SAdd(ctx, routeKey, p.ID)
}