From ecd65f37e35fecbce5efd38173a7573feebaef0c Mon Sep 17 00:00:00 2001 From: Micah Lee Date: Sun, 15 Sep 2019 16:23:19 -0700 Subject: [PATCH 1/3] Fix bug with rendering index.html files in subdirs --- onionshare/web/website_mode.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/onionshare/web/website_mode.py b/onionshare/web/website_mode.py index 0b7602ea..9dac8627 100644 --- a/onionshare/web/website_mode.py +++ b/onionshare/web/website_mode.py @@ -30,11 +30,13 @@ class WebsiteModeWeb(SendBaseModeWeb): """ return self.render_logic(path) - def directory_listing_template(self, path, files, dirs): + def directory_listing_template(self, path, files, dirs, breadcrumbs, breadcrumbs_leaf): return make_response(render_template('listing.html', path=path, files=files, dirs=dirs, + breadcrumbs=breadcrumbs, + breadcrumbs_leaf=breadcrumbs_leaf, static_url_path=self.web.static_url_path)) def set_file_info_custom(self, filenames, processed_size_callback): @@ -51,7 +53,7 @@ class WebsiteModeWeb(SendBaseModeWeb): index_path = os.path.join(path, 'index.html') if index_path in self.files: # Render it - return self.stream_individual_file(filesystem_path) + return self.stream_individual_file(self.files[index_path]) else: # Otherwise, render directory listing From a5e01a18e2ccf31ff31184d28c90554ea2c61f70 Mon Sep 17 00:00:00 2001 From: Micah Lee Date: Sun, 15 Sep 2019 16:44:24 -0700 Subject: [PATCH 2/3] Add breadcrumbs for website mode --- onionshare/web/send_base_mode.py | 8 +++++++- onionshare/web/share_mode.py | 2 +- share/static/css/style.css | 24 ++++++++++++++++++++++++ share/templates/listing.html | 6 ++++++ 4 files changed, 38 insertions(+), 2 deletions(-) diff --git a/onionshare/web/send_base_mode.py b/onionshare/web/send_base_mode.py index 67fb26d0..24ad55d7 100644 --- a/onionshare/web/send_base_mode.py +++ b/onionshare/web/send_base_mode.py @@ -90,9 +90,15 @@ class SendBaseModeWeb: 'status_code': 200 }) + breadcrumbs = [('☗', '/')] + parts = path.split('/')[:-1] + for i in range(len(parts)): + breadcrumbs.append(('{}'.format(parts[i]), '/{}/'.format('/'.join(parts[0:i+1])))) + breadcrumbs_leaf = breadcrumbs.pop()[0] + # If filesystem_path is None, this is the root directory listing files, dirs = self.build_directory_listing(filenames, filesystem_path) - r = self.directory_listing_template(path, files, dirs) + r = self.directory_listing_template(path, files, dirs, breadcrumbs, breadcrumbs_leaf) return self.web.add_security_headers(r) def build_directory_listing(self, filenames, filesystem_path): diff --git a/onionshare/web/share_mode.py b/onionshare/web/share_mode.py index f52bc2c7..3d1af447 100644 --- a/onionshare/web/share_mode.py +++ b/onionshare/web/share_mode.py @@ -168,7 +168,7 @@ class ShareModeWeb(SendBaseModeWeb): r.headers.set('Content-Type', content_type) return r - def directory_listing_template(self, path, files, dirs): + def directory_listing_template(self, path, files, dirs, breadcrumbs, breadcrumbs_leaf): return make_response(render_template( 'send.html', file_info=self.file_info, diff --git a/share/static/css/style.css b/share/static/css/style.css index bc986e57..af41b155 100644 --- a/share/static/css/style.css +++ b/share/static/css/style.css @@ -74,6 +74,30 @@ a.button:visited { bottom: 10px; } +ul.breadcrumbs { + display: block; + list-style: none; + margin: 10px 0; + padding: 0; +} + +ul.breadcrumbs li { + display: inline-block; + list-style: none; + margin: 0; + padding: 5px; + color: #999999; +} + +ul.breadcrumbs li span.sep { + padding-left: 5px; +} + +ul.breadcrumbs li a:link, ul.breadcrumbs li a:visited { + color: #666666; + border-bottom: 1px solid #666666; +} + table.file-list { width: 100%; margin: 0 auto; diff --git a/share/templates/listing.html b/share/templates/listing.html index e394f842..2f70dbf0 100644 --- a/share/templates/listing.html +++ b/share/templates/listing.html @@ -12,6 +12,12 @@

OnionShare

+ {% if breadcrumbs %} + + {% endif %} + From ce9a2f52d0240c9519175ece2dc6f72ba7c242ec Mon Sep 17 00:00:00 2001 From: Micah Lee Date: Sun, 15 Sep 2019 16:46:28 -0700 Subject: [PATCH 3/3] Add breadcrumbs to share mode --- onionshare/web/share_mode.py | 2 ++ share/templates/send.html | 6 ++++++ 2 files changed, 8 insertions(+) diff --git a/onionshare/web/share_mode.py b/onionshare/web/share_mode.py index 3d1af447..8a3f5969 100644 --- a/onionshare/web/share_mode.py +++ b/onionshare/web/share_mode.py @@ -174,6 +174,8 @@ class ShareModeWeb(SendBaseModeWeb): file_info=self.file_info, files=files, dirs=dirs, + breadcrumbs=breadcrumbs, + breadcrumbs_leaf=breadcrumbs_leaf, filename=os.path.basename(self.download_filename), filesize=self.filesize, filesize_human=self.common.human_readable_filesize(self.download_filesize), diff --git a/share/templates/send.html b/share/templates/send.html index 916b3bfe..941c4130 100644 --- a/share/templates/send.html +++ b/share/templates/send.html @@ -22,6 +22,12 @@

OnionShare

+ {% if breadcrumbs %} + + {% endif %} +
Filename
Filename