aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSaptak Sengupta <saptak013@gmail.com>2023-10-17 21:51:36 +0530
committerGitHub <noreply@github.com>2023-10-17 21:51:36 +0530
commit00eeca793191b67f22e8e83186d5ed01f632b196 (patch)
treeda4a6d0d781758de0f85c4a6b1ae58b917553a35
parent907ef913942ae3b55c3b1dd64f9eec305c39b0e5 (diff)
parentcf6a6e45902fc775673c68442add9d24decdd061 (diff)
downloadonionshare-00eeca793191b67f22e8e83186d5ed01f632b196.tar.gz
onionshare-00eeca793191b67f22e8e83186d5ed01f632b196.zip
Merge pull request #1783 from onionshare/trailing_slash_on_dirs_website_mode
Add trailing slash on directories in website mode to assist with relative asset links
-rw-r--r--cli/onionshare_cli/web/send_base_mode.py17
-rw-r--r--cli/onionshare_cli/web/website_mode.py7
2 files changed, 15 insertions, 9 deletions
diff --git a/cli/onionshare_cli/web/send_base_mode.py b/cli/onionshare_cli/web/send_base_mode.py
index d8cef496..ca79b99f 100644
--- a/cli/onionshare_cli/web/send_base_mode.py
+++ b/cli/onionshare_cli/web/send_base_mode.py
@@ -131,7 +131,7 @@ class SendBaseModeWeb:
self.set_file_info_custom(filenames, processed_size_callback)
- def directory_listing(self, filenames, path="", filesystem_path=None):
+ def directory_listing(self, filenames, path="", filesystem_path=None, add_trailing_slash=False):
# Tell the GUI about the directory listing
history_id = self.cur_history_id
self.cur_history_id += 1
@@ -150,12 +150,12 @@ class SendBaseModeWeb:
breadcrumbs_leaf = breadcrumbs.pop()[0]
# If filesystem_path is None, this is the root directory listing
- files, dirs = self.build_directory_listing(path, filenames, filesystem_path)
+ files, dirs = self.build_directory_listing(path, filenames, filesystem_path, add_trailing_slash)
return self.directory_listing_template(
path, files, dirs, breadcrumbs, breadcrumbs_leaf
)
- def build_directory_listing(self, path, filenames, filesystem_path):
+ def build_directory_listing(self, path, filenames, filesystem_path, add_trailing_slash=False):
files = []
dirs = []
@@ -168,9 +168,14 @@ class SendBaseModeWeb:
is_dir = os.path.isdir(this_filesystem_path)
if is_dir:
- dirs.append(
- {"link": os.path.join(f"/{path}", filename), "basename": filename}
- )
+ if add_trailing_slash:
+ dirs.append(
+ {"link": os.path.join(f"/{path}", filename, ""), "basename": filename}
+ )
+ else:
+ dirs.append(
+ {"link": os.path.join(f"/{path}", filename), "basename": filename}
+ )
else:
size = os.path.getsize(this_filesystem_path)
size_human = self.common.human_readable_filesize(size)
diff --git a/cli/onionshare_cli/web/website_mode.py b/cli/onionshare_cli/web/website_mode.py
index 1f61532b..34f5abf1 100644
--- a/cli/onionshare_cli/web/website_mode.py
+++ b/cli/onionshare_cli/web/website_mode.py
@@ -84,12 +84,13 @@ class WebsiteModeWeb(SendBaseModeWeb):
return self.stream_individual_file(self.files[index_path])
else:
- # Otherwise, render directory listing
+ # Otherwise, render directory listing, and enforce trailing slash
+ # which can help with relative asset links in sub-directories.
filenames = []
for filename in os.listdir(filesystem_path):
filenames.append(filename)
filenames.sort()
- return self.directory_listing(filenames, path, filesystem_path)
+ return self.directory_listing(filenames, path, filesystem_path, True)
# If it's a file
elif os.path.isfile(filesystem_path):
@@ -112,7 +113,7 @@ class WebsiteModeWeb(SendBaseModeWeb):
# Root directory listing
filenames = list(self.root_files)
filenames.sort()
- return self.directory_listing(filenames, path)
+ return self.directory_listing(filenames, path, None, True)
else:
# If the path isn't found, throw a 404