优化Web UI样式,Web UI允许强制添加Cookie,优化图标资源下载

This commit is contained in:
CMHopeSunshine 2022-11-10 16:59:35 +08:00
parent 4375a835e1
commit d99e524539
10 changed files with 104 additions and 64 deletions

View File

@ -42,17 +42,17 @@ class GenshinInfoManager:
result = ''
await LastQuery.update_last_query(self.user_id, self.uid)
mihoyo_result = await self.update_from_mihoyo()
result += f'米游社数据:\n{mihoyo_result}\n'
result += f'米游社数据:{mihoyo_result}\n'
if include_talent:
if await self.is_bind():
talent_result = await self.update_talent()
result += f'天赋数据:\n{talent_result}\n'
result += f'天赋数据:{talent_result}\n'
else:
result += '天赋数据:\n未绑定私人Cookie\n'
result += '天赋数据:未绑定私人Cookie\n'
enka_result = await self.update_from_enka()
result += f'Enka数据\n{enka_result}'
result += f'Enka数据{enka_result}'
return result or enka_result
async def update_from_enka(self) -> str:

View File

@ -98,7 +98,8 @@ class aiorequests:
timeout=timeout,
**kwargs)
# 不保存安柏计划的问号图标
if resp.headers.get('etag') == 'W/"6363798a-13c7"':
if resp.headers.get('etag') == 'W/"6363798a-13c7"' or resp.headers.get(
'content-md5') == 'JeG5b/z8SpViMmO/E9eayA==':
save_path = False
resp = resp.read()
if b'NoSuchKey' in resp or b'character not exists' in resp:
@ -111,7 +112,8 @@ class aiorequests:
params=params,
timeout=timeout,
**kwargs)
if resp.headers.get('etag') == 'W/"6363798a-13c7"':
if resp.headers.get('etag') == 'W/"6363798a-13c7"' or resp.headers.get(
'content-md5') == 'JeG5b/z8SpViMmO/E9eayA==':
save_path = False
resp = resp.read()
if b'error' in resp:
@ -136,9 +138,9 @@ class aiorequests:
async def download(url: str, save_path: Path, exclude_json: bool = False):
"""
下载文件(带进度条)
:param url: url
:param save_path: 保存路径
:param exclude_json: 是否排除json文件
:param url: url
:param save_path: 保存路径
:param exclude_json: 是否排除json文件
"""
save_path.parent.mkdir(parents=True, exist_ok=True)
async with httpx.AsyncClient().stream(method='GET', url=url, follow_redirects=True) as datas:
@ -163,17 +165,31 @@ class aiorequests:
**kwargs):
"""
下载icon
:param name: url
:param headers: 请求头
:param save_path: 保存路径
:param name: url
:param headers: 请求头
:param save_path: 保存路径
"""
url = None
if name.startswith(('UI_EquipIcon', 'UI_RelicIcon')):
url = f'https://upload-bbs.mihoyo.com/game_record/genshin/equip/{name}'
elif name.startswith('UI_Talent'):
url = f'https://upload-bbs.mihoyo.com/game_record/genshin/constellation_icon/{name}'
elif name.startswith('UI_AvatarIcon'):
if name.endswith('UI_AvatarIcon_Side'):
url = f'https://upload-bbs.mihoyo.com/game_record/genshin/character_side_icon/{name}'
elif name.endswith('Card.png'):
url = f'https://upload-bbs.mihoyo.com/game_record/genshin/character_card_icon/{name}'
else:
url = f'https://upload-bbs.mihoyo.com/game_record/genshin/character_icon/{name}'
urls = [
f'https://file.microgg.cn/MiniGG/ui/{name}',
url,
f'https://file.microgg.cn/KimigaiiWuyi/resource/icon/{name}'
f'https://api.ambr.top/assets/UI/{name}',
f'https://enka.network/ui/{name}'
f'https://enka.network/ui/{name}',
]
for url in urls:
with contextlib.suppress(Exception):
return await aiorequests.get_img(url=url, headers=headers, save_path=save_path, **kwargs)
if url is not None:
return await aiorequests.get_img(url=url, headers=headers, save_path=save_path, **kwargs)
logger.opt(colors=True).info(f'<u><y>[资源检查]</y></u>图标资源<m>{name}</m><r>下载失败</r>')
return None

View File

