Unified · Split
| @@ -15,6 +15,7 @@ import ( · 14 unmodified lines | ||
| 15 | 15 | "github.com/gin-gonic/gin" |
| 16 | 16 | "github.com/router-for-me/CLIProxyAPI/v7/internal/auth/codex" |
| 17 | 17 | "github.com/router-for-me/CLIProxyAPI/v7/internal/config" |
| 18 | + "github.com/router-for-me/CLIProxyAPI/v7/internal/credentialweight" | |
| 18 | 19 | "github.com/router-for-me/CLIProxyAPI/v7/internal/registry" |
| 19 | 20 | coreauth "github.com/router-for-me/CLIProxyAPI/v7/sdk/cliproxy/auth" |
| 20 | 21 | log "github.com/sirupsen/logrus" |
| @@ -260,6 +261,20 @@ func (h *Handler) listAuthFilesFromDisk(c *gin.Context) { · 239 unmodified lines | ||
| 260 | 261 | } |
| 261 | 262 | } |
| 262 | 263 | } |
| 264 | + if wv := gjson.GetBytes(data, coreauth.AttributeWeight); wv.Exists() { | |
| 265 | + var rawWeight string | |
| 266 | + switch wv.Type { | |
| 267 | + case gjson.Number: | |
| 268 | + rawWeight = wv.Raw | |
| 269 | + case gjson.String: | |
| 270 | + rawWeight = wv.String() | |
| 271 | + } | |
| 272 | + if rawWeight != "" { | |
| 273 | + if weight, errWeight := credentialweight.ParseString(rawWeight); errWeight == nil { | |
| 274 | + fileData[coreauth.AttributeWeight] = weight | |
| 275 | + } | |
| 276 | + } | |
| 277 | + } | |
| 263 | 278 | if nv := gjson.GetBytes(data, "note"); nv.Exists() && nv.Type == gjson.String { |
| 264 | 279 | if trimmed := strings.TrimSpace(nv.String()); trimmed != "" { |
| 265 | 280 | fileData["note"] = trimmed |
| @@ -403,12 +418,34 @@ func (h *Handler) buildAuthFileEntryLocked(auth *coreauth.Auth) gin.H { · 137 unmodified lines | ||
| 403 | 418 | } |
| 404 | 419 | } |
| 405 | 420 | } |
| 421 | + if weight, ok := authWeightValue(auth); ok { | |
| 422 | + entry[coreauth.AttributeWeight] = weight | |
| 423 | + } | |
| 406 | 424 | if websockets, ok := authWebsocketsValue(auth); ok { |
| 407 | 425 | entry["websockets"] = websockets |
| 408 | 426 | } |
| 409 | 427 | return entry |
| 410 | 428 | } |
| 411 | 429 | |
| 430 | +func authWeightValue(auth *coreauth.Auth) (int64, bool) { | |
| 431 | + if auth == nil { | |
| 432 | + return 0, false | |
| 433 | + } | |
| 434 | + if rawWeight := strings.TrimSpace(authAttribute(auth, coreauth.AttributeWeight)); rawWeight != "" { | |
| 435 | + weight, errWeight := credentialweight.ParseString(rawWeight) | |
| 436 | + return weight, errWeight == nil | |
| 437 | + } | |
| 438 | + if auth.Metadata == nil { | |
| 439 | + return 0, false | |
| 440 | + } | |
| 441 | + rawWeight, ok := auth.Metadata[coreauth.AttributeWeight] | |
| 442 | + if !ok || rawWeight == nil { | |
| 443 | + return 0, false | |
| 444 | + } | |
| 445 | + weight, errWeight := credentialweight.ParseValue(rawWeight) | |
| 446 | + return weight, errWeight == nil | |
| 447 | +} | |
| 448 | + | |
| 412 | 449 | func authWebsocketsValue(auth *coreauth.Auth) (bool, bool) { |
| 413 | 450 | if auth == nil { |
| 414 | 451 | return false, false |