Adds attribute self.mode_supports_file_requests in Web class. Don't send REQUEST_INDIVIDUAL_FILE_STARTED to the frontend if the mode doesn't support this, so that we don't trigger a chain reaction of toggling history widgets and the like. Set this attribute to True by default since most modes use it, but turn it off for Chat mode. Prevents an exception when sending a bad HTTP method or a 404 to a chat room

This commit is contained in:
Miguel Jacq 2021-05-11 08:41:17 +10:00
parent a55a59e021
commit 0b6db6559d
No known key found for this signature in database
GPG Key ID: EEA4341C6D97A0B6

View File

@ -152,6 +152,7 @@ class Web:
self.receive_mode = None self.receive_mode = None
self.website_mode = None self.website_mode = None
self.chat_mode = None self.chat_mode = None
self.mode_supports_file_requests = True
if self.mode == "share": if self.mode == "share":
self.share_mode = ShareModeWeb(self.common, self) self.share_mode = ShareModeWeb(self.common, self)
elif self.mode == "receive": elif self.mode == "receive":
@ -162,6 +163,9 @@ class Web:
self.socketio = SocketIO() self.socketio = SocketIO()
self.socketio.init_app(self.app) self.socketio.init_app(self.app)
self.chat_mode = ChatModeWeb(self.common, self) self.chat_mode = ChatModeWeb(self.common, self)
# Chat mode has no concept of individual file requests that
# turn into history widgets in the GUI
self.mode_supports_file_requests = False
self.cleanup_filenames = [] self.cleanup_filenames = []
@ -294,6 +298,7 @@ class Web:
return self.add_security_headers(r) return self.add_security_headers(r)
def error404(self, history_id): def error404(self, history_id):
if self.mode_supports_file_requests:
self.add_request( self.add_request(
self.REQUEST_INDIVIDUAL_FILE_STARTED, self.REQUEST_INDIVIDUAL_FILE_STARTED,
request.path, request.path,
@ -307,6 +312,7 @@ class Web:
return self.add_security_headers(r) return self.add_security_headers(r)
def error405(self, history_id): def error405(self, history_id):
if self.mode_supports_file_requests:
self.add_request( self.add_request(
self.REQUEST_INDIVIDUAL_FILE_STARTED, self.REQUEST_INDIVIDUAL_FILE_STARTED,
request.path, request.path,
@ -320,6 +326,7 @@ class Web:
return self.add_security_headers(r) return self.add_security_headers(r)
def error500(self, history_id): def error500(self, history_id):
if self.mode_supports_file_requests:
self.add_request( self.add_request(
self.REQUEST_INDIVIDUAL_FILE_STARTED, self.REQUEST_INDIVIDUAL_FILE_STARTED,
request.path, request.path,