@ -7,8 +7,6 @@ from .plugin import route as plugin_route
from .status import route as status_route
from .utils import authentication
# from .learning_chat import route as chat_route
BaseApiRouter = APIRouter(prefix='/LittlePaimon/api')
BaseApiRouter.include_router(cookie_route)
@ -16,4 +14,3 @@ BaseApiRouter.include_router(plugin_route)
BaseApiRouter.include_router(bot_info_route)
BaseApiRouter.include_router(status_route)
BaseApiRouter.include_router(login_route)
# BaseApiRouter.include_router(chat_route)

View File

@ -14,7 +14,10 @@ route = APIRouter()
class BindCookie(BaseModel):
user_id: int
uid: Optional[int]
mys_id: Optional[int]
cookie: str
stoken: Optional[str]
@route.post('/bind_cookie', response_class=JSONResponse)
@ -81,20 +84,28 @@ async def delete_private_cookie(id: int):
@route.post('/add_public_cookie', response_class=JSONResponse, dependencies=[authentication()])
async def add_public_cookie(data: dict):
async def add_public_cookie(force: bool, data: dict):
cookie = data.get('cookie')
if not cookie:
return {'status': 100, 'msg': '参数错误'}
if await get_bind_game_info(cookie, True):
if not force:
if await get_bind_game_info(cookie, True):
new_cookie = await PublicCookie.create(cookie=cookie)
return {'status': 0, 'msg': f'{new_cookie.id}号公共Cookie添加成功'}
else:
return {'status': 200, 'msg': '该Cookie无效'}
else:
new_cookie = await PublicCookie.create(cookie=cookie)
return {'status': 0, 'msg': f'{new_cookie.id}号公共Cookie添加成功'}
else:
return {'status': 200, 'msg': '该Cookie无效'}
@route.post('/save_private_cookie', response_class=JSONResponse, dependencies=[authentication()])
async def save_private_cookie(data: BindCookie):
if game_info := await get_bind_game_info(data.cookie):
async def save_private_cookie(force: bool, data: BindCookie):
if force:
await PrivateCookie.update_or_create(user_id=data.user_id, uid=data.uid, mys_id=data.mys_id,
defaults={'cookie': data.cookie, 'stoken': data.stoken})
return {'status': 0, 'msg': f'QQ{data.user_id}的UID{data.uid}的Cookie强制修改成功。'}
elif game_info := await get_bind_game_info(data.cookie):
game_uid = game_info['game_role_id']
mys_id = game_info['mys_id']
await LastQuery.update_or_create(user_id=data.user_id,

View File

@ -345,5 +345,5 @@ select = Select(label='选择配置类',
'value': 8
}
])
page = PageSchema(url='/configs', label='配置项管理',
page = PageSchema(url='/bot_config/configs', icon='fa fa-wrench', label='配置项管理',
schema=Page(title='配置项管理', initApi='/LittlePaimon/api/get_config', body=[select, cookie_web_form, sim_gacha_form, auto_mys_form, ssbq_form, ys_form, notice_form, other_form, nonebot_form]))

View File

@ -6,17 +6,6 @@ from .plugin_manage import page as plugin_manage_page
from .private_cookie import page as private_cookie_page
from .public_cookie import page as public_cookie_page
# from .learning_chat_manage import page as learning_chat_page
# dropdown = DropDownButton(
# buttons=[
# ActionType.Dialog(label='用户信息',
# dialog=Dialog(title='用户信息',
# body='待定')),
# ActionType.Url(label='退出登录',
# url='/LittlePaimon/api/logout')
# ]
# )
github_logo = Tpl(className='w-full',
tpl='<div class="flex justify-between"><div></div><div><a href="https://github.com/CMHopeSunshine/LittlePaimon" target="_blank" title="Copyright"><i class="fa fa-github fa-2x"></i></a></div></div>')
@ -29,9 +18,9 @@ admin_app = App(brandName='LittlePaimon',
pages=[{
'children': [
home_page,
PageSchema(label='Cookie管理', url='/cookie', icon='fa fa-key',
PageSchema(label='Cookie管理', icon='fa fa-key',
children=[public_cookie_page, private_cookie_page]),
PageSchema(label='机器人配置', url='/config', icon='fa fa-wrench',
PageSchema(label='机器人配置', icon='fa fa-wrench',
children=[plugin_manage_page, config_page]),
]}],
footer=f'<div class="p-2 text-center bg-blue-100">Copyright © 2021 - 2022 <a href="https://github.com/CMHopeSunshine/LittlePaimon" target="_blank" class="link-secondary">LittlePaimon v{__version__}</a> X<a target="_blank" href="https://github.com/baidu/amis" class="link-secondary" rel="noopener"> amis v2.2.0</a></div>')

View File

@ -135,4 +135,4 @@ cards_curd = CardsCRUD(mode='cards',
footerToolbar=['switch-per-page', 'pagination'],
columnsCount=3,
card=card)
page = PageSchema(url='/plugins', label='插件管理', schema=Page(title='插件管理', body=cards_curd))
page = PageSchema(url='/bot_config/plugins', icon='fa fa-cube', label='插件管理', schema=Page(title='插件管理', body=cards_curd))

View File

@ -1,18 +1,20 @@
from amis import Page, PageSchema, ActionType, LevelEnum, Dialog, Form, InputNumber, Textarea, Action, Static, TableCRUD, TableColumn, ColumnOperation
from amis import Page, PageSchema, ActionType, LevelEnum, Dialog, Form, InputNumber, Textarea, Action, Static, \
TableCRUD, TableColumn, ColumnOperation
from .constants import status_map, status_filter
add_button = ActionType.Dialog(label='添加私人Cookie',
level=LevelEnum.primary,
dialog=Dialog(title='添加私人Cookie',
body=Form(api='post:/LittlePaimon/api/save_private_cookie',
body=Form(api='post:/LittlePaimon/api/save_private_cookie?force=false',
body=[InputNumber(name='user_id', label='QQ号', required=True),
Textarea(name='cookie', label='Cookie', required=True,showCounter=False)])))
Textarea(name='cookie', label='Cookie', required=True,
showCounter=False)])))
delete_button = ActionType.Ajax(label='删除', level=LevelEnum.danger,
confirmText='确认删除该私人Cookie',
api='delete:/LittlePaimon/api/delete_private_cookie?id=${id}')
save_action_button = Action(label='保存修改', level=LevelEnum.warning, type='submit')
cancel_action_button = Action(label='关闭', level=LevelEnum.default, actionType='close')
detail_button = ActionType.Dialog(label='详情',
detail_button = ActionType.Dialog(label='修改',
level=LevelEnum.info,
dialog=Dialog(title='Cookie详情',
body=Form(
@ -21,9 +23,24 @@ detail_button = ActionType.Dialog(label='详情',
InputNumber(name='user_id', label='QQ号', required=True),
Static(name='uid', label='UID'),
Static(name='mys_id', label='米游社ID'),
Textarea(name='cookie', label='Cookie', required=True,showCounter=False),
Textarea(name='cookie', label='Cookie', required=True,
showCounter=False),
Static(name='stoken', label='Stoken')]),
actions=[cancel_action_button, save_action_button]))
force_button = ActionType.Dialog(label='强制修改',
level=LevelEnum.warning,
confirmText='强制修改Cookie不会对Cookie有效性和与uid的关联性进行校验如果你不确定是否正确有效请不要强制修改。',
dialog=Dialog(title='Cookie详情强制修改',
body=Form(
api='post:/LittlePaimon/api/save_private_cookie?force=true',
body=[Static(name='id', label='ID'),
InputNumber(name='user_id', label='QQ号', required=True),
InputNumber(name='uid', label='UID', required=True),
InputNumber(name='mys_id', label='米游社ID', required=True),
Textarea(name='cookie', label='Cookie', required=True,
showCounter=False),
Textarea(name='stoken', label='Stoken', showCounter=False)]),
actions=[cancel_action_button, Action(label='保存修改', level=LevelEnum.warning, type='submit', confirmText='强制修改Cookie不会对Cookie有效性和与uid的关联性进行校验如果你不确定是否正确有效请不要强制修改。')]))
table = TableCRUD(mode='table',
title='',
syncLocation=False,
@ -34,8 +51,8 @@ table = TableCRUD(mode='table',
TableColumn(label='米游社ID', name='mys_id', searchable=True),
TableColumn(type='mapping', label='状态', name='status', filterable=status_filter,
map=status_map),
ColumnOperation(label='操作', buttons=[detail_button, delete_button])],
ColumnOperation(label='操作', buttons=[detail_button, force_button, delete_button])],
headerToolbar=[add_button],
footerToolbar=['switch-per-page', 'pagination'])
page = PageSchema(url='/private_cookie', label='私人Cookie', schema=Page(title='私人Cookie', body=table))
page = PageSchema(url='/cookie/private', icon='fa fa-key', label='私人Cookie', schema=Page(title='私人Cookie', body=table))

