mirror of
https://github.com/onionshare/onionshare.git
synced 2024-10-01 01:35:40 -04:00
Hold a share open if its timer hsa expired but a file is still uploading. Don't allow other uploads during this time
This commit is contained in:
parent
4777c45ad8
commit
b06fd8af26
@ -118,6 +118,7 @@ class Web(object):
|
||||
self.download_in_progress = False
|
||||
|
||||
self.done = False
|
||||
self.can_upload = True
|
||||
|
||||
# If the client closes the OnionShare window while a download is in progress,
|
||||
# it should immediately stop serving the file. The client_cancel global is
|
||||
@ -343,6 +344,7 @@ class Web(object):
|
||||
"""
|
||||
Upload files.
|
||||
"""
|
||||
while self.can_upload:
|
||||
# Make sure downloads_dir exists
|
||||
valid = True
|
||||
try:
|
||||
@ -420,6 +422,10 @@ class Web(object):
|
||||
for filename in filenames:
|
||||
flash('Sent {}'.format(filename), 'info')
|
||||
|
||||
|
||||
# Register that uploads were sent (for shutdown timer)
|
||||
self.done = True
|
||||
|
||||
if self.common.settings.get('public_mode'):
|
||||
return redirect('/')
|
||||
else:
|
||||
@ -428,11 +434,14 @@ class Web(object):
|
||||
@self.app.route("/<slug_candidate>/upload", methods=['POST'])
|
||||
def upload(slug_candidate):
|
||||
self.check_slug_candidate(slug_candidate)
|
||||
if self.can_upload:
|
||||
return upload_logic(slug_candidate)
|
||||
else:
|
||||
return self.error404()
|
||||
|
||||
@self.app.route("/upload", methods=['POST'])
|
||||
def upload_public():
|
||||
if not self.common.settings.get('public_mode'):
|
||||
if not self.common.settings.get('public_mode') or not self.can_upload:
|
||||
return self.error404()
|
||||
return upload_logic()
|
||||
|
||||
@ -449,11 +458,14 @@ class Web(object):
|
||||
@self.app.route("/<slug_candidate>/close", methods=['POST'])
|
||||
def close(slug_candidate):
|
||||
self.check_slug_candidate(slug_candidate)
|
||||
if self.can_upload:
|
||||
return close_logic(slug_candidate)
|
||||
else:
|
||||
return self.error404()
|
||||
|
||||
@self.app.route("/close", methods=['POST'])
|
||||
def close_public():
|
||||
if not self.common.settings.get('public_mode'):
|
||||
if not self.common.settings.get('public_mode') or not self.can_upload:
|
||||
return self.error404()
|
||||
return close_logic()
|
||||
|
||||
@ -745,7 +757,7 @@ class ReceiveModeRequest(Request):
|
||||
|
||||
# Is this a valid upload request?
|
||||
self.upload_request = False
|
||||
if self.method == 'POST':
|
||||
if self.method == 'POST' and self.web.can_upload:
|
||||
if self.path == '/{}/upload'.format(self.web.slug):
|
||||
self.upload_request = True
|
||||
else:
|
||||
|
@ -98,6 +98,17 @@ class ReceiveMode(Mode):
|
||||
The shutdown timer expired, should we stop the server? Returns a bool
|
||||
"""
|
||||
# TODO: wait until the final upload is done before stoppign the server?
|
||||
# If there were no attempts to upload files, or all uploads are done, we can stop
|
||||
if self.web.upload_count == 0 or self.web.done:
|
||||
self.server_status.stop_server()
|
||||
self.server_status_label.setText(strings._('close_on_timeout', True))
|
||||
return True
|
||||
# An upload is probably still running - hold off on stopping the share, but block new shares.
|
||||
else:
|
||||
self.server_status_label.setText(strings._('timeout_upload_still_running', True))
|
||||
self.web.can_upload = False
|
||||
return False
|
||||
|
||||
return True
|
||||
|
||||
def start_server_custom(self):
|
||||
|
@ -15,6 +15,7 @@
|
||||
"close_on_timeout": "Stopped because timer expired",
|
||||
"closing_automatically": "Stopped because download finished",
|
||||
"timeout_download_still_running": "Waiting for download to complete",
|
||||
"timeout_upload_still_running": "Waiting for upload to complete",
|
||||
"large_filesize": "Warning: Sending large files could take hours",
|
||||
"systray_menu_exit": "Quit",
|
||||
"systray_download_started_title": "OnionShare Download Started",
|
||||
|
Loading…
Reference in New Issue
Block a user