From 27c97174451bb0d29f4e181b653301d0a99ac48f Mon Sep 17 00:00:00 2001
From: Ruochen <1051989940@qq.com>
Date: Fri, 27 Jun 2025 17:03:26 +0800
Subject: [PATCH 1/4] =?UTF-8?q?feat:=E5=85=81=E8=AE=B8html=5Frender?=
=?UTF-8?q?=E6=96=B9=E6=B3=95=E4=BC=A0=E5=85=A5=E9=85=8D=E7=BD=AE=E5=8F=82?=
=?UTF-8?q?=E6=95=B0?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
astrbot/core/star/__init__.py | 6 ++++--
astrbot/core/utils/t2i/network_strategy.py | 16 ++++++++++------
astrbot/core/utils/t2i/renderer.py | 13 +++++++++----
3 files changed, 23 insertions(+), 12 deletions(-)
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/utils/t2i/network_strategy.py b/astrbot/core/utils/t2i/network_strategy.py
index f8f54b0dc..49588204f 100644
--- a/astrbot/core/utils/t2i/network_strategy.py
+++ b/astrbot/core/utils/t2i/network_strategy.py
@@ -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,
) -> str:
"""使用自定义文转图模板"""
+ default_options = {"full_page": True, "type": "jpeg", "quality": 40}
+ if options:
+ default_options.update(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..ddfd2d0da 100644
--- a/astrbot/core/utils/t2i/renderer.py
+++ b/astrbot/core/utils/t2i/renderer.py
@@ -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,
):
"""使用自定义文转图模板。该方法会通过网络调用 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
From 80d2ad40bc299d92e317a71cc894803d6e4885dc Mon Sep 17 00:00:00 2001
From: Magstic <43901908+Magstic@users.noreply.github.com>
Date: Wed, 25 Jun 2025 17:55:20 +0800
Subject: [PATCH 2/4] =?UTF-8?q?fix:=20=E4=BB=AA=E8=A1=A8=E7=9B=98=E7=9A=84?=
=?UTF-8?q?=E3=80=8E=E6=8F=92=E4=BB=B6=E9=85=8D=E7=BD=AE=E3=80=8F=E4=B8=AD?=
=?UTF-8?q?=E4=B8=8D=E6=98=BE=E7=A4=BA=20JSON=20=E7=BC=96=E8=BE=91?=
=?UTF-8?q?=E7=AA=97?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
该提交与 #1919 关联。
精准定位错误 @Pine-Ln,Fix from Gemini 2.5 Pro.
这个问题是由两个错误叠加造成的:
1. **组件崩溃**:`AstrBotConfig.vue` 混用了 Vue 3 的 `
\ No newline at end of file
+
From 9a9017bc6c8881e7d5b261399895753c2d4f8894 Mon Sep 17 00:00:00 2001
From: Soulter <37870767+Soulter@users.noreply.github.com>
Date: Sat, 28 Jun 2025 14:46:29 +0800
Subject: [PATCH 3/4] perf: use union oper for merging dict
Co-authored-by: sourcery-ai[bot] <58596630+sourcery-ai[bot]@users.noreply.github.com>
---
astrbot/core/utils/t2i/network_strategy.py | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/astrbot/core/utils/t2i/network_strategy.py b/astrbot/core/utils/t2i/network_strategy.py
index 49588204f..3bd8e15fd 100644
--- a/astrbot/core/utils/t2i/network_strategy.py
+++ b/astrbot/core/utils/t2i/network_strategy.py
@@ -43,7 +43,7 @@ class NetworkRenderStrategy(RenderStrategy):
"""使用自定义文转图模板"""
default_options = {"full_page": True, "type": "jpeg", "quality": 40}
if options:
- default_options.update(options)
+ default_options |= options
post_data = {
"tmpl": tmpl_str,
From d14513ddfd953c7e11d8ffd31ce77385841b5445 Mon Sep 17 00:00:00 2001
From: Soulter <905617992@qq.com>
Date: Sat, 28 Jun 2025 14:51:35 +0800
Subject: [PATCH 4/4] fix: lint warnings
---
astrbot/core/star/filter/command.py | 4 ++--
astrbot/core/utils/t2i/network_strategy.py | 4 ++--
astrbot/core/utils/t2i/renderer.py | 4 ++--
3 files changed, 6 insertions(+), 6 deletions(-)
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 3bd8e15fd..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
@@ -38,7 +38,7 @@ class NetworkRenderStrategy(RenderStrategy):
tmpl_str: str,
tmpl_data: dict,
return_url: bool = True,
- options: dict = None,
+ options: dict | None = None,
) -> str:
"""使用自定义文转图模板"""
default_options = {"full_page": True, "type": "jpeg", "quality": 40}
diff --git a/astrbot/core/utils/t2i/renderer.py b/astrbot/core/utils/t2i/renderer.py
index ddfd2d0da..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()
@@ -20,7 +20,7 @@ class HtmlRenderer:
tmpl_str: str,
tmpl_data: dict,
return_url: bool = False,
- options: dict = None,
+ options: dict | None = None,
):
"""使用自定义文转图模板。该方法会通过网络调用 t2i 终结点图文渲染API。
@param tmpl_str: HTML Jinja2 模板。