mirror of
https://github.com/Genshin-bots/gsuid_core.git
synced 2025-05-12 06:55:49 +08:00
✨ 提供插件配置插槽
This commit is contained in:
parent
a139a180d3
commit
256956c55e
@ -17,6 +17,12 @@ from gsuid_core.handler import handle_event # noqa: E402
|
||||
from gsuid_core.models import MessageReceive # noqa: E402
|
||||
from gsuid_core.webconsole.mount_app import site # noqa: E402
|
||||
from gsuid_core.aps import start_scheduler, shutdown_scheduler # noqa: E402
|
||||
from gsuid_core.utils.plugins_config.models import ( # noqa: E402
|
||||
GsListStrConfig,
|
||||
)
|
||||
from gsuid_core.utils.plugins_config.gs_config import ( # noqa: E402
|
||||
all_config_list,
|
||||
)
|
||||
|
||||
app = FastAPI()
|
||||
HOST = core_config.get_config('HOST')
|
||||
@ -76,20 +82,19 @@ def main():
|
||||
data['white_list'] = []
|
||||
sv.set(**data)
|
||||
|
||||
'''
|
||||
@app.post('/genshinuid/setGsConfig')
|
||||
@app.post('/genshinuid/setGsConfig/{config_name}')
|
||||
@site.auth.requires('admin')
|
||||
async def _set_Config(request: Request, data: Dict):
|
||||
async def _set_Config(request: Request, data: Dict, config_name: str):
|
||||
for name in data:
|
||||
if name == 'params':
|
||||
continue
|
||||
config = gsconfig[name]
|
||||
config = all_config_list[config_name][name]
|
||||
if isinstance(config, GsListStrConfig):
|
||||
value = data[name].split(':')
|
||||
else:
|
||||
value = data[name]
|
||||
gsconfig.set_config(name, value)
|
||||
'''
|
||||
all_config_list[config_name].set_config(name, value)
|
||||
|
||||
site.mount_app(app)
|
||||
|
||||
uvicorn.run(
|
||||
|
@ -14,6 +14,7 @@ from typing import Any, Dict, List, Union, Literal, Optional, cast
|
||||
from aiohttp import ClientSession, ContentTypeError
|
||||
|
||||
from gsuid_core.logger import logger
|
||||
from gsuid_core.utils.plugins_config.gs_config import core_plugins_config
|
||||
|
||||
from .api import _API
|
||||
from .tools import (
|
||||
@ -62,9 +63,11 @@ RECOGNIZE_SERVER = {
|
||||
'9': 'os_cht',
|
||||
}
|
||||
|
||||
proxy_url = core_plugins_config.get_config('proxy').data
|
||||
|
||||
|
||||
class BaseMysApi:
|
||||
proxy_url: Optional[str] = None
|
||||
proxy_url: Optional[str] = proxy_url if proxy_url else None
|
||||
mysVersion = '2.44.1'
|
||||
_HEADER = {
|
||||
'x-rpc-app_version': mysVersion,
|
||||
@ -214,6 +217,44 @@ class BaseMysApi:
|
||||
|
||||
|
||||
class MysApi(BaseMysApi):
|
||||
async def _pass(self, gt: str, ch: str, header: Dict):
|
||||
# 警告:使用该服务(例如某RR等)需要注意风险问题
|
||||
# 本项目不以任何形式提供相关接口
|
||||
# 代码来源:GITHUB项目MIT开源
|
||||
_pass_api = core_plugins_config.get_config('_pass_API').data
|
||||
if _pass_api:
|
||||
data = await self._mys_request(
|
||||
url=f'{_pass_api}>={gt}&challenge={ch}',
|
||||
method='GET',
|
||||
header=header,
|
||||
)
|
||||
if isinstance(data, int):
|
||||
return None, None
|
||||
else:
|
||||
validate = data['data']['validate']
|
||||
ch = data['data']['challenge']
|
||||
else:
|
||||
validate = None
|
||||
|
||||
return validate, ch
|
||||
|
||||
async def _upass(self, header: Dict, is_bbs: bool = False):
|
||||
if is_bbs:
|
||||
raw_data = await self.get_bbs_upass_link(header)
|
||||
else:
|
||||
raw_data = await self.get_upass_link(header)
|
||||
if isinstance(raw_data, int):
|
||||
return False
|
||||
gt = raw_data['data']['gt']
|
||||
ch = raw_data['data']['challenge']
|
||||
|
||||
vl, ch = await self._pass(gt, ch, header)
|
||||
|
||||
if vl:
|
||||
await self.get_header_and_vl(header, ch, vl)
|
||||
else:
|
||||
return True
|
||||
|
||||
async def get_upass_link(self, header: Dict) -> Union[int, Dict]:
|
||||
header['DS'] = get_ds_token('is_high=false')
|
||||
return await self._mys_request(
|
||||
|
@ -1,5 +1,5 @@
|
||||
from pathlib import Path
|
||||
from typing import Dict, List, Union
|
||||
from typing import Any, Dict, List, Union
|
||||
|
||||
from msgspec import json as msgjson
|
||||
|
||||
@ -78,31 +78,36 @@ class StringConfig:
|
||||
# 重新写回
|
||||
self.write_config()
|
||||
|
||||
def get_config(self, key: str) -> GSC:
|
||||
def get_config(self, key: str) -> Any:
|
||||
if key in self.config:
|
||||
return self.config[key]
|
||||
elif key in self.config_list:
|
||||
logger.info(f'[配置] 配置项 {key} 不存在, 但是默认配置存在, 已更新...')
|
||||
logger.info(
|
||||
f'[配置][{self.config_name}] 配置项 {key} 不存在, 但是默认配置存在, 已更新...'
|
||||
)
|
||||
self.update_config()
|
||||
return self.config[key]
|
||||
else:
|
||||
logger.warning(f'[配置] 配置项 {key} 不存在也没有配置, 返回默认参数...')
|
||||
logger.warning(
|
||||
f'[配置][{self.config_name}] 配置项 {key} 不存在也没有配置, 返回默认参数...'
|
||||
)
|
||||
return GsBoolConfig('缺省值', '获取错误的配置项', False)
|
||||
|
||||
def set_config(
|
||||
self, key: str, value: Union[str, List, bool, Dict]
|
||||
) -> bool:
|
||||
if key in self.config_list:
|
||||
temp = self.config[key]
|
||||
temp = self.config[key].data
|
||||
if type(value) == type(temp):
|
||||
temp.data = value # type:ignore
|
||||
# 设置值
|
||||
self.config[key] = temp
|
||||
self.config[key].data = value # type: ignore
|
||||
# 重新写回
|
||||
self.write_config()
|
||||
return True
|
||||
else:
|
||||
logger.warning(f'[配置] 配置项 {key} 写入类型不正确, 停止写入...')
|
||||
logger.warning(
|
||||
f'[配置][{self.config_name}] 配置项 {key} 写入类型不正确, 停止写入...'
|
||||
)
|
||||
return False
|
||||
else:
|
||||
return False
|
||||
@ -111,5 +116,5 @@ class StringConfig:
|
||||
all_config_list: Dict[str, StringConfig] = {}
|
||||
|
||||
core_plugins_config = StringConfig(
|
||||
'core', get_res_path() / 'core_config.json', CONIFG_DEFAULT
|
||||
'Core', get_res_path() / 'core_config.json', CONIFG_DEFAULT
|
||||
)
|
||||
|
@ -11,6 +11,46 @@ from gsuid_core.webconsole.create_base_panel import (
|
||||
)
|
||||
|
||||
|
||||
def get_card_page(card_name: str):
|
||||
return {
|
||||
'type': 'service',
|
||||
'body': {
|
||||
'type': 'card',
|
||||
'header': {'title': card_name, 'subTitle': ''},
|
||||
'body': [],
|
||||
'actions': [
|
||||
{
|
||||
'type': 'button',
|
||||
'label': '确认修改',
|
||||
'id': 'u:5784cfaa5c0a',
|
||||
'actionType': 'ajax',
|
||||
'api': f'/genshinuid/setGsConfig/{card_name}',
|
||||
'onEvent': {
|
||||
'click': {
|
||||
'weight': 0,
|
||||
'actions': [
|
||||
{
|
||||
'args': {
|
||||
'msgType': 'success',
|
||||
'position': 'top-center',
|
||||
'closeButton': True,
|
||||
'showIcon': True,
|
||||
'msg': '成功设置!',
|
||||
'timeout': 100,
|
||||
},
|
||||
'actionType': 'toast',
|
||||
}
|
||||
],
|
||||
}
|
||||
},
|
||||
}
|
||||
],
|
||||
'id': 'u:69b06813bfbe',
|
||||
},
|
||||
'id': 'u:4c2981f6a055',
|
||||
}
|
||||
|
||||
|
||||
def get_config_page():
|
||||
page = {
|
||||
'type': 'page',
|
||||
@ -18,42 +58,10 @@ def get_config_page():
|
||||
'body': [],
|
||||
'id': 'u:a9be7e0dc626',
|
||||
}
|
||||
card = {
|
||||
'type': 'card',
|
||||
'header': {'title': '', 'subTitle': ''},
|
||||
'body': [],
|
||||
'actions': [
|
||||
{
|
||||
'type': 'button',
|
||||
'label': '确认修改',
|
||||
'id': 'u:5784cfaa5c0a',
|
||||
'actionType': 'ajax',
|
||||
'api': '/genshinuid/setGsConfig',
|
||||
'onEvent': {
|
||||
'click': {
|
||||
'weight': 0,
|
||||
'actions': [
|
||||
{
|
||||
'args': {
|
||||
'msgType': 'success',
|
||||
'position': 'top-center',
|
||||
'closeButton': True,
|
||||
'showIcon': True,
|
||||
'msg': '成功设置!',
|
||||
'timeout': 100,
|
||||
},
|
||||
'actionType': 'toast',
|
||||
}
|
||||
],
|
||||
}
|
||||
},
|
||||
}
|
||||
],
|
||||
'id': 'u:69b06813bfbe',
|
||||
}
|
||||
body = []
|
||||
solo_body = []
|
||||
for config_name in all_config_list:
|
||||
card = get_card_page(config_name)
|
||||
_config = all_config_list[config_name]
|
||||
for config in _config:
|
||||
gsc = _config[config]
|
||||
@ -68,7 +76,9 @@ def get_config_page():
|
||||
if len(solo_body) == 3:
|
||||
body.append(get_container_panel(solo_body))
|
||||
solo_body = []
|
||||
body.append(get_container_panel(solo_body))
|
||||
card['body'] = body
|
||||
page['body'].append(card)
|
||||
body.append(get_container_panel(solo_body))
|
||||
card['body']['body'] = body
|
||||
page['body'].append(card)
|
||||
body = []
|
||||
solo_body = []
|
||||
return page
|
||||
|
Loading…
x
Reference in New Issue
Block a user