mirror of
https://github.com/suyiiyii/nonebot-bison.git
synced 2025-06-02 09:26:12 +08:00
✨ 关联cookie是不显示匿名cookie
This commit is contained in:
parent
418a941448
commit
06079b98f7
@ -260,8 +260,9 @@ class DBConfig:
|
||||
return res
|
||||
|
||||
async def get_cookie(self, platform_name: str = None, target: T_Target = None) -> list[Cookie]:
|
||||
"""根据平台名和订阅名获取 cookie,不会返回匿名cookie"""
|
||||
async with create_session() as sess:
|
||||
query = select(Cookie).distinct()
|
||||
query = select(Cookie).distinct().where(Cookie.is_universal == False) # noqa: E712
|
||||
if platform_name:
|
||||
query = query.where(Cookie.platform_name == platform_name)
|
||||
query = query.outerjoin(CookieTarget).options(selectinload(Cookie.targets))
|
||||
@ -277,12 +278,7 @@ class DBConfig:
|
||||
query = select(Cookie).distinct().where(Cookie.is_universal == True) # noqa: E712
|
||||
if platform_name:
|
||||
query = query.where(Cookie.platform_name == platform_name)
|
||||
query = query.outerjoin(CookieTarget).options(selectinload(Cookie.targets))
|
||||
res = (await sess.scalars(query)).all()
|
||||
if target:
|
||||
query = select(CookieTarget.cookie_id).join(Target).where(Target.target == target)
|
||||
ids = set((await sess.scalars(query)).all())
|
||||
res = [cookie for cookie in res if cookie.id in ids]
|
||||
return res
|
||||
|
||||
async def add_cookie_with_content(self, platform_name: str, content: str) -> int:
|
||||
|
@ -55,9 +55,10 @@ class CookieClientManager(ClientManager):
|
||||
async def init_universal_cookie(cls):
|
||||
"""移除已有的匿名cookie,添加一个新的匿名cookie"""
|
||||
universal_cookies = await config.get_unviersal_cookie(cls._platform_name)
|
||||
universal_cookie = Cookie(platform_name=cls._platform_name, content="{}", is_universal=True)
|
||||
for cookie in universal_cookies:
|
||||
await config.delete_cookie(cookie.id)
|
||||
universal_cookie = Cookie(platform_name=cls._platform_name, content="{}", is_universal=True)
|
||||
universal_cookie.id = cookie.id # 保持原有的id
|
||||
await config.add_cookie(universal_cookie)
|
||||
|
||||
@classmethod
|
||||
|
Loading…
x
Reference in New Issue
Block a user