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

download file directly from client

parent babc552a
......@@ -70,30 +70,6 @@ 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():
return render_template('Upload.html')
......
......@@ -30,21 +30,30 @@
{% for file in up.files %}
<li class="list-group-item">
{{ file.filename }}
<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 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>
<script>
$("button:parent").click(function (e) {
console.log("download file");
e.preventDefault();
window.location.href = `http://localhost:6969/share/{{ up.id }}/attachment/{{ file.id }}`;
})
</script>
</button>
</a>
</li>
{% endfor %}
</ul>
{% if up.is_zipped %}
<div class="input-group">
<a href="{{ url_for('zip_attachments', share_id=up.id) }}" download class="btn btn-block btn-outline-primary">
<a href="{{ url_for('zip_attachments', share_id=up.id) }}" download
class="btn btn-block btn-outline-primary">
Dateien gepackt herunterladen
</a>
</div>
......
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