MibooGram/modules/apihelper/models/genshin/cookies.py

64 lines
1.5 KiB
Python
Raw Normal View History

2023-02-21 09:43:40 +00:00
from typing import Optional, TypeVar
from pydantic import BaseModel
IntStr = TypeVar("IntStr", int, str)
__all__ = ("CookiesModel",)
class CookiesModel(BaseModel):
login_uid: Optional[IntStr] = None
login_ticket: Optional[str] = None
stoken: Optional[str] = None
stuid: Optional[IntStr] = None
account_id: Optional[IntStr] = None
cookie_token: Optional[str] = None
ltoken: Optional[str] = None
ltuid: Optional[IntStr] = None
account_mid_v2: Optional[str] = None
cookie_token_v2: Optional[str] = None
ltoken_v2: Optional[str] = None
ltmid_v2: Optional[str] = None
@property
def is_v1(self) -> bool:
if self.account_id or self.cookie_token or self.ltoken or self.ltuid:
return True
return False
@property
def is_v2(self) -> bool:
if self.account_mid_v2 or self.cookie_token_v2 or self.ltoken_v2 or self.ltmid_v2:
return True
return False
def remove_v2(self):
self.account_mid_v2 = None
self.cookie_token_v2 = None
self.ltoken_v2 = None
self.ltmid_v2 = None
def to_dict(self):
return self.dict(exclude_defaults=True)
def to_json(self):
return self.json(exclude_defaults=True)
@property
def user_id(self) -> Optional[int]:
if self.ltuid:
return self.ltuid
if self.account_id:
return self.account_id
if self.login_uid:
return self.login_uid
if self.stuid:
return self.stuid
return None