@@ -1063,17 +1063,17 @@ type importToken struct {
10631063
10641064// jsonAccountEntry CLIProxyAPI 凭证 JSON 条目
10651065type jsonAccountEntry struct {
1066- RefreshToken string `json:"refresh_token"`
1067- SessionToken string `json:"session_token"`
1068- SessionTokenCamel string `json:"sessionToken"`
1069- AccessToken string `json:"access_token"`
1070- IDToken string `json:"id_token"`
1071- AccountID string `json:"account_id"`
1072- Email string `json:"email"`
1073- Name string `json:"name"`
1074- PlanType string `json:"plan_type"`
1075- Expired string `json:"expired"`
1076- ExpiresAt string `json:"expires_at"`
1066+ RefreshToken string `json:"refresh_token"`
1067+ SessionToken string `json:"session_token"`
1068+ SessionTokenCamel string `json:"sessionToken"`
1069+ AccessToken string `json:"access_token"`
1070+ IDToken string `json:"id_token"`
1071+ AccountID string `json:"account_id"`
1072+ Email string `json:"email"`
1073+ Name string `json:"name"`
1074+ PlanType string `json:"plan_type"`
1075+ Expired importJSONScalarString `json:"expired"`
1076+ ExpiresAt importJSONScalarString `json:"expires_at"`
10771077}
10781078
10791079type sub2apiImportPayload struct {
@@ -1086,16 +1086,45 @@ type sub2apiAccountEntry struct {
10861086}
10871087
10881088type sub2apiAccountCredentials struct {
1089- RefreshToken string `json:"refresh_token"`
1090- SessionToken string `json:"session_token"`
1091- SessionTokenCamel string `json:"sessionToken"`
1092- AccessToken string `json:"access_token"`
1093- IDToken string `json:"id_token"`
1094- AccountID string `json:"account_id"`
1095- Email string `json:"email"`
1096- PlanType string `json:"plan_type"`
1097- ExpiresAt string `json:"expires_at"`
1098- Expired string `json:"expired"`
1089+ RefreshToken string `json:"refresh_token"`
1090+ SessionToken string `json:"session_token"`
1091+ SessionTokenCamel string `json:"sessionToken"`
1092+ AccessToken string `json:"access_token"`
1093+ IDToken string `json:"id_token"`
1094+ AccountID string `json:"account_id"`
1095+ Email string `json:"email"`
1096+ PlanType string `json:"plan_type"`
1097+ ExpiresAt importJSONScalarString `json:"expires_at"`
1098+ Expired importJSONScalarString `json:"expired"`
1099+ }
1100+
1101+ type importJSONScalarString string
1102+
1103+ func (v * importJSONScalarString ) UnmarshalJSON (data []byte ) error {
1104+ decoder := json .NewDecoder (bytes .NewReader (data ))
1105+ decoder .UseNumber ()
1106+
1107+ var raw interface {}
1108+ if err := decoder .Decode (& raw ); err != nil {
1109+ return err
1110+ }
1111+
1112+ switch value := raw .(type ) {
1113+ case string :
1114+ * v = importJSONScalarString (strings .TrimSpace (value ))
1115+ case json.Number :
1116+ * v = importJSONScalarString (value .String ())
1117+ case bool :
1118+ * v = importJSONScalarString (strconv .FormatBool (value ))
1119+ default :
1120+ * v = ""
1121+ }
1122+
1123+ return nil
1124+ }
1125+
1126+ func (v importJSONScalarString ) String () string {
1127+ return strings .TrimSpace (string (v ))
10991128}
11001129
11011130var utf8BOM = []byte {0xef , 0xbb , 0xbf }
@@ -1155,7 +1184,7 @@ func jsonAccountEntriesToTokens(entries []jsonAccountEntry) []importToken {
11551184 idToken : strings .TrimSpace (entry .IDToken ),
11561185 accountID : strings .TrimSpace (entry .AccountID ),
11571186 planType : strings .TrimSpace (entry .PlanType ),
1158- expiresAt : firstNonEmpty (entry .ExpiresAt , entry .Expired ),
1187+ expiresAt : firstNonEmpty (entry .ExpiresAt . String () , entry .Expired . String () ),
11591188 })
11601189 }
11611190 }
@@ -1190,7 +1219,7 @@ func parseSub2APIJSONImportTokens(data []byte) []importToken {
11901219 idToken : strings .TrimSpace (account .Credentials .IDToken ),
11911220 accountID : strings .TrimSpace (account .Credentials .AccountID ),
11921221 planType : strings .TrimSpace (account .Credentials .PlanType ),
1193- expiresAt : firstNonEmpty (account .Credentials .ExpiresAt , account .Credentials .Expired ),
1222+ expiresAt : firstNonEmpty (account .Credentials .ExpiresAt . String () , account .Credentials .Expired . String () ),
11941223 })
11951224 }
11961225 }
0 commit comments