mirror of
https://github.com/xuthus83/LittlePaimon.git
synced 2025-04-12 23:29:37 +08:00
✨ Web UI
公共Cookie管理增加暂停使用
功能
This commit is contained in:
parent
9afea36787
commit
d9398c2fb2
@ -13,7 +13,7 @@ class PublicCookie(Model):
|
|||||||
cookie: str = fields.TextField()
|
cookie: str = fields.TextField()
|
||||||
"""cookie内容"""
|
"""cookie内容"""
|
||||||
status: int = fields.IntField(default=1)
|
status: int = fields.IntField(default=1)
|
||||||
"""cookie状态,0为疑似失效,1为可用,2为每日限制"""
|
"""cookie状态,0为疑似失效,1为可用,2为每日限制,3为暂停使用"""
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
table = 'public_cookie'
|
table = 'public_cookie'
|
||||||
|
@ -184,7 +184,7 @@ async def check_retcode(data: dict, cookie_info, cookie_type: str, user_id: str,
|
|||||||
logger.info('原神Cookie', f'UID<m>{cookie_info.uid}</m>使用的缓存cookie已达到每日30次查询上限')
|
logger.info('原神Cookie', f'UID<m>{cookie_info.uid}</m>使用的缓存cookie已达到每日30次查询上限')
|
||||||
return False
|
return False
|
||||||
else:
|
else:
|
||||||
if cookie_type == 'public':
|
if cookie_type == 'public' and data['retcode'] != 1034:
|
||||||
await CookieCache.update_or_create(uid=uid, defaults={'cookie': cookie_info.cookie})
|
await CookieCache.update_or_create(uid=uid, defaults={'cookie': cookie_info.cookie})
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
@ -5,7 +5,7 @@ from fastapi import APIRouter
|
|||||||
from fastapi.responses import JSONResponse
|
from fastapi.responses import JSONResponse
|
||||||
from pydantic import BaseModel
|
from pydantic import BaseModel
|
||||||
|
|
||||||
from LittlePaimon.database import PublicCookie, PrivateCookie, LastQuery
|
from LittlePaimon.database import PublicCookie, PrivateCookie, LastQuery, CookieCache
|
||||||
from LittlePaimon.utils.api import get_bind_game_info, get_stoken_by_cookie
|
from LittlePaimon.utils.api import get_bind_game_info, get_stoken_by_cookie
|
||||||
from .utils import authentication
|
from .utils import authentication
|
||||||
|
|
||||||
@ -49,6 +49,26 @@ async def get_public_cookies(status: Optional[int] = None):
|
|||||||
return await PublicCookie.filter(status=status).values()
|
return await PublicCookie.filter(status=status).values()
|
||||||
|
|
||||||
|
|
||||||
|
@route.post('/set_public_cookie', response_class=JSONResponse, dependencies=[authentication()])
|
||||||
|
async def set_public_cookie(id: int):
|
||||||
|
cookie = await PublicCookie.get_or_none(id=id)
|
||||||
|
if cookie.status != 3:
|
||||||
|
await CookieCache.filter(cookie=cookie.cookie).delete()
|
||||||
|
cookie.status = 3
|
||||||
|
await cookie.save()
|
||||||
|
return {
|
||||||
|
'status': 0,
|
||||||
|
'msg': f'{id}号公共Cookie暂停使用成功'
|
||||||
|
}
|
||||||
|
else:
|
||||||
|
cookie.status = 1
|
||||||
|
await cookie.save()
|
||||||
|
return {
|
||||||
|
'status': 0,
|
||||||
|
'msg': f'{id}号公共Cookie恢复使用成功'
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@route.get('/get_private_cookies', response_class=JSONResponse, dependencies=[authentication()])
|
@route.get('/get_private_cookies', response_class=JSONResponse, dependencies=[authentication()])
|
||||||
async def get_private_cookies(
|
async def get_private_cookies(
|
||||||
page: int = 1,
|
page: int = 1,
|
||||||
@ -83,7 +103,9 @@ async def get_private_cookie(id: int):
|
|||||||
@route.delete('/delete_cookie', response_class=JSONResponse, dependencies=[authentication()])
|
@route.delete('/delete_cookie', response_class=JSONResponse, dependencies=[authentication()])
|
||||||
async def delete_public_cookie(cookie_type: str, id: int):
|
async def delete_public_cookie(cookie_type: str, id: int):
|
||||||
if cookie_type == 'public':
|
if cookie_type == 'public':
|
||||||
await PublicCookie.filter(id=id).delete()
|
cookie = await PublicCookie.get(id=id)
|
||||||
|
await CookieCache.filter(cookie=cookie.cookie).delete()
|
||||||
|
await cookie.delete()
|
||||||
return {'status': 0, 'msg': f'{id}号公共Cookie删除成功'}
|
return {'status': 0, 'msg': f'{id}号公共Cookie删除成功'}
|
||||||
else:
|
else:
|
||||||
await PrivateCookie.filter(id=id).delete()
|
await PrivateCookie.filter(id=id).delete()
|
||||||
|
@ -1,9 +1,11 @@
|
|||||||
status_map = {
|
status_map = {
|
||||||
0: '疑似失效',
|
0: '疑似失效',
|
||||||
1: '可用',
|
1: '可用',
|
||||||
2: '达到每日限制'
|
2: '达到每日限制',
|
||||||
|
3: '暂停使用'
|
||||||
}
|
}
|
||||||
status_filter = {
|
status_filter = {
|
||||||
'options': [{'label': '疑似失效', 'value': 0},
|
'options': [{'label': '疑似失效', 'value': 0},
|
||||||
{'label': '可用', 'value': 1},
|
{'label': '可用', 'value': 1},
|
||||||
{'label': '达到每日限制', 'value': 2}]}
|
{'label': '达到每日限制', 'value': 2},
|
||||||
|
{'label': '暂停使用', 'value': 3}]}
|
||||||
|
@ -5,17 +5,22 @@ from .constants import status_map, status_filter
|
|||||||
add_button = ActionType.Dialog(label='添加公共Cookie',
|
add_button = ActionType.Dialog(label='添加公共Cookie',
|
||||||
level=LevelEnum.primary,
|
level=LevelEnum.primary,
|
||||||
dialog=Dialog(title='添加公共Cookie',
|
dialog=Dialog(title='添加公共Cookie',
|
||||||
body=Form(api='post:/LittlePaimon/api/add_cookie?cookie_type=public&force=false',
|
body=Form(
|
||||||
|
api='post:/LittlePaimon/api/add_cookie?cookie_type=public&force=false',
|
||||||
body=[Textarea(name='cookie', label='Cookie', required=True,
|
body=[Textarea(name='cookie', label='Cookie', required=True,
|
||||||
showCounter=False)])))
|
showCounter=False)])))
|
||||||
add_button_force = ActionType.Dialog(label='强制添加公共Cookie',
|
add_button_force = ActionType.Dialog(label='强制添加公共Cookie',
|
||||||
level=LevelEnum.warning,
|
level=LevelEnum.warning,
|
||||||
confirmText='强制添加公共Cookie不会对Cookie有效性进行校验,如果你不确定是否正确有效,请不要强制添加。',
|
confirmText='强制添加公共Cookie不会对Cookie有效性进行校验,如果你不确定是否正确有效,请不要强制添加。',
|
||||||
dialog=Dialog(title='强制添加公共Cookie',
|
dialog=Dialog(title='强制添加公共Cookie',
|
||||||
body=Form(api='post:/LittlePaimon/api/add_cookie?cookie_type=public&force=true',
|
body=Form(
|
||||||
|
api='post:/LittlePaimon/api/add_cookie?cookie_type=public&force=true',
|
||||||
body=[
|
body=[
|
||||||
Textarea(name='cookie', label='Cookie', required=True,
|
Textarea(name='cookie', label='Cookie', required=True,
|
||||||
showCounter=False)])))
|
showCounter=False)])))
|
||||||
|
set_button = ActionType.Ajax(label='${status == 3 ? "恢复使用" : "暂停使用"}', level=LevelEnum.warning,
|
||||||
|
confirmText='将该公共Cookie设为${status == 3 ? "恢复使用?恢复后该Cookie将回到可用状态" : "暂停使用?暂停后在查询时将不使用该Cookie"}',
|
||||||
|
api='post:/LittlePaimon/api/set_public_cookie?id=${id}')
|
||||||
delete_button = ActionType.Ajax(label='删除', level=LevelEnum.danger,
|
delete_button = ActionType.Ajax(label='删除', level=LevelEnum.danger,
|
||||||
confirmText='确认删除该公共Cookie',
|
confirmText='确认删除该公共Cookie',
|
||||||
api='delete:/LittlePaimon/api/delete_cookie?cookie_type=public&id=${id}')
|
api='delete:/LittlePaimon/api/delete_cookie?cookie_type=public&id=${id}')
|
||||||
@ -27,7 +32,7 @@ table = TableCRUD(mode='table',
|
|||||||
TableColumn(label='Cookie', name='cookie', width='64%'),
|
TableColumn(label='Cookie', name='cookie', width='64%'),
|
||||||
TableColumn(type='mapping', label='状态', name='status', filterable=status_filter,
|
TableColumn(type='mapping', label='状态', name='status', filterable=status_filter,
|
||||||
map=status_map, width='12%'),
|
map=status_map, width='12%'),
|
||||||
ColumnOperation(label='操作', buttons=[delete_button], width='16%')],
|
ColumnOperation(label='操作', buttons=[set_button, delete_button], width='16%')],
|
||||||
headerToolbar=[add_button, add_button_force])
|
headerToolbar=[add_button, add_button_force])
|
||||||
page = PageSchema(label='公共Cookie', icon='fa fa-key', url='/cookie/public',
|
page = PageSchema(label='公共Cookie', icon='fa fa-key', url='/cookie/public',
|
||||||
schema=Page(title='公共Cookie', body=table))
|
schema=Page(title='公共Cookie', body=table))
|
||||||
|
Loading…
x
Reference in New Issue
Block a user