feat(图片管理): 添加图片尺寸配置支持
在 config.toml 中新增 image_manager 配置块,包含图片高度和宽度设置 修改 ImageManager 类以使用配置中的尺寸,替代硬编码值 添加 ImageManagerModel 配置模型并集成到全局配置中
This commit is contained in:
@@ -47,3 +47,9 @@ ca_cert_path = "ca/ca.pem"
|
|||||||
client_cert_path = "ca/cert.pem"
|
client_cert_path = "ca/cert.pem"
|
||||||
# 客户端密钥路径(可选)
|
# 客户端密钥路径(可选)
|
||||||
client_key_path = "ca/key.pem"
|
client_key_path = "ca/key.pem"
|
||||||
|
|
||||||
|
[image_manager]
|
||||||
|
# 图片高度
|
||||||
|
image_height = 1920
|
||||||
|
# 图片宽度
|
||||||
|
image_width = 1080
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ from pathlib import Path
|
|||||||
|
|
||||||
import tomllib
|
import tomllib
|
||||||
from pydantic import ValidationError
|
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.logger import ModuleLogger
|
||||||
from .utils.exceptions import ConfigError, ConfigNotFoundError, ConfigValidationError
|
from .utils.exceptions import ConfigError, ConfigNotFoundError, ConfigValidationError
|
||||||
|
|
||||||
@@ -115,6 +115,13 @@ class Config:
|
|||||||
"""
|
"""
|
||||||
return self._model.docker
|
return self._model.docker
|
||||||
|
|
||||||
|
@property
|
||||||
|
def image_manager(self) -> ImageManagerModel:
|
||||||
|
"""
|
||||||
|
获取图片生成管理器配置
|
||||||
|
"""
|
||||||
|
return self._model.image_manager
|
||||||
|
|
||||||
|
|
||||||
# 实例化全局配置对象
|
# 实例化全局配置对象
|
||||||
global_config = Config()
|
global_config = Config()
|
||||||
|
|||||||
@@ -49,6 +49,13 @@ class DockerModel(BaseModel):
|
|||||||
client_cert_path: Optional[str] = None
|
client_cert_path: Optional[str] = None
|
||||||
client_key_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):
|
class ConfigModel(BaseModel):
|
||||||
"""
|
"""
|
||||||
@@ -58,3 +65,6 @@ class ConfigModel(BaseModel):
|
|||||||
bot: BotModel
|
bot: BotModel
|
||||||
redis: RedisModel
|
redis: RedisModel
|
||||||
docker: DockerModel
|
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 .browser_manager import browser_manager
|
||||||
from ..utils.logger import logger
|
from ..utils.logger import logger
|
||||||
from ..utils.singleton import Singleton
|
from ..utils.singleton import Singleton
|
||||||
|
from ..config_loader import global_config
|
||||||
|
|
||||||
class ImageManager(Singleton):
|
class ImageManager(Singleton):
|
||||||
"""
|
"""
|
||||||
@@ -73,8 +74,8 @@ class ImageManager(Singleton):
|
|||||||
return None
|
return None
|
||||||
|
|
||||||
try:
|
try:
|
||||||
width = 1920
|
width = global_config.image_manager.image_width
|
||||||
height = 1080
|
height = global_config.image_manager.image_height
|
||||||
await page.set_viewport_size({"width": width, "height": height})
|
await page.set_viewport_size({"width": width, "height": height})
|
||||||
|
|
||||||
# 加载内容
|
# 加载内容
|
||||||
|
|||||||
Reference in New Issue
Block a user