feat:允许html_render方法传入配置参数
This commit is contained in:
@@ -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):
|
||||
|
||||
@@ -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())
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user