diff options
Diffstat (limited to 'onionshare/web/receive_mode.py')
-rw-r--r-- | onionshare/web/receive_mode.py | 41 |
1 files changed, 23 insertions, 18 deletions
diff --git a/onionshare/web/receive_mode.py b/onionshare/web/receive_mode.py index 3f848d2f..83040683 100644 --- a/onionshare/web/receive_mode.py +++ b/onionshare/web/receive_mode.py @@ -8,7 +8,7 @@ from werkzeug.utils import secure_filename from .. import strings -class ReceiveModeWeb(object): +class ReceiveModeWeb: """ All of the web logic for receive mode """ @@ -18,13 +18,12 @@ class ReceiveModeWeb(object): self.web = web - # Reset assets path - self.web.app.static_folder=self.common.get_resource_path('static') - self.can_upload = True - self.upload_count = 0 self.uploads_in_progress = [] + # This tracks the history id + self.cur_history_id = 0 + self.define_routes() def define_routes(self): @@ -33,8 +32,15 @@ class ReceiveModeWeb(object): """ @self.web.app.route("/") def index(): + history_id = self.cur_history_id + self.cur_history_id += 1 + self.web.add_request(self.web.REQUEST_INDIVIDUAL_FILE_STARTED, '{}'.format(request.path), { + 'id': history_id, + 'status_code': 200 + }) + self.web.add_request(self.web.REQUEST_LOAD, request.path) - r = make_response(render_template('receive.html', + r = make_response(render_template('receive.html', static_url_path=self.web.static_url_path)) return self.web.add_security_headers(r) @@ -55,7 +61,7 @@ class ReceiveModeWeb(object): # Tell the GUI the receive mode directory for this file self.web.add_request(self.web.REQUEST_UPLOAD_SET_DIR, request.path, { - 'id': request.upload_id, + 'id': request.history_id, 'filename': basename, 'dir': request.receive_mode_dir }) @@ -275,10 +281,9 @@ class ReceiveModeRequest(Request): # Prevent new uploads if we've said so (timer expired) if self.web.receive_mode.can_upload: - # Create an upload_id, attach it to the request - self.upload_id = self.web.receive_mode.upload_count - - self.web.receive_mode.upload_count += 1 + # Create an history_id, attach it to the request + self.history_id = self.web.receive_mode.cur_history_id + self.web.receive_mode.cur_history_id += 1 # Figure out the content length try: @@ -305,10 +310,10 @@ class ReceiveModeRequest(Request): if not self.told_gui_about_request: # Tell the GUI about the request self.web.add_request(self.web.REQUEST_STARTED, self.path, { - 'id': self.upload_id, + 'id': self.history_id, 'content_length': self.content_length }) - self.web.receive_mode.uploads_in_progress.append(self.upload_id) + self.web.receive_mode.uploads_in_progress.append(self.history_id) self.told_gui_about_request = True @@ -340,19 +345,19 @@ class ReceiveModeRequest(Request): try: if self.told_gui_about_request: - upload_id = self.upload_id + history_id = self.history_id if not self.web.stop_q.empty() or not self.progress[self.filename]['complete']: # Inform the GUI that the upload has canceled self.web.add_request(self.web.REQUEST_UPLOAD_CANCELED, self.path, { - 'id': upload_id + 'id': history_id }) else: # Inform the GUI that the upload has finished self.web.add_request(self.web.REQUEST_UPLOAD_FINISHED, self.path, { - 'id': upload_id + 'id': history_id }) - self.web.receive_mode.uploads_in_progress.remove(upload_id) + self.web.receive_mode.uploads_in_progress.remove(history_id) except AttributeError: pass @@ -378,7 +383,7 @@ class ReceiveModeRequest(Request): # Update the GUI on the upload progress if self.told_gui_about_request: self.web.add_request(self.web.REQUEST_PROGRESS, self.path, { - 'id': self.upload_id, + 'id': self.history_id, 'progress': self.progress }) |