Properly set the web 'done' state to True on loading the directory listing

This commit is contained in:
Miguel Jacq 2025-02-13 12:17:42 +11:00
parent 795f63f7d6
commit 32672077d0
No known key found for this signature in database
GPG Key ID: 59B3F0C24135C6A9
2 changed files with 14 additions and 6 deletions

View File

@ -515,7 +515,7 @@ def main(cwd=None):
if not app.autostop_timer_thread.is_alive():
if mode == "share":
# If there were no attempts to download the share, or all downloads are done, we can stop
if web.share_mode.cur_history_id == 0 or web.done:
if not web.share_mode.download_in_progress or web.share_mode.cur_history_id == 0 or web.done:
print("Stopped because auto-stop timer ran out")
web.stop(app.port)
break

View File

@ -132,6 +132,9 @@ class SendBaseModeWeb:
self.set_file_info_custom(filenames, processed_size_callback)
def directory_listing(self, filenames, path="", filesystem_path=None, add_trailing_slash=False):
"""
Display the front page of a share or index.html-less website, listing the files/directories.
"""
# Tell the GUI about the directory listing
history_id = self.cur_history_id
self.cur_history_id += 1
@ -151,6 +154,11 @@ class SendBaseModeWeb:
# If filesystem_path is None, this is the root directory listing
files, dirs = self.build_directory_listing(path, filenames, filesystem_path, add_trailing_slash)
# Mark the request as done so we know we can close the share if in auto-stop mode.
self.web.done = True
# Render and return the response.
return self.directory_listing_template(
path, files, dirs, breadcrumbs, breadcrumbs_leaf
)
@ -228,11 +236,11 @@ class SendBaseModeWeb:
chunk_size = 102400 # 100kb
fp = open(file_to_download, "rb")
done = False
while not done:
self.web.done = False
while not self.web.done:
chunk = fp.read(chunk_size)
if chunk == b"":
done = True
self.web.done = True
else:
try:
yield chunk
@ -273,10 +281,10 @@ class SendBaseModeWeb:
"filesize": filesize,
},
)
done = False
self.web.done = False
except Exception:
# Looks like the download was canceled
done = True
self.web.done = True
# Tell the GUI the individual file was canceled
self.web.add_request(