Start code sharing between WebsiteMode and ShareMode

This commit is contained in:
hiro 2019-06-05 13:47:41 +02:00
parent 9a327f26ea
commit 0f40e9589c
3 changed files with 52 additions and 36 deletions

View File

@ -0,0 +1,45 @@
import os
import sys
import tempfile
import mimetypes
from flask import Response, request, render_template, make_response
from .. import strings
class BaseModeWeb(object):
"""
All of the web logic shared between share and website mode
"""
def __init__(self, common, web):
super(BaseModeWeb, self).__init__()
self.common = common
self.web = web
# Information about the file to be shared
self.file_info = []
self.is_zipped = False
self.download_filename = None
self.download_filesize = None
self.gzip_filename = None
self.gzip_filesize = None
self.zip_writer = None
# Dictionary mapping file paths to filenames on disk
self.files = {}
self.visit_count = 0
self.download_count = 0
# If "Stop After First Download" is checked (stay_open == False), only allow
# one download at a time.
self.download_in_progress = False
# Reset assets path
self.web.app.static_folder=self.common.get_resource_path('static')
def init(self):
"""
Add custom initialization here.
"""
pass

View File

@ -6,38 +6,17 @@ import mimetypes
import gzip import gzip
from flask import Response, request, render_template, make_response from flask import Response, request, render_template, make_response
from .base_mode import BaseModeWeb
from .. import strings from .. import strings
class ShareModeWeb(object): class ShareModeWeb(BaseModeWeb):
""" """
All of the web logic for share mode All of the web logic for share mode
""" """
def __init__(self, common, web): def init(self):
self.common = common
self.common.log('ShareModeWeb', '__init__') self.common.log('ShareModeWeb', '__init__')
self.web = web
# Information about the file to be shared
self.file_info = []
self.is_zipped = False
self.download_filename = None
self.download_filesize = None
self.gzip_filename = None
self.gzip_filesize = None
self.zip_writer = None
self.download_count = 0
# If "Stop After First Download" is checked (stay_open == False), only allow
# one download at a time.
self.download_in_progress = False
# Reset assets path
self.web.app.static_folder=self.common.get_resource_path('static')
self.define_routes() self.define_routes()
def define_routes(self): def define_routes(self):

View File

@ -4,26 +4,18 @@ import tempfile
import mimetypes import mimetypes
from flask import Response, request, render_template, make_response, send_from_directory from flask import Response, request, render_template, make_response, send_from_directory
from .base_mode import BaseModeWeb
from .. import strings from .. import strings
class WebsiteModeWeb(object): class WebsiteModeWeb(BaseModeWeb):
""" """
All of the web logic for share mode All of the web logic for share mode
""" """
def __init__(self, common, web): def init(self):
self.common = common
self.common.log('WebsiteModeWeb', '__init__') self.common.log('WebsiteModeWeb', '__init__')
self.web = web
# Dictionary mapping file paths to filenames on disk
self.files = {}
self.visit_count = 0
# Reset assets path
self.web.app.static_folder=self.common.get_resource_path('static')
self.define_routes() self.define_routes()
def define_routes(self): def define_routes(self):