memegen.routes.api_links.get_with_text()   A
last analyzed

Complexity

Conditions 3

Size

Total Lines 24
Code Lines 19

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 18
CRAP Score 3

Importance

Changes 0
Metric Value
cc 3
eloc 19
nop 2
dl 0
loc 24
rs 9.45
c 0
b 0
f 0
ccs 18
cts 18
cp 1
crap 3
1 1
from collections import OrderedDict
2
3 1
from flask import Blueprint, current_app as app, redirect
0 ignored issues
show
introduced by
Unable to import 'flask'
Loading history...
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'] = "![{k}]({u})".format(k=key, u=visible_url)
34 1
    data['markdown']['masked'] = "![{k}]({u})".format(k=key, u=masked_url)
35
36
    return data
37