mirror of
https://github.com/onionshare/onionshare.git
synced 2024-10-01 01:35:40 -04:00
Add trailing slash on directories in website mode to assist with relative asset links
This commit is contained in:
parent
7c11266107
commit
cf6a6e4590
@ -131,7 +131,7 @@ 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):
|
def directory_listing(self, filenames, path="", filesystem_path=None, add_trailing_slash=False):
|
||||||
# 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
|
||||||
@ -150,12 +150,12 @@ class SendBaseModeWeb:
|
|||||||
breadcrumbs_leaf = breadcrumbs.pop()[0]
|
breadcrumbs_leaf = breadcrumbs.pop()[0]
|
||||||
|
|
||||||
# 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)
|
files, dirs = self.build_directory_listing(path, filenames, filesystem_path, add_trailing_slash)
|
||||||
return self.directory_listing_template(
|
return self.directory_listing_template(
|
||||||
path, files, dirs, breadcrumbs, breadcrumbs_leaf
|
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 = []
|
files = []
|
||||||
dirs = []
|
dirs = []
|
||||||
|
|
||||||
@ -168,6 +168,11 @@ class SendBaseModeWeb:
|
|||||||
is_dir = os.path.isdir(this_filesystem_path)
|
is_dir = os.path.isdir(this_filesystem_path)
|
||||||
|
|
||||||
if is_dir:
|
if is_dir:
|
||||||
|
if add_trailing_slash:
|
||||||
|
dirs.append(
|
||||||
|
{"link": os.path.join(f"/{path}", filename, ""), "basename": filename}
|
||||||
|
)
|
||||||
|
else:
|
||||||
dirs.append(
|
dirs.append(
|
||||||
{"link": os.path.join(f"/{path}", filename), "basename": filename}
|
{"link": os.path.join(f"/{path}", filename), "basename": filename}
|
||||||
)
|
)
|
||||||
|
@ -84,12 +84,13 @@ class WebsiteModeWeb(SendBaseModeWeb):
|
|||||||
return self.stream_individual_file(self.files[index_path])
|
return self.stream_individual_file(self.files[index_path])
|
||||||
|
|
||||||
else:
|
else:
|
||||||
# Otherwise, render directory listing
|
# Otherwise, render directory listing, and enforce trailing slash
|
||||||
|
# which can help with relative asset links in sub-directories.
|
||||||
filenames = []
|
filenames = []
|
||||||
for filename in os.listdir(filesystem_path):
|
for filename in os.listdir(filesystem_path):
|
||||||
filenames.append(filename)
|
filenames.append(filename)
|
||||||
filenames.sort()
|
filenames.sort()
|
||||||
return self.directory_listing(filenames, path, filesystem_path)
|
return self.directory_listing(filenames, path, filesystem_path, True)
|
||||||
|
|
||||||
# If it's a file
|
# If it's a file
|
||||||
elif os.path.isfile(filesystem_path):
|
elif os.path.isfile(filesystem_path):
|
||||||
@ -112,7 +113,7 @@ class WebsiteModeWeb(SendBaseModeWeb):
|
|||||||
# Root directory listing
|
# Root directory listing
|
||||||
filenames = list(self.root_files)
|
filenames = list(self.root_files)
|
||||||
filenames.sort()
|
filenames.sort()
|
||||||
return self.directory_listing(filenames, path)
|
return self.directory_listing(filenames, path, None, True)
|
||||||
|
|
||||||
else:
|
else:
|
||||||
# If the path isn't found, throw a 404
|
# If the path isn't found, throw a 404
|
||||||
|
Loading…
Reference in New Issue
Block a user