mirror of
https://github.com/onionshare/onionshare.git
synced 2024-12-29 01:06:16 -05:00
Make receive mode events just like share mode, and rename REQUEST_DOWNLOAD to REQUEST_SHARE
This commit is contained in:
parent
996f6c0725
commit
591e97a57a
@ -45,7 +45,7 @@ class Web(object):
|
|||||||
The Web object is the OnionShare web server, powered by flask
|
The Web object is the OnionShare web server, powered by flask
|
||||||
"""
|
"""
|
||||||
REQUEST_LOAD = 0
|
REQUEST_LOAD = 0
|
||||||
REQUEST_DOWNLOAD = 1
|
REQUEST_STARTED = 1
|
||||||
REQUEST_PROGRESS = 2
|
REQUEST_PROGRESS = 2
|
||||||
REQUEST_OTHER = 3
|
REQUEST_OTHER = 3
|
||||||
REQUEST_CANCELED = 4
|
REQUEST_CANCELED = 4
|
||||||
@ -103,6 +103,7 @@ class Web(object):
|
|||||||
self.slug = None
|
self.slug = None
|
||||||
|
|
||||||
self.download_count = 0
|
self.download_count = 0
|
||||||
|
self.upload_count = 0
|
||||||
self.error404_count = 0
|
self.error404_count = 0
|
||||||
|
|
||||||
# If "Stop After First Download" is checked (stay_open == False), only allow
|
# If "Stop After First Download" is checked (stay_open == False), only allow
|
||||||
@ -173,17 +174,17 @@ class Web(object):
|
|||||||
r = make_response(render_template('denied.html'))
|
r = make_response(render_template('denied.html'))
|
||||||
return self.add_security_headers(r)
|
return self.add_security_headers(r)
|
||||||
|
|
||||||
# each download has a unique id
|
# Each download has a unique id
|
||||||
download_id = self.download_count
|
download_id = self.download_count
|
||||||
self.download_count += 1
|
self.download_count += 1
|
||||||
|
|
||||||
# prepare some variables to use inside generate() function below
|
# Prepare some variables to use inside generate() function below
|
||||||
# which is outside of the request context
|
# which is outside of the request context
|
||||||
shutdown_func = request.environ.get('werkzeug.server.shutdown')
|
shutdown_func = request.environ.get('werkzeug.server.shutdown')
|
||||||
path = request.path
|
path = request.path
|
||||||
|
|
||||||
# tell GUI the download started
|
# Tell GUI the download started
|
||||||
self.add_request(self.REQUEST_DOWNLOAD, path, {'id': download_id})
|
self.add_request(self.REQUEST_STARTED, path, {'id': download_id})
|
||||||
|
|
||||||
dirname = os.path.dirname(self.zip_filename)
|
dirname = os.path.dirname(self.zip_filename)
|
||||||
basename = os.path.basename(self.zip_filename)
|
basename = os.path.basename(self.zip_filename)
|
||||||
@ -266,9 +267,8 @@ class Web(object):
|
|||||||
|
|
||||||
def receive_routes(self):
|
def receive_routes(self):
|
||||||
"""
|
"""
|
||||||
The web app routes for sharing files
|
The web app routes for receiving files
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def index_logic():
|
def index_logic():
|
||||||
self.add_request(self.REQUEST_LOAD, request.path)
|
self.add_request(self.REQUEST_LOAD, request.path)
|
||||||
|
|
||||||
@ -291,6 +291,9 @@ class Web(object):
|
|||||||
|
|
||||||
|
|
||||||
def upload_logic(slug_candidate=''):
|
def upload_logic(slug_candidate=''):
|
||||||
|
"""
|
||||||
|
Upload files.
|
||||||
|
"""
|
||||||
files = request.files.getlist('file[]')
|
files = request.files.getlist('file[]')
|
||||||
filenames = []
|
filenames = []
|
||||||
for f in files:
|
for f in files:
|
||||||
@ -653,9 +656,24 @@ class ReceiveModeRequest(Request):
|
|||||||
This gets called for each file that gets uploaded, and returns an file-like
|
This gets called for each file that gets uploaded, and returns an file-like
|
||||||
writable stream.
|
writable stream.
|
||||||
"""
|
"""
|
||||||
|
# Each upload has a unique id. Now that the upload is starting, attach its
|
||||||
|
# upload_id to the request
|
||||||
|
self.upload_id = self.web.upload_count
|
||||||
|
self.web.upload_count += 1
|
||||||
|
|
||||||
|
# Tell GUI the upload started
|
||||||
|
self.web.add_request(self.web.REQUEST_STARTED, self.path, {
|
||||||
|
'id': self.upload_id
|
||||||
|
})
|
||||||
|
|
||||||
|
self.onionshare_progress[filename] = {
|
||||||
|
'total_bytes': total_content_length,
|
||||||
|
'uploaded_bytes': 0
|
||||||
|
}
|
||||||
|
|
||||||
if len(self.onionshare_progress) > 0:
|
if len(self.onionshare_progress) > 0:
|
||||||
print('')
|
print('')
|
||||||
self.onionshare_progress[filename] = 0
|
|
||||||
return ReceiveModeTemporaryFile(filename, self.onionshare_update_func)
|
return ReceiveModeTemporaryFile(filename, self.onionshare_update_func)
|
||||||
|
|
||||||
def close(self):
|
def close(self):
|
||||||
@ -670,5 +688,13 @@ class ReceiveModeRequest(Request):
|
|||||||
"""
|
"""
|
||||||
Keep track of the bytes uploaded so far for all files.
|
Keep track of the bytes uploaded so far for all files.
|
||||||
"""
|
"""
|
||||||
self.onionshare_progress[filename] += length
|
self.onionshare_progress[filename]['uploaded_bytes'] += length
|
||||||
print('{} - {} '.format(self.web.common.human_readable_filesize(self.onionshare_progress[filename]), filename), end='\r')
|
uploaded = self.web.common.human_readable_filesize(self.onionshare_progress[filename]['uploaded_bytes'])
|
||||||
|
total = self.web.common.human_readable_filesize(self.onionshare_progress[filename]['total_bytes'])
|
||||||
|
print('{}/{} - {} '.format(uploaded, total, filename), end='\r')
|
||||||
|
|
||||||
|
# Update the GUI on the download progress
|
||||||
|
self.web.add_request(self.web.REQUEST_PROGRESS, self.path, {
|
||||||
|
'id': self.upload_id,
|
||||||
|
'bytes': self.onionshare_progress[filename]['uploaded_bytes']
|
||||||
|
})
|
||||||
|
@ -295,7 +295,7 @@ class Mode(QtWidgets.QWidget):
|
|||||||
|
|
||||||
def handle_request_download(self, event):
|
def handle_request_download(self, event):
|
||||||
"""
|
"""
|
||||||
Handle REQUEST_DOWNLOAD event.
|
Handle REQUEST_STARTED event.
|
||||||
"""
|
"""
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
@ -372,7 +372,7 @@ class OnionShareGui(QtWidgets.QMainWindow):
|
|||||||
if event["type"] == Web.REQUEST_LOAD:
|
if event["type"] == Web.REQUEST_LOAD:
|
||||||
mode.handle_request_load(event)
|
mode.handle_request_load(event)
|
||||||
|
|
||||||
elif event["type"] == Web.REQUEST_DOWNLOAD:
|
elif event["type"] == Web.REQUEST_STARTED:
|
||||||
mode.handle_request_download(event)
|
mode.handle_request_download(event)
|
||||||
|
|
||||||
elif event["type"] == Web.REQUEST_RATE_LIMIT:
|
elif event["type"] == Web.REQUEST_RATE_LIMIT:
|
||||||
|
@ -105,6 +105,7 @@ class ReceiveMode(Mode):
|
|||||||
Starting the server.
|
Starting the server.
|
||||||
"""
|
"""
|
||||||
# Reset web counters
|
# Reset web counters
|
||||||
|
self.web.upload_count = 0
|
||||||
self.web.error404_count = 0
|
self.web.error404_count = 0
|
||||||
|
|
||||||
# Hide and reset the uploads if we have previously shared
|
# Hide and reset the uploads if we have previously shared
|
||||||
@ -118,6 +119,12 @@ class ReceiveMode(Mode):
|
|||||||
self.starting_server_step3.emit()
|
self.starting_server_step3.emit()
|
||||||
self.start_server_finished.emit()
|
self.start_server_finished.emit()
|
||||||
|
|
||||||
|
def handle_tor_broke_custom(self):
|
||||||
|
"""
|
||||||
|
Connection to Tor broke.
|
||||||
|
"""
|
||||||
|
self.info_widget.hide()
|
||||||
|
|
||||||
def handle_request_load(self, event):
|
def handle_request_load(self, event):
|
||||||
"""
|
"""
|
||||||
Handle REQUEST_LOAD event.
|
Handle REQUEST_LOAD event.
|
||||||
|
@ -237,7 +237,7 @@ class ShareMode(Mode):
|
|||||||
|
|
||||||
def handle_request_download(self, event):
|
def handle_request_download(self, event):
|
||||||
"""
|
"""
|
||||||
Handle REQUEST_DOWNLOAD event.
|
Handle REQUEST_STARTED event.
|
||||||
"""
|
"""
|
||||||
self.downloads.add(event["data"]["id"], self.web.zip_filesize)
|
self.downloads.add(event["data"]["id"], self.web.zip_filesize)
|
||||||
self.downloads_in_progress += 1
|
self.downloads_in_progress += 1
|
||||||
|
Loading…
Reference in New Issue
Block a user