View File

@ -1,11 +1,21 @@
from amis import Page, PageSchema, ActionType, LevelEnum, Dialog, Form, Textarea, TableCRUD, TableColumn, ColumnOperation
from amis import Page, PageSchema, ActionType, LevelEnum, Dialog, Form, Textarea, TableCRUD, TableColumn, \
ColumnOperation
from .constants import status_map, status_filter
add_button = ActionType.Dialog(label='添加公共Cookie',
level=LevelEnum.primary,
dialog=Dialog(title='添加公共Cookie',
body=Form(api='post:/LittlePaimon/api/add_public_cookie',
body=[Textarea(name='cookie', label='Cookie', required=True,showCounter=False)])))
body=Form(api='post:/LittlePaimon/api/add_public_cookie?force=false',
body=[Textarea(name='cookie', label='Cookie', required=True,
showCounter=False)])))
add_button_force = ActionType.Dialog(label='强制添加公共Cookie',
level=LevelEnum.warning,
confirmText='强制添加公共Cookie不会对Cookie有效性进行校验如果你不确定是否正确有效请不要强制添加。',
dialog=Dialog(title='强制添加公共Cookie',
body=Form(api='post:/LittlePaimon/api/add_public_cookie?force=true',
body=[
Textarea(name='cookie', label='Cookie', required=True,
showCounter=False)])))
delete_button = ActionType.Ajax(label='删除', level=LevelEnum.danger,
confirmText='确认删除该公共Cookie',
api='delete:/LittlePaimon/api/delete_public_cookie?id=${id}')
@ -15,7 +25,9 @@ table = TableCRUD(mode='table',
api='/LittlePaimon/api/get_public_cookies',
columns=[TableColumn(label='ID', name='id', width='8%'),
TableColumn(label='Cookie', name='cookie', width='64%'),
TableColumn(type='mapping', label='状态', name='status', filterable=status_filter, map=status_map, width='12%'),
TableColumn(type='mapping', label='状态', name='status', filterable=status_filter,
map=status_map, width='12%'),
ColumnOperation(label='操作', buttons=[delete_button], width='16%')],
headerToolbar=[add_button])
page = PageSchema(label='公共Cookie', url='public_cookie', schema=Page(title='公共Cookie', body=table))
headerToolbar=[add_button, add_button_force])
page = PageSchema(label='公共Cookie', icon='fa fa-key', url='/cookie/public',
schema=Page(title='公共Cookie', body=table))

