diff --git a/editor/server/share.py b/editor/server/share.py index ff044a5..e8840fa 100644 --- a/editor/server/share.py +++ b/editor/server/share.py @@ -2,7 +2,10 @@ import random import string +from typing import cast + +from cloudflare_error_page import ErrorPageParams from flask import ( Blueprint, current_app, @@ -85,7 +88,7 @@ def get(name: str): }) else: return abort(404) - params: dict = item.params + params = cast(ErrorPageParams, item.params) params.pop('time', None) params.pop('ray_id', None) params.pop('client_ip', None) diff --git a/editor/server/utils.py b/editor/server/utils.py index 02129f5..1de753d 100644 --- a/editor/server/utils.py +++ b/editor/server/utils.py @@ -1,5 +1,6 @@ import json import os +import re from typing import Any from cloudflare_error_page import ( @@ -17,8 +18,7 @@ env = Environment( trim_blocks=True, lstrip_blocks=True, ) -template = env.from_string(''' -{% extends base %} +template = env.from_string('''{% extends base %} {% block header %} {% if page_icon_url %} @@ -32,8 +32,8 @@ template = env.from_string(''' - - + + {% if page_image_url %} {% endif %} @@ -41,7 +41,7 @@ template = env.from_string(''' - + {% if page_image_url %} {% endif %} @@ -122,6 +122,9 @@ def render_extended_template(params: ErrorPageParams, *args: Any, **kwargs: Any) -> str: fill_cf_template_params(params) + description = params.get('what_happened') or 'Cloudflare error page' + description = re.sub(r'', '', description).strip() + page_image_id = 'ok' cf_status_obj = params.get('cloudflare_status') if cf_status_obj: @@ -134,8 +137,8 @@ def render_extended_template(params: ErrorPageParams, base=base_template, page_icon_url=current_app.config.get('PAGE_ICON_URL'), page_icon_type=current_app.config.get('PAGE_ICON_TYPE'), - url=request.url, - description='Cloudflare error page', + page_url=request.url, + page_description=description, page_image_url=page_image_url, *args, **kwargs)