aboutsummaryrefslogtreecommitdiffstats
path: root/fatcat/routes.py
blob: f6d6c4e3395f6ec163934eb100f81c2faff352b6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126

import os
import json
from flask import Flask, render_template, send_from_directory, request, \
    url_for, abort, g, redirect, jsonify, session
from fatcat import app, db, api


### Views ###################################################################

@app.route('/work/create', methods=['GET'])
def work_create():
    return render_template('work_add.html')

@app.route('/work/random', methods=['GET'])
def work_random():
    rv = api.api_work_random()
    ident = rv.location.split('/')[-1]
    return redirect("/work/{}".format(ident))

@app.route('/work/<int:ident>', methods=['GET'])
def work_view(ident):
    rv = api.api_work_get(ident)
    if rv.status_code != 200:
        # TODO: better wrapping for all entities
        return abort(rv.status_code)
    entity = json.loads(rv.data.decode('utf-8'))
    return render_template('work_view.html', work=entity)

@app.route('/release/<int:ident>', methods=['GET'])
def release_view(ident):
    rv = api.api_release_get(ident)
    if rv.status_code != 200:
        # TODO: better wrapping for all entities
        return abort(rv.status_code)
    entity = json.loads(rv.data.decode('utf-8'))
    return render_template('release_view.html', release=entity)

@app.route('/release/random', methods=['GET'])
def release_random():
    rv = api.api_release_random()
    ident = rv.location.split('/')[-1]
    return redirect("/release/{}".format(ident))

@app.route('/creator/<int:ident>', methods=['GET'])
def creator_view(ident):
    rv = api.api_creator_get(ident)
    if rv.status_code != 200:
        # TODO: better wrapping for all entities
        return abort(rv.status_code)
    entity = json.loads(rv.data.decode('utf-8'))
    return render_template('creator_view.html', creator=entity)

@app.route('/container/<int:ident>', methods=['GET'])
def container_view(ident):
    rv = api.api_container_get(ident)
    if rv.status_code != 200:
        # TODO: better wrapping for all entities
        return abort(rv.status_code)
    entity = json.loads(rv.data.decode('utf-8'))
    return render_template('container_view.html', container=entity)

@app.route('/file/<int:ident>', methods=['GET'])
def file_view(ident):
    rv = api.api_file_get(ident)
    if rv.status_code != 200:
        # TODO: better wrapping for all entities
        return abort(rv.status_code)
    entity = json.loads(rv.data.decode('utf-8'))
    return render_template('file_view.html', file=entity)

@app.route('/editgroup/<int:ident>', methods=['GET'])
def editgroup_view(ident):
    rv = api.api_edit_group_get(ident)
    if rv.status_code != 200:
        # TODO: better wrapping for all entities
        return abort(rv.status_code)
    entity = json.loads(rv.data.decode('utf-8'))
    return render_template('editgroup_view.html', editgroup=entity)

@app.route('/editgroup/current', methods=['GET'])
def editgroup_current():
    eg = api.get_or_create_edit_group()
    return redirect('/editgroup/{}'.format(eg.id))

@app.route('/editor/<username>', methods=['GET'])
def editor_view(username):
    rv = api.api_editor_get(username)
    if rv.status_code != 200:
        # TODO: better wrapping for all entities
        return abort(rv.status_code)
    entity = json.loads(rv.data.decode('utf-8'))
    return render_template('editor_view.html', editor=entity)

@app.route('/editor/<username>/changelog', methods=['GET'])
def editor_changelog(username):
    rv = api.api_editor_get(username)
    if rv.status_code != 200:
        # TODO: better wrapping for all entities
        return abort(rv.status_code)
    editor = json.loads(rv.data.decode('utf-8'))
    rv = api.api_editor_changelog(username)
    changelog_entries = json.loads(rv.data.decode('utf-8'))
    return render_template('editor_changelog.html', editor=editor,
        changelog_entries=changelog_entries)


### Static Routes ###########################################################

@app.route('/', methods=['GET'])
def homepage():
    return render_template('home.html')

@app.route('/about', methods=['GET'])
def aboutpage():
    return render_template('about.html')

@app.route('/robots.txt', methods=['GET'])
def robots():
    return send_from_directory(os.path.join(app.root_path, 'static'),
                               'robots.txt',
                               mimetype='text/plain')

@app.route('/health', methods=['GET'])
def health():
    return jsonify({'ok': True})