feat(图片管理): 添加图片尺寸配置支持
在 config.toml 中新增 image_manager 配置块,包含图片高度和宽度设置 修改 ImageManager 类以使用配置中的尺寸,替代硬编码值 添加 ImageManagerModel 配置模型并集成到全局配置中
This commit is contained in:
@@ -7,7 +7,7 @@ from pathlib import Path
|
||||
|
||||
import tomllib
|
||||
from pydantic import ValidationError
|
||||
from .config_models import ConfigModel, NapCatWSModel, BotModel, RedisModel, DockerModel
|
||||
from .config_models import ConfigModel, NapCatWSModel, BotModel, RedisModel, DockerModel, ImageManagerModel
|
||||
from .utils.logger import ModuleLogger
|
||||
from .utils.exceptions import ConfigError, ConfigNotFoundError, ConfigValidationError
|
||||
|
||||
@@ -114,6 +114,13 @@ class Config:
|
||||
获取 Docker 配置
|
||||
"""
|
||||
return self._model.docker
|
||||
|
||||
@property
|
||||
def image_manager(self) -> ImageManagerModel:
|
||||
"""
|
||||
获取图片生成管理器配置
|
||||
"""
|
||||
return self._model.image_manager
|
||||
|
||||
|
||||
# 实例化全局配置对象
|
||||
|
||||
@@ -49,6 +49,13 @@ class DockerModel(BaseModel):
|
||||
client_cert_path: Optional[str] = None
|
||||
client_key_path: Optional[str] = None
|
||||
|
||||
class ImageManagerModel(BaseModel):
|
||||
"""
|
||||
对应 `config.toml` 中的 `[image_manager]` 配置块。
|
||||
"""
|
||||
image_height: int = 1920
|
||||
image_width: int = 1080
|
||||
|
||||
|
||||
class ConfigModel(BaseModel):
|
||||
"""
|
||||
@@ -58,3 +65,6 @@ class ConfigModel(BaseModel):
|
||||
bot: BotModel
|
||||
redis: RedisModel
|
||||
docker: DockerModel
|
||||
image_manager: ImageManagerModel
|
||||
|
||||
|
||||
|
||||
File diff suppressed because one or more lines are too long
@@ -12,6 +12,7 @@ from jinja2 import Template
|
||||
from .browser_manager import browser_manager
|
||||
from ..utils.logger import logger
|
||||
from ..utils.singleton import Singleton
|
||||
from ..config_loader import global_config
|
||||
|
||||
class ImageManager(Singleton):
|
||||
"""
|
||||
@@ -73,8 +74,8 @@ class ImageManager(Singleton):
|
||||
return None
|
||||
|
||||
try:
|
||||
width = 1920
|
||||
height = 1080
|
||||
width = global_config.image_manager.image_width
|
||||
height = global_config.image_manager.image_height
|
||||
await page.set_viewport_size({"width": width, "height": height})
|
||||
|
||||
# 加载内容
|
||||
|
||||
Reference in New Issue
Block a user