Newer
Older
from flask import render_template, redirect, url_for, current_app, abort, request, flash
from util import AuthForm, get_password, set_password
@app.route('/privacy')
def privacy():
return render_template('Privacy.html')
@app.route('/about')
def about():
return render_template('About.html')
@app.route('/')
def index():
@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)
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}'))
return redirect(url_for('download_auth', share_id=share_id))
@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('/d/<string:share_id>/f/<string:file_id>')
def media(share_id, file_id):
password = get_password(share_id)
if password:
res = api.get(urljoin(current_app.config['API_URL'], f'/share/{share_id}/attachment/{file_id}'), auth=(share_id, password), stream=True)
else:
res = api.get(urljoin(current_app.config['API_URL'], f'/share/{share_id}/attachment/{file_id}'), stream=True)
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:
from flask import stream_with_context
from flask import Response
return Response(
stream_with_context(res.raw),
headers={
'Content-Disposition': res.headers['Content-Disposition']
},
mimetype=res.headers['Content-Type']
)
@app.route('/upload', methods=['GET', 'POST'])
def upload():