|
1
|
1 |
|
from collections import OrderedDict |
|
2
|
|
|
|
|
3
|
1 |
|
from flask import Blueprint, current_app as app, redirect |
|
|
|
|
|
|
4
|
|
|
|
|
5
|
1 |
|
from ..domain import Text |
|
6
|
|
|
|
|
7
|
1 |
|
from ._utils import route |
|
8
|
|
|
|
|
9
|
|
|
|
|
10
|
1 |
|
blueprint = Blueprint('links', __name__, url_prefix="/api/templates/") |
|
11
|
|
|
|
|
12
|
|
|
|
|
13
|
1 |
|
@blueprint.route("<key>/<path:path>", endpoint='get') |
|
14
|
|
|
def get_with_text(key, path): |
|
15
|
|
|
"""Get links for generated images.""" |
|
16
|
1 |
|
template = app.template_service.find(key) |
|
17
|
1 |
|
if template.key != key: |
|
18
|
1 |
|
return redirect(route('.get', key=template.key, path=path)) |
|
19
|
|
|
|
|
20
|
1 |
|
text = Text(path) |
|
21
|
1 |
|
if text.path != path: |
|
22
|
1 |
|
return redirect(route('.get', key=key, path=text.path)) |
|
23
|
|
|
|
|
24
|
1 |
|
data = OrderedDict() |
|
25
|
|
|
|
|
26
|
1 |
|
data['direct'] = OrderedDict() |
|
27
|
1 |
|
visible_url = route('image.get', key=key, path=path, _external=True) |
|
28
|
1 |
|
data['direct']['visible'] = visible_url |
|
29
|
1 |
|
code = app.link_service.encode(key, path) |
|
30
|
1 |
|
masked_url = route('image.get_encoded', code=code, _external=True) |
|
31
|
1 |
|
data['direct']['masked'] = masked_url |
|
32
|
1 |
|
data['markdown'] = OrderedDict() |
|
33
|
1 |
|
data['markdown']['visible'] = "".format(k=key, u=visible_url) |
|
34
|
1 |
|
data['markdown']['masked'] = "".format(k=key, u=masked_url) |
|
35
|
|
|
|
|
36
|
|
|
return data |
|
37
|
|
|
|