mirror of
https://github.com/onionshare/onionshare.git
synced 2024-12-25 23:39:43 -05:00
When there is only 1 file being shared, don't zip it
This commit is contained in:
parent
dbae501689
commit
324538bdd3
@ -120,13 +120,13 @@ def main(cwd=None):
|
||||
print(strings._("preparing_files"))
|
||||
try:
|
||||
web.set_file_info(filenames)
|
||||
app.cleanup_filenames.append(web.zip_filename)
|
||||
app.cleanup_filenames.append(web.download_filename)
|
||||
except OSError as e:
|
||||
print(e.strerror)
|
||||
sys.exit(1)
|
||||
|
||||
# Warn about sending large files over Tor
|
||||
if web.zip_filesize >= 157286400: # 150mb
|
||||
if web.download_filesize >= 157286400: # 150mb
|
||||
print('')
|
||||
print(strings._("large_filesize"))
|
||||
print('')
|
||||
|
@ -102,8 +102,9 @@ class Web(object):
|
||||
|
||||
# Information about the file
|
||||
self.file_info = []
|
||||
self.zip_filename = None
|
||||
self.zip_filesize = None
|
||||
self.is_zipped = False
|
||||
self.download_filename = None
|
||||
self.download_filesize = None
|
||||
self.zip_writer = None
|
||||
|
||||
self.security_headers = [
|
||||
@ -182,17 +183,19 @@ class Web(object):
|
||||
'send.html',
|
||||
slug=self.slug,
|
||||
file_info=self.file_info,
|
||||
filename=os.path.basename(self.zip_filename),
|
||||
filesize=self.zip_filesize,
|
||||
filesize_human=self.common.human_readable_filesize(self.zip_filesize)))
|
||||
filename=os.path.basename(self.download_filename),
|
||||
filesize=self.download_filesize,
|
||||
filesize_human=self.common.human_readable_filesize(self.download_filesize),
|
||||
is_zipped=self.is_zipped))
|
||||
else:
|
||||
# If download is allowed to continue, serve download page
|
||||
r = make_response(render_template(
|
||||
'send.html',
|
||||
file_info=self.file_info,
|
||||
filename=os.path.basename(self.zip_filename),
|
||||
filesize=self.zip_filesize,
|
||||
filesize_human=self.common.human_readable_filesize(self.zip_filesize)))
|
||||
filename=os.path.basename(self.download_filename),
|
||||
filesize=self.download_filesize,
|
||||
filesize_human=self.common.human_readable_filesize(self.download_filesize),
|
||||
is_zipped=self.is_zipped))
|
||||
return self.add_security_headers(r)
|
||||
|
||||
@self.app.route("/<slug_candidate>/download")
|
||||
@ -231,8 +234,8 @@ class Web(object):
|
||||
'id': download_id}
|
||||
)
|
||||
|
||||
dirname = os.path.dirname(self.zip_filename)
|
||||
basename = os.path.basename(self.zip_filename)
|
||||
dirname = os.path.dirname(self.download_filename)
|
||||
basename = os.path.basename(self.download_filename)
|
||||
|
||||
def generate():
|
||||
# The user hasn't canceled the download
|
||||
@ -244,7 +247,7 @@ class Web(object):
|
||||
|
||||
chunk_size = 102400 # 100kb
|
||||
|
||||
fp = open(self.zip_filename, 'rb')
|
||||
fp = open(self.download_filename, 'rb')
|
||||
self.done = False
|
||||
canceled = False
|
||||
while not self.done:
|
||||
@ -264,7 +267,7 @@ class Web(object):
|
||||
|
||||
# tell GUI the progress
|
||||
downloaded_bytes = fp.tell()
|
||||
percent = (1.0 * downloaded_bytes / self.zip_filesize) * 100
|
||||
percent = (1.0 * downloaded_bytes / self.download_filesize) * 100
|
||||
|
||||
# only output to stdout if running onionshare in CLI mode, or if using Linux (#203, #304)
|
||||
if not self.gui_mode or self.common.platform == 'Linux' or self.common.platform == 'BSD':
|
||||
@ -308,7 +311,7 @@ class Web(object):
|
||||
pass
|
||||
|
||||
r = Response(generate())
|
||||
r.headers.set('Content-Length', self.zip_filesize)
|
||||
r.headers.set('Content-Length', self.download_filesize)
|
||||
r.headers.set('Content-Disposition', 'attachment', filename=basename)
|
||||
r = self.add_security_headers(r)
|
||||
# guess content type
|
||||
@ -517,8 +520,9 @@ class Web(object):
|
||||
page will need to display. This includes zipping up the file in order to
|
||||
get the zip file's name and size.
|
||||
"""
|
||||
self.common.log("Web", "set_file_info")
|
||||
self.cancel_compression = False
|
||||
|
||||
|
||||
# build file info list
|
||||
self.file_info = {'files': [], 'dirs': []}
|
||||
for filename in filenames:
|
||||
@ -537,22 +541,30 @@ class Web(object):
|
||||
self.file_info['files'] = sorted(self.file_info['files'], key=lambda k: k['basename'])
|
||||
self.file_info['dirs'] = sorted(self.file_info['dirs'], key=lambda k: k['basename'])
|
||||
|
||||
# Zip up the files and folders
|
||||
self.zip_writer = ZipWriter(self.common, processed_size_callback=processed_size_callback)
|
||||
self.zip_filename = self.zip_writer.zip_filename
|
||||
for info in self.file_info['files']:
|
||||
self.zip_writer.add_file(info['filename'])
|
||||
# Canceling early?
|
||||
if self.cancel_compression:
|
||||
self.zip_writer.close()
|
||||
return False
|
||||
# Check if there's only 1 file and no folders
|
||||
if len(self.file_info['files']) == 1 and len(self.file_info['dirs']) == 0:
|
||||
self.is_zipped = False
|
||||
self.download_filename = self.file_info['files'][0]['filename']
|
||||
self.download_filesize = self.file_info['files'][0]['size']
|
||||
else:
|
||||
# Zip up the files and folders
|
||||
self.zip_writer = ZipWriter(self.common, processed_size_callback=processed_size_callback)
|
||||
self.download_filename = self.zip_writer.zip_filename
|
||||
for info in self.file_info['files']:
|
||||
self.zip_writer.add_file(info['filename'])
|
||||
# Canceling early?
|
||||
if self.cancel_compression:
|
||||
self.zip_writer.close()
|
||||
return False
|
||||
|
||||
for info in self.file_info['dirs']:
|
||||
if not self.zip_writer.add_dir(info['filename']):
|
||||
return False
|
||||
for info in self.file_info['dirs']:
|
||||
if not self.zip_writer.add_dir(info['filename']):
|
||||
return False
|
||||
|
||||
self.zip_writer.close()
|
||||
self.download_filesize = os.path.getsize(self.download_filename)
|
||||
self.is_zipped = True
|
||||
|
||||
self.zip_writer.close()
|
||||
self.zip_filesize = os.path.getsize(self.zip_filename)
|
||||
return True
|
||||
|
||||
def _safe_select_jinja_autoescape(self, filename):
|
||||
|
@ -47,7 +47,7 @@ class CompressThread(QtCore.QThread):
|
||||
# Cancelled
|
||||
pass
|
||||
|
||||
self.mode.app.cleanup_filenames.append(self.mode.web.zip_filename)
|
||||
self.mode.app.cleanup_filenames.append(self.mode.web.download_filename)
|
||||
except OSError as e:
|
||||
self.error.emit(e.strerror)
|
||||
|
||||
|
Binary file not shown.
Before Width: | Height: | Size: 45 KiB |
@ -10,18 +10,18 @@
|
||||
<body>
|
||||
|
||||
<header class="clearfix">
|
||||
<div class="right">
|
||||
<ul>
|
||||
<li>Total size: <strong>{{ filesize_human }}</strong> (compressed)</li>
|
||||
{% if slug %}
|
||||
<li><a class="button" href='/{{ slug }}/download'>Download Files</a></li>
|
||||
{% else %}
|
||||
<li><a class="button" href='/download'>Download Files</a></li>
|
||||
{% endif %}
|
||||
</ul>
|
||||
</div>
|
||||
<img class="logo" src="/static/img/logo.png" title="OnionShare">
|
||||
<h1>OnionShare</h1>
|
||||
<div class="right">
|
||||
<ul>
|
||||
<li>Total size: <strong>{{ filesize_human }}</strong> {% if is_zipped %} (compressed){% endif %}</li>
|
||||
{% if slug %}
|
||||
<li><a class="button" href='/{{ slug }}/download'>Download Files</a></li>
|
||||
{% else %}
|
||||
<li><a class="button" href='/download'>Download Files</a></li>
|
||||
{% endif %}
|
||||
</ul>
|
||||
</div>
|
||||
<img class="logo" src="/static/img/logo.png" title="OnionShare">
|
||||
<h1>OnionShare</h1>
|
||||
</header>
|
||||
|
||||
<table class="file-list" id="file-list">
|
||||
|
Loading…
Reference in New Issue
Block a user