Simplify share and receive mode so they no longer need to worry about slug_candidates

This commit is contained in:
Micah Lee 2019-05-20 19:11:24 -07:00
parent 79b87c3e30
commit 7fe733e9fc
No known key found for this signature in database
GPG Key ID: 403C2657CD994F73
2 changed files with 7 additions and 65 deletions

View File

@ -31,7 +31,8 @@ class ReceiveModeWeb(object):
""" """
The web app routes for receiving files The web app routes for receiving files
""" """
def index_logic(): @self.web.app.route("/")
def index():
self.web.add_request(self.web.REQUEST_LOAD, request.path) self.web.add_request(self.web.REQUEST_LOAD, request.path)
if self.common.settings.get('public_mode'): if self.common.settings.get('public_mode'):
@ -44,23 +45,8 @@ class ReceiveModeWeb(object):
upload_action=upload_action)) upload_action=upload_action))
return self.web.add_security_headers(r) return self.web.add_security_headers(r)
@self.web.app.route("/<slug_candidate>") @self.web.app.route("/upload", methods=['POST'])
def index(slug_candidate): def upload(ajax=False):
if not self.can_upload:
return self.web.error403()
self.web.check_slug_candidate(slug_candidate)
return index_logic()
@self.web.app.route("/")
def index_public():
if not self.can_upload:
return self.web.error403()
if not self.common.settings.get('public_mode'):
return self.web.error404()
return index_logic()
def upload_logic(slug_candidate='', ajax=False):
""" """
Handle the upload files POST request, though at this point, the files have Handle the upload files POST request, though at this point, the files have
already been uploaded and saved to their correct locations. already been uploaded and saved to their correct locations.
@ -141,35 +127,11 @@ class ReceiveModeWeb(object):
r = make_response(render_template('thankyou.html')) r = make_response(render_template('thankyou.html'))
return self.web.add_security_headers(r) return self.web.add_security_headers(r)
@self.web.app.route("/<slug_candidate>/upload", methods=['POST'])
def upload(slug_candidate):
if not self.can_upload:
return self.web.error403()
self.web.check_slug_candidate(slug_candidate)
return upload_logic(slug_candidate)
@self.web.app.route("/upload", methods=['POST'])
def upload_public():
if not self.can_upload:
return self.web.error403()
if not self.common.settings.get('public_mode'):
return self.web.error404()
return upload_logic()
@self.web.app.route("/<slug_candidate>/upload-ajax", methods=['POST'])
def upload_ajax(slug_candidate):
if not self.can_upload:
return self.web.error403()
self.web.check_slug_candidate(slug_candidate)
return upload_logic(slug_candidate, ajax=True)
@self.web.app.route("/upload-ajax", methods=['POST']) @self.web.app.route("/upload-ajax", methods=['POST'])
def upload_ajax_public(): def upload_ajax_public():
if not self.can_upload: if not self.can_upload:
return self.web.error403() return self.web.error403()
if not self.common.settings.get('public_mode'): return upload(ajax=True)
return self.web.error404()
return upload_logic(ajax=True)
class ReceiveModeWSGIMiddleware(object): class ReceiveModeWSGIMiddleware(object):

View File

@ -44,18 +44,8 @@ class ShareModeWeb(object):
""" """
The web app routes for sharing files The web app routes for sharing files
""" """
@self.web.app.route("/<slug_candidate>")
def index(slug_candidate):
self.web.check_slug_candidate(slug_candidate)
return index_logic()
@self.web.app.route("/") @self.web.app.route("/")
def index_public(): def index():
if not self.common.settings.get('public_mode'):
return self.web.error404()
return index_logic()
def index_logic(slug_candidate=''):
""" """
Render the template for the onionshare landing page. Render the template for the onionshare landing page.
""" """
@ -94,18 +84,8 @@ class ShareModeWeb(object):
is_zipped=self.is_zipped)) is_zipped=self.is_zipped))
return self.web.add_security_headers(r) return self.web.add_security_headers(r)
@self.web.app.route("/<slug_candidate>/download")
def download(slug_candidate):
self.web.check_slug_candidate(slug_candidate)
return download_logic()
@self.web.app.route("/download") @self.web.app.route("/download")
def download_public(): def download():
if not self.common.settings.get('public_mode'):
return self.web.error404()
return download_logic()
def download_logic(slug_candidate=''):
""" """
Download the zip file. Download the zip file.
""" """