memegen.routes.api_links   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 25
dl 0
loc 37
rs 10
c 0
b 0
f 0
ccs 23
cts 23
cp 1
wmc 3

1 Function

Rating   Name   Duplication   Size   Complexity  
A get_with_text() 0 24 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