Fix logic for handling an upload still in progress when timer runs out. Show thankyou page for last uploader post-timer expiry

This commit is contained in:
Miguel Jacq 2018-10-01 18:42:53 +10:00
parent f653e8cc04
commit 3f32db2cca
No known key found for this signature in database
GPG Key ID: EEA4341C6D97A0B6
3 changed files with 53 additions and 29 deletions

View File

@ -19,6 +19,7 @@ class ReceiveModeWeb(object):
self.web = web
self.can_upload = True
self.can_stop_share_now = False
self.upload_count = 0
self.uploads_in_progress = []
@ -39,6 +40,7 @@ class ReceiveModeWeb(object):
r = make_response(render_template(
'receive.html',
upload_action=upload_action))
return self.web.add_security_headers(r)
@self.web.app.route("/<slug_candidate>")
@ -138,10 +140,24 @@ class ReceiveModeWeb(object):
for filename in filenames:
flash('Sent {}'.format(filename), 'info')
if self.can_upload:
if self.common.settings.get('public_mode'):
return redirect('/')
path = '/'
else:
return redirect('/{}'.format(slug_candidate))
path = '/{}'.format(slug_candidate)
return redirect('{}'.format(path))
else:
# It was the last upload and the timer ran out
if self.common.settings.get('public_mode'):
return thankyou_logic(slug_candidate)
else:
return thankyou_logic()
def thankyou_logic(slug_candidate=''):
r = make_response(render_template(
'thankyou.html'))
return self.web.add_security_headers(r)
@self.web.app.route("/<slug_candidate>/upload", methods=['POST'])
def upload(slug_candidate):
@ -231,14 +247,13 @@ class ReceiveModeRequest(Request):
if self.path == '/upload':
self.upload_request = True
if self.upload_request:
if self.upload_request and self.web.receive_mode.can_upload:
# A dictionary that maps filenames to the bytes uploaded so far
self.progress = {}
# Create an upload_id, attach it to the request
self.upload_id = self.web.receive_mode.upload_count
if self.web.receive_mode.can_upload:
self.web.receive_mode.upload_count += 1
# Figure out the content length
@ -262,8 +277,6 @@ class ReceiveModeRequest(Request):
})
self.previous_file = None
else:
self.upload_rejected = True
def _get_file_stream(self, total_content_length, content_type, filename=None, content_length=None):
"""
@ -284,14 +297,19 @@ class ReceiveModeRequest(Request):
"""
super(ReceiveModeRequest, self).close()
if self.upload_request:
if not self.upload_rejected:
try:
upload_id = self.upload_id
# Inform the GUI that the upload has finished
self.web.add_request(self.web.REQUEST_UPLOAD_FINISHED, self.path, {
'id': self.upload_id
'id': upload_id
})
# remove from self.uploads_in_progress
self.web.receive_mode.uploads_in_progress.remove(self.upload_id)
self.web.receive_mode.uploads_in_progress.remove(upload_id)
except AttributeError:
# We may not have got an upload_id (e.g uploads were rejected)
pass
def file_write_func(self, filename, length):
"""

View File

@ -51,6 +51,7 @@ class ReceiveMode(Mode):
self.uploads_in_progress = 0
self.uploads_completed = 0
self.new_upload = False # For scrolling to the bottom of the uploads list
self.can_stop_server = False # for communicating to the auto-stop timer
# Information about share, and show uploads button
self.info_in_progress_uploads_count = QtWidgets.QLabel()
@ -93,7 +94,7 @@ class ReceiveMode(Mode):
The shutdown timer expired, should we stop the server? Returns a bool
"""
# If there were no attempts to upload files, or all uploads are done, we can stop
if self.web.receive_mode.upload_count == 0 or not self.web.receive_mode.uploads_in_progress:
if self.web.receive_mode.upload_count == 0 or self.can_stop_server:
self.server_status.stop_server()
self.server_status_label.setText(strings._('close_on_timeout', True))
return True
@ -110,7 +111,9 @@ class ReceiveMode(Mode):
Starting the server.
"""
# Reset web counters
self.can_stop_server = False
self.web.receive_mode.upload_count = 0
self.web.receive_mode.can_upload = True
self.web.error404_count = 0
# Hide and reset the uploads if we have previously shared
@ -144,6 +147,7 @@ class ReceiveMode(Mode):
self.uploads.add(event["data"]["id"], event["data"]["content_length"])
self.uploads_in_progress += 1
self.update_uploads_in_progress()
self.can_stop_server = False
self.system_tray.showMessage(strings._('systray_upload_started_title', True), strings._('systray_upload_started_message', True))
@ -177,6 +181,8 @@ class ReceiveMode(Mode):
# Update the 'in progress uploads' info
self.uploads_in_progress -= 1
self.update_uploads_in_progress()
if self.uploads_in_progress == 0:
self.can_stop_server = True
def on_reload_settings(self):
"""