diff --git a/openplugin/template/utils.py b/openplugin/template/utils.py index 11ad9c9..ce98ebe 100644 --- a/openplugin/template/utils.py +++ b/openplugin/template/utils.py @@ -15,6 +15,7 @@ # limitations under the License. """""" +from jinja2 import Template def render_ROOT_URL(text: str, request=None) -> str: @@ -23,5 +24,8 @@ def render_ROOT_URL(text: str, request=None) -> str: ROOT_URL = request.url_root if ROOT_URL.endswith("/"): ROOT_URL = ROOT_URL[:-1] - text = text.replace("{% ROOT_URL %}", ROOT_URL) - return text + + template = Template(text) + rendered_text = template.render(ROOT_URL=ROOT_URL) + # text = text.replace("{{ROOT_URL}}", ROOT_URL) + return rendered_text diff --git a/openplugin/utils/app_util.py b/openplugin/utils/app_util.py index ea8dbd9..c902835 100644 --- a/openplugin/utils/app_util.py +++ b/openplugin/utils/app_util.py @@ -357,16 +357,16 @@ def write_error(sock, status_int, reason, mesg): html_error = ( textwrap.dedent( """\ - - - %(reason)s - - -

%(reason)s

- %(mesg)s - - - """ + + + %(reason)s + + +

%(reason)s

+ %(mesg)s + + + """ ) % {"reason": reason, "mesg": html.escape(mesg)} ) @@ -374,12 +374,12 @@ def write_error(sock, status_int, reason, mesg): http = ( textwrap.dedent( """\ - HTTP/1.1 %s %s\r - Connection: close\r - Content-Type: text/html\r - Content-Length: %d\r - \r - %s""" + HTTP/1.1 %s %s\r + Connection: close\r + Content-Type: text/html\r + Content-Length: %d\r + \r + %s""" ) % (str(status_int), reason, len(html_error), html_error) ) diff --git a/plugins/QRcode_plugin/openapi.yaml b/plugins/QRcode_plugin/openapi.yaml index c51f3b9..2ad3a3c 100644 --- a/plugins/QRcode_plugin/openapi.yaml +++ b/plugins/QRcode_plugin/openapi.yaml @@ -5,7 +5,7 @@ info: version: 1.0.0 servers: - - url: {% ROOT_URL %} + - url: {{ROOT_URL}} paths: /qrcode_image: diff --git a/plugins/ikun_plugin/openapi.yaml b/plugins/ikun_plugin/openapi.yaml index 2d037db..e9e2122 100644 --- a/plugins/ikun_plugin/openapi.yaml +++ b/plugins/ikun_plugin/openapi.yaml @@ -5,7 +5,7 @@ info: version: 1.0.0 servers: - - url: {% ROOT_URL %} + - url: {{ROOT_URL}} paths: /ikun_image: diff --git a/plugins/todo_plugin/ai-plugin.json b/plugins/todo_plugin/ai-plugin.json index 767095b..e914772 100644 --- a/plugins/todo_plugin/ai-plugin.json +++ b/plugins/todo_plugin/ai-plugin.json @@ -9,9 +9,9 @@ }, "api": { "type": "openapi", - "url": "{% ROOT_URL %}/openapi.yaml" + "url": "{{ROOT_URL}}/openapi.yaml" }, - "logo_url": "{% ROOT_URL %}/logo.png", + "logo_url": "{{ROOT_URL}}/logo.png", "contact_email": "huangsy1314@163.com", "legal_info_url": "http://example.com/legal" } diff --git a/plugins/todo_plugin/openapi.yaml b/plugins/todo_plugin/openapi.yaml index 29ebe25..1d96dbb 100644 --- a/plugins/todo_plugin/openapi.yaml +++ b/plugins/todo_plugin/openapi.yaml @@ -4,7 +4,7 @@ info: description: A plugin that allows the user to create and manage a TODO list using ChatGPT. If you do not know the user's username, ask them first before making queries to the plugin. Otherwise, use the username "global". version: 'v1' servers: - - url: {% ROOT_URL %} + - url: {{ROOT_URL}} paths: /todos/{username}: get: diff --git a/setup.py b/setup.py index ef29cb6..0524a7c 100644 --- a/setup.py +++ b/setup.py @@ -38,6 +38,7 @@ def get_install_requires() -> list: "ifaddr", "numpy", "requests", + "jinja2", ]