Commit 33597b40 authored by Lukas Bhm's avatar Lukas Bhm
Browse files

fixed upload

parent 3f9bbb53
...@@ -16,4 +16,4 @@ ENV FLASK_APP chiefsend.py ...@@ -16,4 +16,4 @@ ENV FLASK_APP chiefsend.py
EXPOSE 5000 EXPOSE 5000
EXPOSE 6379 EXPOSE 6379
ENTRYPOINT gunicorn -b :5000 --access-logfile - --error-logfile - chiefsend:app ENTRYPOINT gunicorn -b :5000 --workers=3 --worker-class=tornado --timeout=90 --graceful-timeout=30 --log-level=DEBUG --access-logfile - --error-logfile - chiefsend:app
...@@ -18,7 +18,8 @@ app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False ...@@ -18,7 +18,8 @@ app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
app.config['MAX_MEDIA_SIZE'] = 1000 * 1024 * 1024 # 1000 MB app.config['MAX_MEDIA_SIZE'] = 1000 * 1024 * 1024 # 1000 MB
db = SQLAlchemy(app) db = SQLAlchemy(app)
task_queue = Queue(connection=Redis.from_url('redis://chiefsend-redis')) #task_queue = Queue(connection=Redis.from_url('redis://chiefsend-redis'))
task_queue = Queue(connection=Redis())
from app.models import * from app.models import *
......
...@@ -83,7 +83,6 @@ def upload(): ...@@ -83,7 +83,6 @@ def upload():
que.enqueue_at(share.expires, delete_share, share.id) que.enqueue_at(share.expires, delete_share, share.id)
# wrap it up # wrap it up
db.session.commit() db.session.commit()
# TODO catch HTTP errors or else there will be HTML stuff in the URL
return url_for('shared', share_id=share.id) return url_for('shared', share_id=share.id)
return render_template('Upload.html', form=form) return render_template('Upload.html', form=form)
......
...@@ -6,18 +6,19 @@ ...@@ -6,18 +6,19 @@
<p class="lead">Hier können Sie Dateien bis zu 1000MB hochladen und sofort per Link teilen.</p> <p class="lead">Hier können Sie Dateien bis zu 1000MB hochladen und sofort per Link teilen.</p>
</div> </div>
<div class="card mb-4 shadow-sm text-center"> <div class="card mb-4 text-center shadow">
<form method="post" enctype="multipart/form-data"> <form method="post" enctype="multipart/form-data">
{{ form.hidden_tag() }} {{ form.hidden_tag() }}
<div class="card-header"> <div class="card-header">
<h4 class="my-0 font-weight-normal">{{ form.name(class='form-control', placeholder='Name vergeben (optional)') }}</h4> <h4 class="my-0 font-weight-normal">{{ form.name(class='form-control', placeholder='Name vergeben (optional)', size=32) }}</h4>
</div> </div>
<div class="card-body"> <div class="card-body">
<div class="custom-file mb-3"> <div class="custom-file mb-3">
{{ form.files(class='custom-file-input') }} {{ form.files(class='custom-file-input') }}
{{ form.files.label(class='custom-file-label') }} {{ form.files.label(class='custom-file-label truncate') }}
</div> </div>
<div class="row form-group"> <div class="row form-group">
...@@ -39,28 +40,38 @@ ...@@ -39,28 +40,38 @@
</form> </form>
</div> </div>
<style>
.truncate {
width: 100%;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}
</style>
<script> <script>
// to let the name of the file appear on select // to let the name of the file appear on select
$(".custom-file-input").on("change", function() { $(".custom-file-input").on("change", function() {
let fns = $(this)[0].files; let fns = $(this)[0].files;
let label = ""; let label = "";
for (var i = 0; i < fns.length; i++){ for (var i = 0; i < fns.length; i++) {
label = label.concat(fns[i].name); label = label.concat(fns[i].name);
if (i < fns.length-1) label = label.concat(", "); if (i < fns.length - 1) label = label.concat(", ");
} }
$(this).siblings(".custom-file-label").addClass("selected").html(label); $(this).siblings(".custom-file-label").addClass("selected").html(label);
}); });
</script> </script>
<script src="{{ url_for('static', filename='js/jquery.form.min.js') }}"></script> <script src="{{ url_for('static', filename='js/jquery.form.min.js') }}"></script>
<script> <script>
// PROGRESS BAR AND SUBMIT
let abb = false; let abb = false;
$('form').ajaxForm({ $('form').ajaxForm({
beforeSend: function (xhr) { beforeSend: function (xhr) {
console.log('starting send')
$('.progress').removeClass('d-none'); $('.progress').removeClass('d-none');
document.getElementById('download_limit').disabled = true; document.getElementById('download_limit').disabled = true;
document.getElementById('timer').disabled = true; document.getElementById('timer').disabled = true;
document.getElementById('submit').disabled = true; document.getElementById('submit').disabled = true;
document.getElementById('name').disabled = true;
document.getElementById('files').disabled = true;
$('#abort').removeClass('d-none').click(function (){ $('#abort').removeClass('d-none').click(function (){
console.log('ABORTED UPLOAD') console.log('ABORTED UPLOAD')
...@@ -70,18 +81,27 @@ ...@@ -70,18 +81,27 @@
}, },
uploadProgress: function(event, position, total, percentComplete) { uploadProgress: function(event, position, total, percentComplete) {
let percentVal = percentComplete + '%'; let percentVal = percentComplete + '%';
console.log(percentVal);
$('.progress-bar').html(percentVal).width(percentVal); $('.progress-bar').html(percentVal).width(percentVal);
}, },
complete: function(xhr) { complete: function(xhr) {
if (!abb){ if (!abb){
window.location.href = xhr.responseText; if(xhr.responseText === "undefined") {
window.location.href = "{{ url_for('expired') }}"
} else if(xhr.responseText.includes("<html")) {
$("html").html(xhr.responseText);
} else {
window.location.href = xhr.responseText;
}
} else { } else {
document.getElementById('download_limit').disabled = false; document.getElementById('download_limit').disabled = false;
document.getElementById('timer').disabled = false; document.getElementById('timer').disabled = false;
document.getElementById('submit').disabled = false; document.getElementById('submit').disabled = false;
document.getElementById('name').disabled = false;
document.getElementById('files').disabled = false;
} }
}, }
});
</script>
}); });
</script> </script>
{% endblock content %} {% endblock content %}
\ No newline at end of file
Flask click==7.1.2
Flask-SQLAlchemy Flask==1.1.2
Flask-WTF Flask-SQLAlchemy==2.4.4
rq Flask-WTF==0.14.3
\ No newline at end of file itsdangerous==1.1.0
Jinja2==2.11.2
MarkupSafe==1.1.1
redis==3.5.3
rq==1.5.2
six==1.15.0
SQLAlchemy==1.3.20
Werkzeug==1.0.1
WTForms==2.3.3
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