mirror of
https://github.com/onionshare/onionshare.git
synced 2024-12-28 08:49:30 -05:00
Refactor set_file_list between website and share mode
This commit is contained in:
parent
0f40e9589c
commit
5c0839a557
@ -26,6 +26,8 @@ class BaseModeWeb(object):
|
|||||||
|
|
||||||
# Dictionary mapping file paths to filenames on disk
|
# Dictionary mapping file paths to filenames on disk
|
||||||
self.files = {}
|
self.files = {}
|
||||||
|
self.cleanup_filenames = []
|
||||||
|
self.file_info = {'files': [], 'dirs': []}
|
||||||
|
|
||||||
self.visit_count = 0
|
self.visit_count = 0
|
||||||
self.download_count = 0
|
self.download_count = 0
|
||||||
@ -34,8 +36,7 @@ class BaseModeWeb(object):
|
|||||||
# one download at a time.
|
# one download at a time.
|
||||||
self.download_in_progress = False
|
self.download_in_progress = False
|
||||||
|
|
||||||
# Reset assets path
|
self.define_routes()
|
||||||
self.web.app.static_folder=self.common.get_resource_path('static')
|
|
||||||
|
|
||||||
|
|
||||||
def init(self):
|
def init(self):
|
||||||
@ -43,3 +44,27 @@ class BaseModeWeb(object):
|
|||||||
Add custom initialization here.
|
Add custom initialization here.
|
||||||
"""
|
"""
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
def set_file_info(self, filenames, processed_size_callback=None):
|
||||||
|
"""
|
||||||
|
Build a data structure that describes the list of files
|
||||||
|
"""
|
||||||
|
if self.web.mode == 'website':
|
||||||
|
self.common.log("WebsiteModeWeb", "set_file_info")
|
||||||
|
self.web.cancel_compression = True
|
||||||
|
|
||||||
|
# This is only the root files and dirs, as opposed to all of them
|
||||||
|
self.root_files = {}
|
||||||
|
|
||||||
|
# If there's just one folder, replace filenames with a list of files inside that folder
|
||||||
|
if len(filenames) == 1 and os.path.isdir(filenames[0]):
|
||||||
|
filenames = [os.path.join(filenames[0], x) for x in os.listdir(filenames[0])]
|
||||||
|
|
||||||
|
self.build_file_list(filenames)
|
||||||
|
|
||||||
|
elif self.web.mode == 'share':
|
||||||
|
self.common.log("ShareModeWeb", "set_file_info")
|
||||||
|
self.web.cancel_compression = False
|
||||||
|
self.build_zipfile_list(filenames, processed_size_callback)
|
||||||
|
|
||||||
|
return True
|
||||||
|
@ -177,19 +177,8 @@ class ShareModeWeb(BaseModeWeb):
|
|||||||
r.headers.set('Content-Type', content_type)
|
r.headers.set('Content-Type', content_type)
|
||||||
return r
|
return r
|
||||||
|
|
||||||
def set_file_info(self, filenames, processed_size_callback=None):
|
def build_zipfile_list(self, filenames, processed_size_callback=None):
|
||||||
"""
|
self.common.log("ShareModeWeb", "build_file_list")
|
||||||
Using the list of filenames being shared, fill in details that the web
|
|
||||||
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("ShareModeWeb", "set_file_info")
|
|
||||||
self.web.cancel_compression = False
|
|
||||||
|
|
||||||
self.cleanup_filenames = []
|
|
||||||
|
|
||||||
# build file info list
|
|
||||||
self.file_info = {'files': [], 'dirs': []}
|
|
||||||
for filename in filenames:
|
for filename in filenames:
|
||||||
info = {
|
info = {
|
||||||
'filename': filename,
|
'filename': filename,
|
||||||
|
@ -10,12 +10,14 @@ from .. import strings
|
|||||||
|
|
||||||
class WebsiteModeWeb(BaseModeWeb):
|
class WebsiteModeWeb(BaseModeWeb):
|
||||||
"""
|
"""
|
||||||
All of the web logic for share mode
|
All of the web logic for website mode
|
||||||
"""
|
"""
|
||||||
def init(self):
|
def init(self):
|
||||||
|
|
||||||
self.common.log('WebsiteModeWeb', '__init__')
|
self.common.log('WebsiteModeWeb', '__init__')
|
||||||
|
|
||||||
|
# Reset assets path
|
||||||
|
self.web.app.static_folder=self.common.get_resource_path('share/static')
|
||||||
|
|
||||||
self.define_routes()
|
self.define_routes()
|
||||||
|
|
||||||
def define_routes(self):
|
def define_routes(self):
|
||||||
@ -127,22 +129,12 @@ class WebsiteModeWeb(BaseModeWeb):
|
|||||||
static_url_path=self.web.static_url_path))
|
static_url_path=self.web.static_url_path))
|
||||||
return self.web.add_security_headers(r)
|
return self.web.add_security_headers(r)
|
||||||
|
|
||||||
def set_file_info(self, filenames):
|
def build_file_list(self, filenames):
|
||||||
"""
|
"""
|
||||||
Build a data structure that describes the list of files that make up
|
Build a data structure that describes the list of files that make up
|
||||||
the static website.
|
the static website.
|
||||||
"""
|
"""
|
||||||
self.common.log("WebsiteModeWeb", "set_file_info")
|
self.common.log("WebsiteModeWeb", "build_file_list")
|
||||||
|
|
||||||
# This is a dictionary that maps HTTP routes to filenames on disk
|
|
||||||
self.files = {}
|
|
||||||
|
|
||||||
# This is only the root files and dirs, as opposed to all of them
|
|
||||||
self.root_files = {}
|
|
||||||
|
|
||||||
# If there's just one folder, replace filenames with a list of files inside that folder
|
|
||||||
if len(filenames) == 1 and os.path.isdir(filenames[0]):
|
|
||||||
filenames = [os.path.join(filenames[0], x) for x in os.listdir(filenames[0])]
|
|
||||||
|
|
||||||
# Loop through the files
|
# Loop through the files
|
||||||
for filename in filenames:
|
for filename in filenames:
|
||||||
|
Loading…
Reference in New Issue
Block a user