Only allow downloading of individual files if it is enabled in settings, and stop sharing automatically isn't

This commit is contained in:
Micah Lee 2019-09-01 20:36:30 -07:00
parent 1c465b40fe
commit 6561d71edd
No known key found for this signature in database
GPG Key ID: 403C2657CD994F73
5 changed files with 35 additions and 7 deletions

View File

@ -41,10 +41,13 @@ class SendBaseModeWeb:
self.download_in_progress = False
self.define_routes()
self.init()
def init(self):
self.common.log('SendBaseModeWeb', '__init__')
self.define_routes()
"""
Inherited class will implement this
"""
pass
def define_routes(self):
"""
@ -105,6 +108,10 @@ class SendBaseModeWeb:
if len(filenames) == 1 and os.path.isdir(filenames[0]):
filenames = [os.path.join(filenames[0], x) for x in os.listdir(filenames[0])]
# Re-initialize
self.init()
# Build the file list
self.build_file_list(filenames)
self.set_file_info_custom(filenames, processed_size_callback)

View File

@ -14,6 +14,12 @@ class ShareModeWeb(SendBaseModeWeb):
"""
All of the web logic for share mode
"""
def init(self):
self.common.log('ShareModeWeb', 'init')
# If "Stop sharing after files have been sent" is unchecked and "Allow downloading of individual files" is checked
self.download_individual_files = not self.common.settings.get('close_after_first_download') \
and self.common.settings.get('share_allow_downloading_individual_files')
def define_routes(self):
"""
The web app routes for sharing files
@ -26,7 +32,7 @@ class ShareModeWeb(SendBaseModeWeb):
"""
self.web.add_request(self.web.REQUEST_LOAD, request.path)
# Deny new downloads if "Stop After First Download" is checked and there is
# Deny new downloads if "Stop sharing after files have been sent" is checked and there is
# currently a download
deny_download = not self.web.stay_open and self.download_in_progress
if deny_download:
@ -175,7 +181,8 @@ class ShareModeWeb(SendBaseModeWeb):
filesize=self.filesize,
filesize_human=self.common.human_readable_filesize(self.download_filesize),
is_zipped=self.is_zipped,
static_url_path=self.web.static_url_path))
static_url_path=self.web.static_url_path,
download_individual_files=self.download_individual_files))
def set_file_info_custom(self, filenames, processed_size_callback):
self.common.log("ShareModeWeb", "set_file_info_custom")
@ -200,9 +207,12 @@ class ShareModeWeb(SendBaseModeWeb):
# If it's a file
elif os.path.isfile(filesystem_path):
dirname = os.path.dirname(filesystem_path)
basename = os.path.basename(filesystem_path)
return send_from_directory(dirname, basename)
if self.download_individual_files:
dirname = os.path.dirname(filesystem_path)
basename = os.path.basename(filesystem_path)
return send_from_directory(dirname, basename)
else:
return self.web.error404()
# If it's not a directory or file, throw a 404
else:

View File

@ -12,6 +12,9 @@ class WebsiteModeWeb(SendBaseModeWeb):
"""
All of the web logic for website mode
"""
def init(self):
pass
def define_routes(self):
"""
The web app routes for sharing a website

View File

@ -56,6 +56,10 @@ header .right ul li {
cursor: pointer;
}
a.button:visited {
color: #ffffff;
}
.close-button {
color: #ffffff;
background-color: #c90c0c;

View File

@ -44,9 +44,13 @@
<tr>
<td>
<img width="30" height="30" title="" alt="" src="{{ static_url_path }}/img/web_file.png" />
{% if download_individual_files %}
<a href="{{ info.basename }}">
{{ info.basename }}
</a>
{% else %}
{{ info.basename }}
{% endif %}
</td>
<td>{{ info.size_human }}</td>
</tr>