Skip to content

Commit

Permalink
Revert text converter
Browse files Browse the repository at this point in the history
It seems like WhiteNoise will intercept matching file paths regardless
of which Flask routes match.
  • Loading branch information
jacebrowning committed May 29, 2016
1 parent f5b66cc commit 2b80e7d
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 10 deletions.
6 changes: 0 additions & 6 deletions memegen/app.py
Expand Up @@ -2,7 +2,6 @@
import logging
from urllib.parse import urlencode, unquote

from werkzeug.routing import BaseConverter
from flask import request, current_app
from flask_api import FlaskAPI
from flask_api.exceptions import APIException, NotFound
Expand All @@ -15,10 +14,6 @@
log = logging.getLogger('api')


class TextConverter(BaseConverter):
regex = '[^/][^/]*/?[^/]*' # string with zero or one slash


class TemplateNotFound(NotFound):
detail = "Template not found."

Expand Down Expand Up @@ -106,7 +101,6 @@ def log_request(response):


def register_blueprints(app):
app.url_map.converters['text'] = TextConverter
app.register_blueprint(routes.aliases.blueprint)
app.register_blueprint(routes.image.blueprint)
app.register_blueprint(routes.index.blueprint)
Expand Down
4 changes: 2 additions & 2 deletions memegen/routes/image.py
Expand Up @@ -38,7 +38,7 @@ def get_without_text_jpeg(key):
return redirect(route('.get_without_text', key=key))


@blueprint.route(r"<key>/<text:path>.jpg", endpoint='get')
@blueprint.route(r"<key>/<path:path>.jpg", endpoint='get')
@flaskparser.use_kwargs(OPTIONS)
def get_with_text(key, path, alt):
text = domain.Text(path)
Expand All @@ -58,7 +58,7 @@ def get_with_text(key, path, alt):
return display(image.text, image.path)


@blueprint.route("<key>/<text:path>.jpeg")
@blueprint.route("<key>/<path:path>.jpeg")
def get_with_text_jpeg(key, path):
return redirect(route('.get', key=key, path=path))

Expand Down
2 changes: 1 addition & 1 deletion memegen/routes/links.py
Expand Up @@ -16,7 +16,7 @@ def get_without_text(key):
return redirect(route('templates.create', key=template.key))


@blueprint.route("<key>/<text:path>", endpoint='get')
@blueprint.route("<key>/<path:path>", endpoint='get')
def get_with_text(key, path):
"""Get links for generated images."""
template = app.template_service.find(key)
Expand Down
2 changes: 1 addition & 1 deletion memegen/routes/templates.py
Expand Up @@ -59,7 +59,7 @@ def create_meme(key, top, bottom):
assert None


@blueprint.route("<key>/<text:path>")
@blueprint.route("<key>/<path:path>")
def get_meme_with_path(key, path):
"""Redirect if any additional path is provided."""
template = app.template_service.find(key)
Expand Down

0 comments on commit 2b80e7d

Please sign in to comment.