diff options
author | Micah Lee <micah@micahflee.com> | 2019-09-03 21:46:32 -0700 |
---|---|---|
committer | Micah Lee <micah@micahflee.com> | 2019-09-03 21:46:32 -0700 |
commit | 644b47082a716de9a7e2311b9f3c2a75c4d96fbe (patch) | |
tree | f3af6cf0eee7d8f1c7c071c67231851d9db10aea /onionshare | |
parent | c55925c1ce296ec8fe31bbe1b50c23133eda687a (diff) | |
download | onionshare-644b47082a716de9a7e2311b9f3c2a75c4d96fbe.tar.gz onionshare-644b47082a716de9a7e2311b9f3c2a75c4d96fbe.zip |
Start making IndividualFileHistoryItem widgets appear in the history, and make non-GET requests return 405 Method Not Allowed
Diffstat (limited to 'onionshare')
-rw-r--r-- | onionshare/web/send_base_mode.py | 41 | ||||
-rw-r--r-- | onionshare/web/web.py | 32 |
2 files changed, 44 insertions, 29 deletions
diff --git a/onionshare/web/send_base_mode.py b/onionshare/web/send_base_mode.py index a34aedfd..402bc32f 100644 --- a/onionshare/web/send_base_mode.py +++ b/onionshare/web/send_base_mode.py @@ -132,18 +132,28 @@ class SendBaseModeWeb: file_to_download = filesystem_path filesize = os.path.getsize(filesystem_path) - # TODO: Tell GUI the download started - #self.web.add_request(self.web.REQUEST_STARTED, path, { - # 'id': download_id, - # 'use_gzip': use_gzip - #}) + # Each download has a unique id + download_id = self.download_count + self.download_count += 1 + + path = request.path + + # Tell GUI the individual file started + self.web.add_request(self.web.REQUEST_INDIVIDUAL_FILE_STARTED, path, { + 'id': download_id, + 'filesize': filesize, + 'method': request.method + }) + + # Only GET requests are allowed, any other method should fail + if request.method != "GET": + return self.web.error405() def generate(): chunk_size = 102400 # 100kb fp = open(file_to_download, 'rb') done = False - canceled = False while not done: chunk = fp.read(chunk_size) if chunk == b'': @@ -152,7 +162,7 @@ class SendBaseModeWeb: try: yield chunk - # TODO: Tell GUI the progress + # Tell GUI the progress downloaded_bytes = fp.tell() percent = (1.0 * downloaded_bytes / filesize) * 100 if not self.web.is_gui or self.common.platform == 'Linux' or self.common.platform == 'BSD': @@ -160,20 +170,19 @@ class SendBaseModeWeb: "\r{0:s}, {1:.2f}% ".format(self.common.human_readable_filesize(downloaded_bytes), percent)) sys.stdout.flush() - #self.web.add_request(self.web.REQUEST_PROGRESS, path, { - # 'id': download_id, - # 'bytes': downloaded_bytes - # }) + self.web.add_request(self.web.REQUEST_INDIVIDUAL_FILE_PROGRESS, path, { + 'id': download_id, + 'bytes': downloaded_bytes + }) done = False except: # Looks like the download was canceled done = True - canceled = True - # TODO: Tell the GUI the download has canceled - #self.web.add_request(self.web.REQUEST_CANCELED, path, { - # 'id': download_id - #}) + # Tell the GUI the individual file was canceled + self.web.add_request(self.web.REQUEST_INDIVIDUAL_FILE_CANCELED, path, { + 'id': download_id + }) fp.close() diff --git a/onionshare/web/web.py b/onionshare/web/web.py index 8d5a6af5..5a96b324 100644 --- a/onionshare/web/web.py +++ b/onionshare/web/web.py @@ -37,15 +37,18 @@ class Web: REQUEST_LOAD = 0 REQUEST_STARTED = 1 REQUEST_PROGRESS = 2 - REQUEST_OTHER = 3 - REQUEST_CANCELED = 4 - REQUEST_RATE_LIMIT = 5 - REQUEST_UPLOAD_FILE_RENAMED = 6 - REQUEST_UPLOAD_SET_DIR = 7 - REQUEST_UPLOAD_FINISHED = 8 - REQUEST_UPLOAD_CANCELED = 9 - REQUEST_ERROR_DATA_DIR_CANNOT_CREATE = 10 - REQUEST_INVALID_PASSWORD = 11 + REQUEST_CANCELED = 3 + REQUEST_RATE_LIMIT = 4 + REQUEST_UPLOAD_FILE_RENAMED = 5 + REQUEST_UPLOAD_SET_DIR = 6 + REQUEST_UPLOAD_FINISHED = 7 + REQUEST_UPLOAD_CANCELED = 8 + REQUEST_INDIVIDUAL_FILE_STARTED = 9 + REQUEST_INDIVIDUAL_FILE_PROGRESS = 10 + REQUEST_INDIVIDUAL_FILE_CANCELED = 11 + REQUEST_ERROR_DATA_DIR_CANNOT_CREATE = 12 + REQUEST_OTHER = 13 + REQUEST_INVALID_PASSWORD = 14 def __init__(self, common, is_gui, mode='share'): self.common = common @@ -193,15 +196,18 @@ class Web: r = make_response(render_template('401.html', static_url_path=self.static_url_path), 401) return self.add_security_headers(r) - def error404(self): + def error403(self): self.add_request(Web.REQUEST_OTHER, request.path) - r = make_response(render_template('404.html', static_url_path=self.static_url_path), 404) + r = make_response(render_template('403.html', static_url_path=self.static_url_path), 403) return self.add_security_headers(r) - def error403(self): + def error404(self): self.add_request(Web.REQUEST_OTHER, request.path) + r = make_response(render_template('404.html', static_url_path=self.static_url_path), 404) + return self.add_security_headers(r) - r = make_response(render_template('403.html', static_url_path=self.static_url_path), 403) + def error405(self): + r = make_response(render_template('405.html', static_url_path=self.static_url_path), 405) return self.add_security_headers(r) def add_security_headers(self, r): |