Commit a1b0d672 authored by Lukas Böhm's avatar Lukas Böhm 🎱
Browse files

download file

parent cbf53ca8
......@@ -70,6 +70,30 @@ def download_auth(share_id):
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():
if request.method == 'POST':
......
......@@ -30,12 +30,14 @@
{% for file in up.files %}
<li class="list-group-item">
{{ file.filename }}
<button class="btn btn-outline-primary streched-link float-right" type="button" onclick="downloadFile({{ share_id }}, {{ file.id }})">
<svg width="1em" height="1em" viewBox="0 0 16 16" class="bi bi-download" fill="currentColor" xmlns="http://www.w3.org/2000/svg">
<path fill-rule="evenodd" d="M.5 9.9a.5.5 0 0 1 .5.5v2.5a1 1 0 0 0 1 1h12a1 1 0 0 0 1-1v-2.5a.5.5 0 0 1 1 0v2.5a2 2 0 0 1-2 2H2a2 2 0 0 1-2-2v-2.5a.5.5 0 0 1 .5-.5z"></path>
<path fill-rule="evenodd" d="M7.646 11.854a.5.5 0 0 0 .708 0l3-3a.5.5 0 0 0-.708-.708L8.5 10.293V1.5a.5.5 0 0 0-1 0v8.793L5.354 8.146a.5.5 0 1 0-.708.708l3 3z"></path>
</svg>
</button>
<a href="{{ url_for('media', share_id=up.id, file_id=file.id) }}" download>
<button class="btn btn-outline-primary streched-link float-right" type="button">
<svg width="1em" height="1em" viewBox="0 0 16 16" class="bi bi-download" fill="currentColor" xmlns="http://www.w3.org/2000/svg">
<path fill-rule="evenodd" d="M.5 9.9a.5.5 0 0 1 .5.5v2.5a1 1 0 0 0 1 1h12a1 1 0 0 0 1-1v-2.5a.5.5 0 0 1 1 0v2.5a2 2 0 0 1-2 2H2a2 2 0 0 1-2-2v-2.5a.5.5 0 0 1 .5-.5z"></path>
<path fill-rule="evenodd" d="M7.646 11.854a.5.5 0 0 0 .708 0l3-3a.5.5 0 0 0-.708-.708L8.5 10.293V1.5a.5.5 0 0 0-1 0v8.793L5.354 8.146a.5.5 0 1 0-.708.708l3 3z"></path>
</svg>
</button>
</a>
</li>
{% endfor %}
</ul>
......@@ -50,10 +52,4 @@
</div>
</div>
<script>
function downloadFile(share_id, file_id){
}
</script>
{% endblock content %}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment