mirror of
https://github.com/router-for-me/CLIProxyAPI.git
synced 2026-11-16 22:57:53 +08:00
- Introduce `AttributeFilePriority` and helper to track priority inherited from auth files - Preserve file-configured priority attributes and metadata in plugin host during auth refresh - Apply file priority metadata consistently across synthesizer, token filestore, and management handlers Closes: #6089
43 lines
1.0 KiB
Go
43 lines
1.0 KiB
Go
package auth
|
|
|
|
import (
|
|
"strconv"
|
|
"strings"
|
|
)
|
|
|
|
// AttributeFilePriority marks priority values inherited from a physical auth file.
|
|
const AttributeFilePriority = "file_priority"
|
|
|
|
// ApplyAuthPriorityMetadata copies a valid file priority into an auth's metadata and routing attributes.
|
|
func ApplyAuthPriorityMetadata(auth *Auth, metadata map[string]any) {
|
|
if auth == nil {
|
|
return
|
|
}
|
|
delete(auth.Attributes, AttributeFilePriority)
|
|
rawPriority, ok := metadata["priority"]
|
|
if !ok {
|
|
return
|
|
}
|
|
priority := ""
|
|
switch value := rawPriority.(type) {
|
|
case float64:
|
|
priority = strconv.Itoa(int(value))
|
|
case string:
|
|
priority = strings.TrimSpace(value)
|
|
if _, errAtoi := strconv.Atoi(priority); errAtoi != nil {
|
|
return
|
|
}
|
|
default:
|
|
return
|
|
}
|
|
if auth.Metadata == nil {
|
|
auth.Metadata = make(map[string]any)
|
|
}
|
|
auth.Metadata["priority"] = rawPriority
|
|
if auth.Attributes == nil {
|
|
auth.Attributes = make(map[string]string)
|
|
}
|
|
auth.Attributes["priority"] = priority
|
|
auth.Attributes[AttributeFilePriority] = "true"
|
|
}
|