This repository was archived by the owner on Apr 21, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathroutes.py
More file actions
85 lines (63 loc) · 2.43 KB
/
routes.py
File metadata and controls
85 lines (63 loc) · 2.43 KB
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
from urllib.parse import urljoin
from flask import render_template, redirect, url_for, current_app, abort, request, flash
from werkzeug.exceptions import HTTPException
import requests as api
from chiefsend import app
from util import AuthForm, get_password, set_password, SearchForm
@app.route('/privacy')
def privacy():
return render_template('Privacy.html')
@app.route('/about')
def about():
return render_template('About.html')
@app.route('/', methods=['GET', 'POST'])
def landing():
form = SearchForm()
if form.validate_on_submit():
share_id = form.query.data.split(sep="/")[-1]
return redirect(url_for('download', share_id=share_id))
return render_template('Landing.html', form=form)
@app.errorhandler(HTTPException)
def http_error(e):
return render_template('Error.html', e=e)
@app.route('/public')
def public():
res = api.get(urljoin(current_app.config['API_URL'], '/shares'))
if res.status_code != 200:
abort(res.status_code)
else:
shares = res.json()
return render_template('Public.html', shares=shares)
@app.route('/d/<string:share_id>/')
def download(share_id):
password = get_password(share_id)
if password:
res = api.get(urljoin(current_app.config['API_URL'], f'/share/{share_id}'), auth=(share_id, password))
else:
res = api.get(urljoin(current_app.config['API_URL'], f'/share/{share_id}'))
if res.status_code == 401:
return redirect(url_for('download_auth', share_id=share_id))
elif res.status_code != 200:
abort(res.status_code)
else:
share = res.json()
print(share)
return render_template('Download.html', up=share)
@app.route('/d/<string:share_id>/auth', methods=['GET', 'POST'])
def download_auth(share_id):
form = AuthForm()
if form.validate_on_submit():
set_password(share_id, form.password.data)
return redirect(url_for('download', share_id=share_id))
else:
for field, error in form.errors.items():
from markupsafe import Markup
flash(Markup(f'<b>{field}:</b> {error}'), category='danger')
flash('Zugriff verweigert.', category='danger')
return render_template('DownloadAuth.html', form=form)
@app.route('/upload', methods=['GET', 'POST'])
def upload():
return render_template('Upload.html')
@app.route('/shared/<string:share_id>')
def shared(share_id):
return render_template('Shared.html', share_id=share_id)