View File

@ -7,7 +7,7 @@
<p align="center">
<a href="https://cdn.jsdelivr.net/gh/CMHopeSunshine/LittlePaimon@master/LICENSE"><img src="https://img.shields.io/github/license/CMHopeSunshine/LittlePaimon" alt="license"></a>
<img src="https://img.shields.io/badge/Python-3.8+-yellow" alt="python">
<img src="https://img.shields.io/badge/Version-3.0.0rc1-green" alt="version">
<img src="https://img.shields.io/badge/Version-3.0.0rc2-green" alt="version">
<a href="https://qun.qq.com/qqweb/qunpro/share?_wv=3&_wwv=128&inviteCode=MmWrI&from=246610&biz=ka"><img src="https://img.shields.io/badge/QQ频道交流-尘世闲游-blue?style=flat-square" alt="QQ guild"></a>
</p>
@ -64,14 +64,12 @@
文档地址https://docs.paimon.cherishmoon.fun/
## | TODO
- [x] Web管理面板
- [ ] 群聊学习配置 <img src="https://progress-bar.dev/75/" alt="bar">
- [ ] 实时日志和Shell <img src="https://progress-bar.dev/30/" alt="bar">
- [ ] 角色数据管理
- [ ] 功能调用统计
- [ ] 群聊学习优化 <img src="https://progress-bar.dev/75/" alt="bar">
- [ ] 米游社up主订阅 <img src="https://progress-bar.dev/25/" alt="bar">
- [ ] 各种文案提示支持自定义 <img src="https://progress-bar.dev/25/" alt="bar">
- [ ] 角色数据优化
- [ ] 更新机器人方式优化
## | 常见问题&致谢
详见[常见问题](https://docs.paimon.cherishmoon.fun/question.html)和[致谢](https://docs.paimon.cherishmoon.fun/thanks.html)。
## | 其他
- 如果你喜欢这个项目欢迎给个star或者[爱发电](https://afdian.net/a/cherishmoon),十分感谢。
- 本项目完全开源免费,仅供学习使用,禁止用于商业用途和非法行为,如有他人非法使用,与本作者无关。
- 如果您使用并修改了本项目源码,请遵循[GPL-3.0](https://github.com/CMHopeSunshine/LittlePaimon/blob/Bot/LICENSE)将源码开源。