diff --git a/astrbot/core/star/__init__.py b/astrbot/core/star/__init__.py
index ec1ee655b..f871c67c8 100644
--- a/astrbot/core/star/__init__.py
+++ b/astrbot/core/star/__init__.py
@@ -18,10 +18,12 @@ class Star(CommandParserMixin):
"""将文本转换为图片"""
return await html_renderer.render_t2i(text, return_url=return_url)
- async def html_render(self, tmpl: str, data: dict, return_url=True) -> str:
+ async def html_render(
+ self, tmpl: str, data: dict, return_url=True, options: dict = None
+ ) -> str:
"""渲染 HTML"""
return await html_renderer.render_custom_template(
- tmpl, data, return_url=return_url
+ tmpl, data, return_url=return_url, options=options
)
async def terminate(self):
diff --git a/astrbot/core/star/filter/command.py b/astrbot/core/star/filter/command.py
index 7d3cabbfa..32373db37 100755
--- a/astrbot/core/star/filter/command.py
+++ b/astrbot/core/star/filter/command.py
@@ -18,8 +18,8 @@ class CommandFilter(HandlerFilter):
def __init__(
self,
command_name: str,
- alias: set = None,
- handler_md: StarHandlerMetadata = None,
+ alias: set | None = None,
+ handler_md: StarHandlerMetadata | None = None,
parent_command_names: List[str] = [""],
):
self.command_name = command_name
diff --git a/astrbot/core/utils/t2i/network_strategy.py b/astrbot/core/utils/t2i/network_strategy.py
index f8f54b0dc..03db6d5e7 100644
--- a/astrbot/core/utils/t2i/network_strategy.py
+++ b/astrbot/core/utils/t2i/network_strategy.py
@@ -11,7 +11,7 @@ ASTRBOT_T2I_DEFAULT_ENDPOINT = "https://t2i.soulter.top/text2img"
class NetworkRenderStrategy(RenderStrategy):
- def __init__(self, base_url: str = ASTRBOT_T2I_DEFAULT_ENDPOINT) -> None:
+ def __init__(self, base_url: str | None = None) -> None:
super().__init__()
if not base_url:
base_url = ASTRBOT_T2I_DEFAULT_ENDPOINT
@@ -34,18 +34,22 @@ class NetworkRenderStrategy(RenderStrategy):
self.BASE_RENDER_URL += "/text2img"
async def render_custom_template(
- self, tmpl_str: str, tmpl_data: dict, return_url: bool = True
+ self,
+ tmpl_str: str,
+ tmpl_data: dict,
+ return_url: bool = True,
+ options: dict | None = None,
) -> str:
"""使用自定义文转图模板"""
+ default_options = {"full_page": True, "type": "jpeg", "quality": 40}
+ if options:
+ default_options |= options
+
post_data = {
"tmpl": tmpl_str,
"json": return_url,
"tmpldata": tmpl_data,
- "options": {
- "full_page": True,
- "type": "jpeg",
- "quality": 40,
- },
+ "options": default_options,
}
if return_url:
ssl_context = ssl.create_default_context(cafile=certifi.where())
diff --git a/astrbot/core/utils/t2i/renderer.py b/astrbot/core/utils/t2i/renderer.py
index 73e8eee66..9e423be15 100644
--- a/astrbot/core/utils/t2i/renderer.py
+++ b/astrbot/core/utils/t2i/renderer.py
@@ -6,7 +6,7 @@ logger = LogManager.GetLogger(log_name="astrbot")
class HtmlRenderer:
- def __init__(self, endpoint_url: str = None):
+ def __init__(self, endpoint_url: str | None = None):
self.network_strategy = NetworkRenderStrategy(endpoint_url)
self.local_strategy = LocalRenderStrategy()
@@ -16,19 +16,24 @@ class HtmlRenderer:
self.network_strategy.set_endpoint(endpoint_url)
async def render_custom_template(
- self, tmpl_str: str, tmpl_data: dict, return_url: bool = False
+ self,
+ tmpl_str: str,
+ tmpl_data: dict,
+ return_url: bool = False,
+ options: dict | None = None,
):
"""使用自定义文转图模板。该方法会通过网络调用 t2i 终结点图文渲染API。
@param tmpl_str: HTML Jinja2 模板。
@param tmpl_data: jinja2 模板数据。
+ @param options: 渲染选项。
@return: 图片 URL 或者文件路径,取决于 return_url 参数。
@example: 参见 https://astrbot.app 插件开发部分。
"""
- local = locals()
- local.pop("self")
- return await self.network_strategy.render_custom_template(**local)
+ return await self.network_strategy.render_custom_template(
+ tmpl_str, tmpl_data, return_url, options
+ )
async def render_t2i(
self, text: str, use_network: bool = True, return_url: bool = False
diff --git a/dashboard/src/components/shared/AstrBotConfig.vue b/dashboard/src/components/shared/AstrBotConfig.vue
index 104518d8c..5610e7bc4 100644
--- a/dashboard/src/components/shared/AstrBotConfig.vue
+++ b/dashboard/src/components/shared/AstrBotConfig.vue
@@ -1,6 +1,25 @@
\ No newline at end of file
+