Skip to content

Commit

Permalink
🐛 Ensure cookie uid IntStr is int
Browse files Browse the repository at this point in the history
  • Loading branch information
omg-xtao committed Jan 10, 2025
1 parent f4481ed commit fccacb3
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
13 changes: 10 additions & 3 deletions modules/apihelper/models/genshin/cookies.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
from typing import Optional, TypeVar
from typing import Optional, Annotated, Union

from pydantic import BaseModel
from pydantic import BaseModel, BeforeValidator

IntStr = TypeVar("IntStr", int, str)

def int_str_check(value: Union[int, str]) -> Union[int, str]:
if value is not None:
int(value)
return value


IntStr = Annotated[Union[int, str], BeforeValidator(int_str_check)]

__all__ = ("CookiesModel",)

Expand Down
2 changes: 2 additions & 0 deletions plugins/account/cookies.py
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,8 @@ async def parse_cookies(self, update: Update, context: CallbackContext, text: st
)
cookie = {x[0]: x[1] for x in wrapped}
cookies = self.parse_cookie(cookie)
if cookies:
CookiesModel.model_validate(cookies)
except (AttributeError, ValueError, IndexError) as exc:
logger.info("用户 %s[%s] Cookies解析出现错误\ntext:%s", user.full_name, user.id, message.text)
logger.debug("解析Cookies出现错误", exc_info=exc)
Expand Down

0 comments on commit fccacb3

Please sign in to comment.