@@ -1711,6 +1711,45 @@ def refresh_accounts(
17111711
17121712 return result
17131713
1714+ def build_export_item (self , account : dict ) -> dict [str , str ] | None :
1715+ access_token = str (account .get ("access_token" ) or "" ).strip ()
1716+ refresh_token = str (account .get ("refresh_token" ) or "" ).strip ()
1717+ id_token = str (account .get ("id_token" ) or "" ).strip ()
1718+ if not access_token or not refresh_token or not id_token :
1719+ return None
1720+
1721+ access_payload = self ._decode_jwt_payload (access_token )
1722+ id_payload = self ._decode_jwt_payload (id_token )
1723+ auth_claim = access_payload .get ("https://api.openai.com/auth" )
1724+ auth_claim = auth_claim if isinstance (auth_claim , dict ) else {}
1725+ profile_claim = access_payload .get ("https://api.openai.com/profile" )
1726+ profile_claim = profile_claim if isinstance (profile_claim , dict ) else {}
1727+
1728+ email = (
1729+ str (account .get ("email" ) or "" ).strip ()
1730+ or str (profile_claim .get ("email" ) or "" ).strip ()
1731+ or str (id_payload .get ("email" ) or "" ).strip ()
1732+ )
1733+ account_id = (
1734+ str (account .get ("account_id" ) or "" ).strip ()
1735+ or str (auth_claim .get ("chatgpt_account_id" ) or "" ).strip ()
1736+ or str (account .get ("user_id" ) or "" ).strip ()
1737+ )
1738+ item = {
1739+ "type" : str (account .get ("export_type" ) or "codex" ),
1740+ "email" : email ,
1741+ "account_id" : account_id ,
1742+ "access_token" : access_token ,
1743+ "refresh_token" : refresh_token ,
1744+ "id_token" : id_token ,
1745+ "expired" : self ._timestamp_to_iso (access_payload .get ("exp" )),
1746+ "last_refresh" : self ._timestamp_to_iso (access_payload .get ("iat" )),
1747+ }
1748+ password = str (account .get ("password" ) or "" ).strip ()
1749+ if password :
1750+ item ["password" ] = password
1751+ return item
1752+
17141753 def build_export_items (self , access_tokens : list [str ] | None = None ) -> list [dict [str , str ]]:
17151754 target_tokens = set (token for token in (access_tokens or []) if token )
17161755 with self ._lock :
@@ -1720,46 +1759,7 @@ def build_export_items(self, access_tokens: list[str] | None = None) -> list[dic
17201759 if not target_tokens or str (item .get ("access_token" ) or "" ) in target_tokens
17211760 ]
17221761
1723- items : list [dict [str , str ]] = []
1724- for account in accounts :
1725- access_token = str (account .get ("access_token" ) or "" ).strip ()
1726- refresh_token = str (account .get ("refresh_token" ) or "" ).strip ()
1727- id_token = str (account .get ("id_token" ) or "" ).strip ()
1728- if not access_token or not refresh_token or not id_token :
1729- continue
1730-
1731- access_payload = self ._decode_jwt_payload (access_token )
1732- id_payload = self ._decode_jwt_payload (id_token )
1733- auth_claim = access_payload .get ("https://api.openai.com/auth" )
1734- auth_claim = auth_claim if isinstance (auth_claim , dict ) else {}
1735- profile_claim = access_payload .get ("https://api.openai.com/profile" )
1736- profile_claim = profile_claim if isinstance (profile_claim , dict ) else {}
1737-
1738- email = (
1739- str (account .get ("email" ) or "" ).strip ()
1740- or str (profile_claim .get ("email" ) or "" ).strip ()
1741- or str (id_payload .get ("email" ) or "" ).strip ()
1742- )
1743- account_id = (
1744- str (account .get ("account_id" ) or "" ).strip ()
1745- or str (auth_claim .get ("chatgpt_account_id" ) or "" ).strip ()
1746- or str (account .get ("user_id" ) or "" ).strip ()
1747- )
1748- item = {
1749- "type" : str (account .get ("export_type" ) or "codex" ),
1750- "email" : email ,
1751- "account_id" : account_id ,
1752- "access_token" : access_token ,
1753- "refresh_token" : refresh_token ,
1754- "id_token" : id_token ,
1755- "expired" : self ._timestamp_to_iso (access_payload .get ("exp" )),
1756- "last_refresh" : self ._timestamp_to_iso (access_payload .get ("iat" )),
1757- }
1758- password = str (account .get ("password" ) or "" ).strip ()
1759- if password :
1760- item ["password" ] = password
1761- items .append (item )
1762- return items
1762+ return [item for account in accounts if (item := self .build_export_item (account )) is not None ]
17631763
17641764 def get_stats (self ) -> dict :
17651765 with self ._lock :
0 commit comments