Fix IO rendering in the previewer and template editor (#3228)

This commit is contained in:
Aristotelis 2024-06-08 14:18:58 +02:00 committed by GitHub
parent 205068a993
commit 549cc467b6
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 19 additions and 6 deletions

View file

@ -69,15 +69,17 @@ class NotFound:
DynamicRequest = Callable[[], Response] DynamicRequest = Callable[[], Response]
class PageContext(enum.Enum): class PageContext(enum.IntEnum):
UNKNOWN = 0 UNKNOWN = enum.auto()
EDITOR = 1 EDITOR = enum.auto()
REVIEWER = 2 REVIEWER = enum.auto()
PREVIEWER = enum.auto()
CARD_LAYOUT = enum.auto()
# something in /_anki/pages/ # something in /_anki/pages/
NON_LEGACY_PAGE = 3 NON_LEGACY_PAGE = enum.auto()
# Do not use this if you present user content (e.g. content from cards), as it's a # Do not use this if you present user content (e.g. content from cards), as it's a
# security issue. # security issue.
ADDON_PAGE = 4 ADDON_PAGE = enum.auto()
@dataclass @dataclass
@ -694,6 +696,11 @@ def _check_dynamic_request_permissions():
): ):
# reviewer is only allowed to access custom study methods # reviewer is only allowed to access custom study methods
pass pass
elif (
context == PageContext.PREVIEWER or context == PageContext.CARD_LAYOUT
) and request.path == "/_anki/i18nResources":
# previewers are only allowed to access i18n resources
pass
else: else:
# other legacy pages may contain third-party JS, so we do not # other legacy pages may contain third-party JS, so we do not
# allow them to access our API # allow them to access our API

View file

@ -584,6 +584,8 @@ html {{ {font} }}
{web_content.body}</body> {web_content.body}</body>
</html>""" </html>"""
# print(html) # print(html)
import aqt.browser.previewer
import aqt.clayout
import aqt.editor import aqt.editor
import aqt.reviewer import aqt.reviewer
from aqt.mediasrv import PageContext from aqt.mediasrv import PageContext
@ -592,6 +594,10 @@ html {{ {font} }}
page_context = PageContext.EDITOR page_context = PageContext.EDITOR
elif isinstance(context, aqt.reviewer.Reviewer): elif isinstance(context, aqt.reviewer.Reviewer):
page_context = PageContext.REVIEWER page_context = PageContext.REVIEWER
elif isinstance(context, aqt.browser.previewer.Previewer):
page_context = PageContext.PREVIEWER
elif isinstance(context, aqt.clayout.CardLayout):
page_context = PageContext.CARD_LAYOUT
else: else:
page_context = PageContext.UNKNOWN page_context = PageContext.UNKNOWN
self.setHtml(html, page_context) self.setHtml(html, page_context)