76ba500417
CI / docker (push) Successful in 2m4s
OpenAI-compatible AI gateway with Vue admin UI, multi-provider egress, ingress key governance, monitoring, and security controls. Co-authored-by: Cursor <cursoragent@cursor.com>
52 lines
984 B
Go
52 lines
984 B
Go
package admin
|
|
|
|
import (
|
|
"strings"
|
|
)
|
|
|
|
func (h *Handler) providerNameTaken(name string, excludeID uint) bool {
|
|
name = strings.TrimSpace(name)
|
|
if name == "" {
|
|
return false
|
|
}
|
|
for _, p := range h.cache.ListProviders() {
|
|
if p.ID != excludeID && p.Name == name {
|
|
return true
|
|
}
|
|
}
|
|
return false
|
|
}
|
|
|
|
func (h *Handler) modelAliasTaken(alias string, excludeModelID uint) bool {
|
|
alias = strings.TrimSpace(alias)
|
|
if alias == "" {
|
|
return false
|
|
}
|
|
for _, p := range h.cache.ListProviders() {
|
|
for _, m := range h.cache.GetModels(p.ID) {
|
|
if m.ID == excludeModelID {
|
|
continue
|
|
}
|
|
if m.Alias == alias {
|
|
return true
|
|
}
|
|
}
|
|
}
|
|
return false
|
|
}
|
|
|
|
func normalizeAlias(alias string) string {
|
|
return strings.TrimSpace(alias)
|
|
}
|
|
|
|
func validateModelAlias(h *Handler, alias string, excludeModelID uint) string {
|
|
alias = normalizeAlias(alias)
|
|
if alias == "" {
|
|
return ""
|
|
}
|
|
if h.modelAliasTaken(alias, excludeModelID) {
|
|
return "model alias already exists"
|
|
}
|
|
return ""
|
|
}
|