diff --git a/app/main.py b/app/main.py index ff4e4f52..6d06c32d 100644 --- a/app/main.py +++ b/app/main.py @@ -42,7 +42,7 @@ async def robots(request): app.run( host="0.0.0.0", port=5000, - auto_reload=settings.DEBUG, + debug=settings.DEBUG, access_log=False, motd=False, fast=True, diff --git a/app/utils/urls.py b/app/utils/urls.py index 9960edbe..af8a82f2 100644 --- a/app/utils/urls.py +++ b/app/utils/urls.py @@ -56,6 +56,7 @@ def clean(url: str) -> str: # Replace invalid regex escape sequences url = url.replace("\\", "~b") + url = url.replace("\n", "~n") # Replace spaces with underscores url = url.replace(" ", "_") diff --git a/app/views/shortcuts.py b/app/views/shortcuts.py index 76cbadf3..e30dc0c5 100644 --- a/app/views/shortcuts.py +++ b/app/views/shortcuts.py @@ -97,25 +97,34 @@ async def custom_path(request, template_id, text_paths): logger.warning(f"Fixing trailing quote: {text_paths}") text_paths = text_paths.rstrip('"') - if "." in text_paths.strip(".") and text_paths.split(".")[-1].isalnum(): - text_filepath = text_paths - elif text_paths.startswith("."): + if text_paths.startswith("."): return response.redirect( request.app.url_for( "images.detail_blank", template_filename=f"{template_id}{text_paths}", ) ) - else: - text_filepath = text_paths + "." + settings.DEFAULT_EXTENSION - if not settings.DEBUG: + try: + url = request.app.url_for( + "images.detail_text", + template_id=template_id, + text_filepath=text_paths, + **params, + ) + except exceptions.URLBuildError as e: + if "text_filepath" in str(e): + logger.warning(f"Handing missing extension: {e}") + else: + raise url = request.app.url_for( "images.detail_text", template_id=template_id, - text_filepath=text_filepath, + text_filepath=text_paths + "." + settings.DEFAULT_EXTENSION, **params, ) + + if not settings.DEBUG: return response.redirect(url) template = models.Template.objects.get_or_create(template_id)