From e8e39526b3c9f80e42214da2ea00aaffc3619a68 Mon Sep 17 00:00:00 2001 From: Supra4E8C Date: Thu, 30 Jul 2026 07:36:58 +0800 Subject: [PATCH] feat(auth): add support for credential weight parsing in auth file handling --- .../api/handlers/management/auth_files.go | 37 +++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/internal/api/handlers/management/auth_files.go b/internal/api/handlers/management/auth_files.go index 80801d7e7..04927d611 100644 --- a/internal/api/handlers/management/auth_files.go +++ b/internal/api/handlers/management/auth_files.go @@ -15,6 +15,7 @@ import ( "github.com/gin-gonic/gin" "github.com/router-for-me/CLIProxyAPI/v7/internal/auth/codex" "github.com/router-for-me/CLIProxyAPI/v7/internal/config" + "github.com/router-for-me/CLIProxyAPI/v7/internal/credentialweight" "github.com/router-for-me/CLIProxyAPI/v7/internal/registry" coreauth "github.com/router-for-me/CLIProxyAPI/v7/sdk/cliproxy/auth" log "github.com/sirupsen/logrus" @@ -260,6 +261,20 @@ func (h *Handler) listAuthFilesFromDisk(c *gin.Context) { } } } + if wv := gjson.GetBytes(data, coreauth.AttributeWeight); wv.Exists() { + var rawWeight string + switch wv.Type { + case gjson.Number: + rawWeight = wv.Raw + case gjson.String: + rawWeight = wv.String() + } + if rawWeight != "" { + if weight, errWeight := credentialweight.ParseString(rawWeight); errWeight == nil { + fileData[coreauth.AttributeWeight] = weight + } + } + } if nv := gjson.GetBytes(data, "note"); nv.Exists() && nv.Type == gjson.String { if trimmed := strings.TrimSpace(nv.String()); trimmed != "" { fileData["note"] = trimmed @@ -403,12 +418,34 @@ func (h *Handler) buildAuthFileEntryLocked(auth *coreauth.Auth) gin.H { } } } + if weight, ok := authWeightValue(auth); ok { + entry[coreauth.AttributeWeight] = weight + } if websockets, ok := authWebsocketsValue(auth); ok { entry["websockets"] = websockets } return entry } +func authWeightValue(auth *coreauth.Auth) (int64, bool) { + if auth == nil { + return 0, false + } + if rawWeight := strings.TrimSpace(authAttribute(auth, coreauth.AttributeWeight)); rawWeight != "" { + weight, errWeight := credentialweight.ParseString(rawWeight) + return weight, errWeight == nil + } + if auth.Metadata == nil { + return 0, false + } + rawWeight, ok := auth.Metadata[coreauth.AttributeWeight] + if !ok || rawWeight == nil { + return 0, false + } + weight, errWeight := credentialweight.ParseValue(rawWeight) + return weight, errWeight == nil +} + func authWebsocketsValue(auth *coreauth.Auth) (bool, bool) { if auth == nil { return false, false