Files
tbphp fb18dc9e87 refactor(cooldown): 精简模型冷却展示与管理接口 (#606)
* fix(web): 精调模型冷却展示与筛选样式

* refactor(cooldown): 精简模型冷却展示与管理接口
2026-09-09 15:50:02 +08:00

37 lines
881 B
Go

package control
import (
"sort"
"time"
)
type ModelCooldownResponse struct {
Model string `json:"model"`
CooldownUntilMS int64 `json:"cooldown_until_ms"`
}
func hasModelCooldown(limits map[string]time.Time, now time.Time) bool {
for _, until := range limits {
if until.After(now) {
return true
}
}
return false
}
func modelCooldownResponses(limits map[string]time.Time, now time.Time) ([]ModelCooldownResponse, error) {
result := make([]ModelCooldownResponse, 0, len(limits))
for model, until := range limits {
if !until.After(now) {
continue
}
milliseconds, err := safeEpochMilliseconds(until)
if err != nil {
return nil, err
}
result = append(result, ModelCooldownResponse{Model: model, CooldownUntilMS: milliseconds})
}
sort.Slice(result, func(i, j int) bool { return result[i].Model < result[j].Model })
return result, nil
}