mirror of
https://github.com/Genshin-bots/gsuid_core.git
synced 2025-05-09 05:25:48 +08:00
🎨 新增配置图片生成质量
, 并优化网页控制台弹窗
This commit is contained in:
parent
c1cc76abde
commit
1a94853751
1
.vscode/settings.json
vendored
1
.vscode/settings.json
vendored
@ -24,4 +24,5 @@
|
|||||||
"python.linting.flake8CategorySeverity.W": "Warning",
|
"python.linting.flake8CategorySeverity.W": "Warning",
|
||||||
"python.linting.flake8CategorySeverity.F": "Warning",
|
"python.linting.flake8CategorySeverity.F": "Warning",
|
||||||
"python.linting.flake8CategorySeverity.E": "Warning",
|
"python.linting.flake8CategorySeverity.E": "Warning",
|
||||||
|
"python.analysis.autoImportCompletions": true,
|
||||||
}
|
}
|
||||||
|
@ -7,7 +7,9 @@ from gsuid_core.sv import SV, Plugins
|
|||||||
|
|
||||||
# from gsuid_core.utils.image.image_tools import get_color_bg
|
# from gsuid_core.utils.image.image_tools import get_color_bg
|
||||||
from gsuid_core.utils.fonts.fonts import core_font
|
from gsuid_core.utils.fonts.fonts import core_font
|
||||||
|
from gsuid_core.utils.plugins_config.gs_config import pic_gen_config
|
||||||
|
|
||||||
|
pic_quality: int = pic_gen_config.get_config('PicQuality').data
|
||||||
TEXT_PATH = Path(__file__).parent / 'texture2d'
|
TEXT_PATH = Path(__file__).parent / 'texture2d'
|
||||||
CORE_HELP_IMG = Path(__file__).parent / 'core_help.jpg'
|
CORE_HELP_IMG = Path(__file__).parent / 'core_help.jpg'
|
||||||
|
|
||||||
@ -223,7 +225,7 @@ async def get_help_img() -> Image.Image:
|
|||||||
img.save(
|
img.save(
|
||||||
CORE_HELP_IMG,
|
CORE_HELP_IMG,
|
||||||
format='JPEG',
|
format='JPEG',
|
||||||
quality=80,
|
quality=pic_quality,
|
||||||
subsampling=0,
|
subsampling=0,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -7,12 +7,14 @@ from PIL import Image, ImageDraw, ImageFont, ImageFilter
|
|||||||
from gsuid_core.data_store import get_res_path
|
from gsuid_core.data_store import get_res_path
|
||||||
from gsuid_core.utils.image.convert import convert_img
|
from gsuid_core.utils.image.convert import convert_img
|
||||||
from gsuid_core.utils.image.image_tools import crop_center_img
|
from gsuid_core.utils.image.image_tools import crop_center_img
|
||||||
|
from gsuid_core.utils.plugins_config.gs_config import pic_gen_config
|
||||||
|
|
||||||
from .model import PluginHelp
|
from .model import PluginHelp
|
||||||
|
|
||||||
cache: Dict[str, int] = {}
|
cache: Dict[str, int] = {}
|
||||||
MICON_PATH = Path(__file__).parent / 'icon'
|
MICON_PATH = Path(__file__).parent / 'icon'
|
||||||
DEFAULT_ICON = MICON_PATH / '拼图.png'
|
DEFAULT_ICON = MICON_PATH / '拼图.png'
|
||||||
|
pic_quality: int = pic_gen_config.get_config('PicQuality').data
|
||||||
|
|
||||||
|
|
||||||
def cx(w: int, x: int) -> int:
|
def cx(w: int, x: int) -> int:
|
||||||
@ -211,7 +213,7 @@ async def get_help(
|
|||||||
img.save(
|
img.save(
|
||||||
help_path,
|
help_path,
|
||||||
'JPEG',
|
'JPEG',
|
||||||
quality=89,
|
quality=pic_quality,
|
||||||
subsampling=0,
|
subsampling=0,
|
||||||
)
|
)
|
||||||
cache[name] = 1
|
cache[name] = 1
|
||||||
|
@ -17,6 +17,7 @@ from gsuid_core.utils.image.convert import text2pic
|
|||||||
from gsuid_core.utils.image.image_tools import sget
|
from gsuid_core.utils.image.image_tools import sget
|
||||||
from gsuid_core.load_template import markdown_templates
|
from gsuid_core.load_template import markdown_templates
|
||||||
from gsuid_core.utils.plugins_config.gs_config import (
|
from gsuid_core.utils.plugins_config.gs_config import (
|
||||||
|
pic_gen_config,
|
||||||
send_pic_config,
|
send_pic_config,
|
||||||
pic_upload_config,
|
pic_upload_config,
|
||||||
core_plugins_config,
|
core_plugins_config,
|
||||||
@ -34,6 +35,8 @@ is_lf = core_plugins_config.get_config('UseCRLFReplaceLFForMD').data
|
|||||||
SERVER = pic_upload_config.get_config('PicUploadServer').data
|
SERVER = pic_upload_config.get_config('PicUploadServer').data
|
||||||
IS_UPLOAD = pic_upload_config.get_config('PicUpload').data
|
IS_UPLOAD = pic_upload_config.get_config('PicUpload').data
|
||||||
|
|
||||||
|
pic_quality: int = pic_gen_config.get_config('PicQuality').data
|
||||||
|
|
||||||
pclient = None
|
pclient = None
|
||||||
if IS_UPLOAD:
|
if IS_UPLOAD:
|
||||||
if SERVER == 'smms':
|
if SERVER == 'smms':
|
||||||
@ -62,7 +65,9 @@ class MessageSegment:
|
|||||||
if isinstance(img, Image.Image):
|
if isinstance(img, Image.Image):
|
||||||
img = img.convert('RGB')
|
img = img.convert('RGB')
|
||||||
result_buffer = BytesIO()
|
result_buffer = BytesIO()
|
||||||
img.save(result_buffer, format='PNG', quality=80, subsampling=0)
|
img.save(
|
||||||
|
result_buffer, format='PNG', quality=pic_quality, subsampling=0
|
||||||
|
)
|
||||||
img = result_buffer.getvalue()
|
img = result_buffer.getvalue()
|
||||||
elif isinstance(img, bytes):
|
elif isinstance(img, bytes):
|
||||||
pass
|
pass
|
||||||
|
@ -7,8 +7,11 @@ import aiofiles
|
|||||||
from PIL import Image, ImageDraw, ImageFont
|
from PIL import Image, ImageDraw, ImageFont
|
||||||
|
|
||||||
from gsuid_core.utils.fonts.fonts import core_font
|
from gsuid_core.utils.fonts.fonts import core_font
|
||||||
|
from gsuid_core.utils.plugins_config.gs_config import pic_gen_config
|
||||||
from gsuid_core.utils.image.image_tools import draw_center_text_by_line
|
from gsuid_core.utils.image.image_tools import draw_center_text_by_line
|
||||||
|
|
||||||
|
pic_quality: int = pic_gen_config.get_config('PicQuality').data
|
||||||
|
|
||||||
|
|
||||||
@overload
|
@overload
|
||||||
async def convert_img(img: Image.Image, is_base64: bool = False) -> bytes: ...
|
async def convert_img(img: Image.Image, is_base64: bool = False) -> bytes: ...
|
||||||
@ -41,7 +44,7 @@ async def convert_img(
|
|||||||
if isinstance(img, Image.Image):
|
if isinstance(img, Image.Image):
|
||||||
img = img.convert('RGB')
|
img = img.convert('RGB')
|
||||||
result_buffer = BytesIO()
|
result_buffer = BytesIO()
|
||||||
img.save(result_buffer, format='JPEG', quality=90)
|
img.save(result_buffer, format='JPEG', quality=pic_quality)
|
||||||
res = result_buffer.getvalue()
|
res = result_buffer.getvalue()
|
||||||
if is_base64:
|
if is_base64:
|
||||||
res = 'base64://' + b64encode(res).decode()
|
res = 'base64://' + b64encode(res).decode()
|
||||||
|
@ -7,6 +7,7 @@ from gsuid_core.logger import logger
|
|||||||
from gsuid_core.data_store import get_res_path
|
from gsuid_core.data_store import get_res_path
|
||||||
|
|
||||||
from .config_default import CONIFG_DEFAULT
|
from .config_default import CONIFG_DEFAULT
|
||||||
|
from .pic_gen_config import PIC_GEN_CONIFG
|
||||||
from .send_pic_config import SEND_PIC_CONIFG
|
from .send_pic_config import SEND_PIC_CONIFG
|
||||||
from .pic_server_config import PIC_UPLOAD_CONIFG
|
from .pic_server_config import PIC_UPLOAD_CONIFG
|
||||||
from .models import (
|
from .models import (
|
||||||
@ -167,3 +168,7 @@ pic_upload_config = StringConfig(
|
|||||||
send_pic_config = StringConfig(
|
send_pic_config = StringConfig(
|
||||||
'GsCore发送图片', get_res_path() / 'send_pic_config.json', SEND_PIC_CONIFG
|
'GsCore发送图片', get_res_path() / 'send_pic_config.json', SEND_PIC_CONIFG
|
||||||
)
|
)
|
||||||
|
|
||||||
|
pic_gen_config = StringConfig(
|
||||||
|
'GsCore图片生成', get_res_path() / 'pic_gen_config.json', PIC_GEN_CONIFG
|
||||||
|
)
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
from typing import Dict, List, Union
|
from typing import Dict, List, Union, Optional
|
||||||
|
|
||||||
import msgspec
|
import msgspec
|
||||||
|
|
||||||
@ -30,6 +30,16 @@ class GsListConfig(GsConfig, tag=True):
|
|||||||
data: List[int]
|
data: List[int]
|
||||||
|
|
||||||
|
|
||||||
|
class GsIntConfig(GsConfig, tag=True):
|
||||||
|
data: int
|
||||||
|
max_value: Optional[int] = None
|
||||||
|
|
||||||
|
|
||||||
GSC = Union[
|
GSC = Union[
|
||||||
GsDictConfig, GsBoolConfig, GsListConfig, GsListStrConfig, GsStrConfig
|
GsDictConfig,
|
||||||
|
GsBoolConfig,
|
||||||
|
GsListConfig,
|
||||||
|
GsListStrConfig,
|
||||||
|
GsStrConfig,
|
||||||
|
GsIntConfig,
|
||||||
]
|
]
|
||||||
|
9
gsuid_core/utils/plugins_config/pic_gen_config.py
Normal file
9
gsuid_core/utils/plugins_config/pic_gen_config.py
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
from typing import Dict
|
||||||
|
|
||||||
|
from .models import GSC, GsIntConfig
|
||||||
|
|
||||||
|
PIC_GEN_CONIFG: Dict[str, GSC] = {
|
||||||
|
'PicQuality': GsIntConfig(
|
||||||
|
'图片生成质量', '设定生成图片的质量, 最高不可超过100', 85, 100
|
||||||
|
),
|
||||||
|
}
|
@ -109,6 +109,7 @@ def _set_Config(request: Request, data: Dict, config_name: str):
|
|||||||
else:
|
else:
|
||||||
value = data[name]
|
value = data[name]
|
||||||
all_config_list[config_name].set_config(name, value)
|
all_config_list[config_name].set_config(name, value)
|
||||||
|
return {"status": 0, "msg": "成功!"}
|
||||||
|
|
||||||
|
|
||||||
@app.post('/genshinuid/setCoreConfig')
|
@app.post('/genshinuid/setCoreConfig')
|
||||||
|
@ -9,8 +9,10 @@ def get_service(body: List[Dict]):
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
def get_input_number(label: str, name: str, value: int):
|
def get_input_number(
|
||||||
return {
|
label: str, name: str, value: int, max_value: Optional[int] = None
|
||||||
|
):
|
||||||
|
data = {
|
||||||
'type': 'input-number',
|
'type': 'input-number',
|
||||||
'label': label,
|
'label': label,
|
||||||
'name': name,
|
'name': name,
|
||||||
@ -19,6 +21,9 @@ def get_input_number(label: str, name: str, value: int):
|
|||||||
'step': 1,
|
'step': 1,
|
||||||
'value': value,
|
'value': value,
|
||||||
}
|
}
|
||||||
|
if max_value is not None:
|
||||||
|
data['max'] = max_value
|
||||||
|
return data
|
||||||
|
|
||||||
|
|
||||||
def get_input_image_panel(label: str, name: str):
|
def get_input_image_panel(label: str, name: str):
|
||||||
@ -63,6 +68,10 @@ def get_button(title: str, api: Optional[Dict] = None):
|
|||||||
'onEvent': {'click': {'actions': []}},
|
'onEvent': {'click': {'actions': []}},
|
||||||
'id': 'u:2784abaa9455',
|
'id': 'u:2784abaa9455',
|
||||||
'block': True,
|
'block': True,
|
||||||
|
'messages': {
|
||||||
|
'success': '成功!',
|
||||||
|
'failed': '失败...请检查后台...',
|
||||||
|
},
|
||||||
}
|
}
|
||||||
if api:
|
if api:
|
||||||
data['onEvent']['click']['actions'].append(api)
|
data['onEvent']['click']['actions'].append(api)
|
||||||
@ -94,15 +103,15 @@ def get_text_panel(label: str, name: str, value: str):
|
|||||||
|
|
||||||
def get_alert(
|
def get_alert(
|
||||||
message: str,
|
message: str,
|
||||||
level: Literal["success", "warning", "info", 'danger'] = 'info',
|
level: Literal['success', 'warning', 'info', 'danger'] = 'info',
|
||||||
):
|
):
|
||||||
return {
|
return {
|
||||||
"type": "alert",
|
'type': 'alert',
|
||||||
"body": message,
|
'body': message,
|
||||||
"level": level,
|
'level': level,
|
||||||
"showCloseButton": True,
|
'showCloseButton': True,
|
||||||
"showIcon": True,
|
'showIcon': True,
|
||||||
"className": "mb-2",
|
'className': 'mb-2',
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -119,14 +128,14 @@ def get_select_panel(label: str, name: str, value: str, options: List[str]):
|
|||||||
|
|
||||||
def get_input_tag(label: str, name: str, value: List[str], options: List[str]):
|
def get_input_tag(label: str, name: str, value: List[str], options: List[str]):
|
||||||
return {
|
return {
|
||||||
"type": "input-tag",
|
'type': 'input-tag',
|
||||||
"label": label,
|
'label': label,
|
||||||
"name": name,
|
'name': name,
|
||||||
"options": [{'label': option, 'value': option} for option in options],
|
'options': [{'label': option, 'value': option} for option in options],
|
||||||
"id": "u:85ecb7894ccc",
|
'id': 'u:85ecb7894ccc',
|
||||||
"optionsTip": "最近您使用的标签",
|
'optionsTip': '最近您使用的标签',
|
||||||
"autoFill": {},
|
'autoFill': {},
|
||||||
"value": ','.join(value),
|
'value': ','.join(value),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -135,14 +144,14 @@ def get_divider():
|
|||||||
|
|
||||||
|
|
||||||
def get_empty():
|
def get_empty():
|
||||||
return {"body": [], "id": "u:d0bf1032034b"}
|
return {'body': [], 'id': 'u:d0bf1032034b'}
|
||||||
|
|
||||||
|
|
||||||
def get_grid_panel(content: List[Dict]):
|
def get_grid_panel(content: List[Dict]):
|
||||||
_data = []
|
_data = []
|
||||||
for i in content:
|
for i in content:
|
||||||
if i == {"body": [], "id": "u:d0bf1032034b"} or i == {}:
|
if i == {'body': [], 'id': 'u:d0bf1032034b'} or i == {}:
|
||||||
_data.append({"body": [], "id": "u:d0bf1032034b"})
|
_data.append({'body': [], 'id': 'u:d0bf1032034b'})
|
||||||
else:
|
else:
|
||||||
_data.append({'body': [i]})
|
_data.append({'body': [i]})
|
||||||
|
|
||||||
@ -161,9 +170,9 @@ def get_property(items: Union[List[Dict], Dict[str, str]], column: int = 2):
|
|||||||
_items = items
|
_items = items
|
||||||
|
|
||||||
data = {
|
data = {
|
||||||
"type": "property",
|
'type': 'property',
|
||||||
"column": column,
|
'column': column,
|
||||||
"items": _items,
|
'items': _items,
|
||||||
}
|
}
|
||||||
return data
|
return data
|
||||||
|
|
||||||
@ -171,24 +180,24 @@ def get_property(items: Union[List[Dict], Dict[str, str]], column: int = 2):
|
|||||||
def get_tag(
|
def get_tag(
|
||||||
label: str,
|
label: str,
|
||||||
color: Literal[
|
color: Literal[
|
||||||
"inactive", "processing", "success", "error", "active", "warning"
|
'inactive', 'processing', 'success', 'error', 'active', 'warning'
|
||||||
] = "processing",
|
] = 'processing',
|
||||||
displaymode: Literal["normal", "rounded"] = "normal",
|
displaymode: Literal['normal', 'rounded'] = 'normal',
|
||||||
):
|
):
|
||||||
return {
|
return {
|
||||||
"type": "tag",
|
'type': 'tag',
|
||||||
"label": label,
|
'label': label,
|
||||||
"displayMode": displaymode,
|
'displayMode': displaymode,
|
||||||
"color": color,
|
'color': color,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
def get_tpl(label: str = '', value: str = ''):
|
def get_tpl(label: str = '', value: str = ''):
|
||||||
return {
|
return {
|
||||||
"type": "tpl",
|
'type': 'tpl',
|
||||||
"tpl": value,
|
'tpl': value,
|
||||||
"inline": False,
|
'inline': False,
|
||||||
"label": label,
|
'label': label,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
from gsuid_core.utils.plugins_config.gs_config import all_config_list
|
from gsuid_core.utils.plugins_config.gs_config import all_config_list
|
||||||
from gsuid_core.utils.plugins_config.models import (
|
from gsuid_core.utils.plugins_config.models import (
|
||||||
|
GsIntConfig,
|
||||||
GsStrConfig,
|
GsStrConfig,
|
||||||
GsBoolConfig,
|
GsBoolConfig,
|
||||||
GsListStrConfig,
|
GsListStrConfig,
|
||||||
@ -14,6 +15,7 @@ from gsuid_core.webconsole.create_base_panel import (
|
|||||||
get_input_tag,
|
get_input_tag,
|
||||||
get_grid_panel,
|
get_grid_panel,
|
||||||
get_text_panel,
|
get_text_panel,
|
||||||
|
get_input_number,
|
||||||
get_select_panel,
|
get_select_panel,
|
||||||
get_switch_panel,
|
get_switch_panel,
|
||||||
)
|
)
|
||||||
@ -83,6 +85,12 @@ def get_config_page():
|
|||||||
else:
|
else:
|
||||||
_data = get_text_panel(gsc.title, config, gsc.data)
|
_data = get_text_panel(gsc.title, config, gsc.data)
|
||||||
solo_body.append(_data)
|
solo_body.append(_data)
|
||||||
|
elif isinstance(gsc, GsIntConfig):
|
||||||
|
solo_body.append(
|
||||||
|
get_input_number(
|
||||||
|
gsc.title, config, gsc.data, gsc.max_value
|
||||||
|
)
|
||||||
|
)
|
||||||
elif isinstance(gsc, GsBoolConfig):
|
elif isinstance(gsc, GsBoolConfig):
|
||||||
solo_body.append(get_switch_panel(gsc.title, config, gsc.data))
|
solo_body.append(get_switch_panel(gsc.title, config, gsc.data))
|
||||||
elif isinstance(gsc, GsListStrConfig):
|
elif isinstance(gsc, GsListStrConfig):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user