mirror of
https://github.com/onionshare/onionshare.git
synced 2025-06-25 15:00:27 -04:00
Properly set the web 'done' state to True on loading the directory listing
This commit is contained in:
parent
795f63f7d6
commit
32672077d0
2 changed files with 14 additions and 6 deletions
|
@ -515,7 +515,7 @@ def main(cwd=None):
|
||||||
if not app.autostop_timer_thread.is_alive():
|
if not app.autostop_timer_thread.is_alive():
|
||||||
if mode == "share":
|
if mode == "share":
|
||||||
# If there were no attempts to download the share, or all downloads are done, we can stop
|
# 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")
|
print("Stopped because auto-stop timer ran out")
|
||||||
web.stop(app.port)
|
web.stop(app.port)
|
||||||
break
|
break
|
||||||
|
|
|
@ -132,6 +132,9 @@ class SendBaseModeWeb:
|
||||||
self.set_file_info_custom(filenames, processed_size_callback)
|
self.set_file_info_custom(filenames, processed_size_callback)
|
||||||
|
|
||||||
def directory_listing(self, filenames, path="", filesystem_path=None, add_trailing_slash=False):
|
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
|
# Tell the GUI about the directory listing
|
||||||
history_id = self.cur_history_id
|
history_id = self.cur_history_id
|
||||||
self.cur_history_id += 1
|
self.cur_history_id += 1
|
||||||
|
@ -151,6 +154,11 @@ class SendBaseModeWeb:
|
||||||
|
|
||||||
# If filesystem_path is None, this is the root directory listing
|
# If filesystem_path is None, this is the root directory listing
|
||||||
files, dirs = self.build_directory_listing(path, filenames, filesystem_path, add_trailing_slash)
|
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(
|
return self.directory_listing_template(
|
||||||
path, files, dirs, breadcrumbs, breadcrumbs_leaf
|
path, files, dirs, breadcrumbs, breadcrumbs_leaf
|
||||||
)
|
)
|
||||||
|
@ -228,11 +236,11 @@ class SendBaseModeWeb:
|
||||||
chunk_size = 102400 # 100kb
|
chunk_size = 102400 # 100kb
|
||||||
|
|
||||||
fp = open(file_to_download, "rb")
|
fp = open(file_to_download, "rb")
|
||||||
done = False
|
self.web.done = False
|
||||||
while not done:
|
while not self.web.done:
|
||||||
chunk = fp.read(chunk_size)
|
chunk = fp.read(chunk_size)
|
||||||
if chunk == b"":
|
if chunk == b"":
|
||||||
done = True
|
self.web.done = True
|
||||||
else:
|
else:
|
||||||
try:
|
try:
|
||||||
yield chunk
|
yield chunk
|
||||||
|
@ -273,10 +281,10 @@ class SendBaseModeWeb:
|
||||||
"filesize": filesize,
|
"filesize": filesize,
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
done = False
|
self.web.done = False
|
||||||
except Exception:
|
except Exception:
|
||||||
# Looks like the download was canceled
|
# Looks like the download was canceled
|
||||||
done = True
|
self.web.done = True
|
||||||
|
|
||||||
# Tell the GUI the individual file was canceled
|
# Tell the GUI the individual file was canceled
|
||||||
self.web.add_request(
|
self.web.add_request(
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue