|
@@ -18,7 +18,7 @@ from psycopg.rows import TupleRow
|
|
from linkpreview import link_preview
|
|
from linkpreview import link_preview
|
|
|
|
|
|
from .qr import get_qr_code
|
|
from .qr import get_qr_code
|
|
-from .validate import validate, validate_file, validate_parameter, validate_url
|
|
|
|
|
|
+from .validate import get_file_mimetype, get_filename, validate, validate_file, validate_parameter, validate_url
|
|
from .hash_util import normalize_base32
|
|
from .hash_util import normalize_base32
|
|
from .route_decorators import normalize, poison, cursor
|
|
from .route_decorators import normalize, poison, cursor
|
|
from .query_to_xml import get_categories, get_groups, get_products, get_tags
|
|
from .query_to_xml import get_categories, get_groups, get_products, get_tags
|
|
@@ -176,14 +176,18 @@ def upload():
|
|
|
|
|
|
if request.method == 'GET':
|
|
if request.method == 'GET':
|
|
_hash = request.params.hash
|
|
_hash = request.params.hash
|
|
|
|
+ mimetype = None
|
|
if _hash:
|
|
if _hash:
|
|
_hash = normalize_base32(_hash)
|
|
_hash = normalize_base32(_hash)
|
|
-
|
|
|
|
|
|
+ name = get_filename(_hash)
|
|
|
|
+ mimetype = get_file_mimetype(name)
|
|
|
|
+
|
|
link = f'{LOCATION}/upload/{_hash}' if _hash else f'{LOCATION}/upload'
|
|
link = f'{LOCATION}/upload/{_hash}' if _hash else f'{LOCATION}/upload'
|
|
response.content_type = 'text/html; charset=utf-8'
|
|
response.content_type = 'text/html; charset=utf-8'
|
|
form = template('file-form', action='/upload', method='post')
|
|
form = template('file-form', action='/upload', method='post')
|
|
svg = get_qr_code(link)
|
|
svg = get_qr_code(link)
|
|
- return template('upload', form=form, svg=svg, link=link)
|
|
|
|
|
|
+
|
|
|
|
+ return template('upload', form=form, svg=svg, link=link, mimetype=mimetype)
|
|
|
|
|
|
if request.method == 'POST':
|
|
if request.method == 'POST':
|
|
if 'paste' not in request.files:
|
|
if 'paste' not in request.files:
|
|
@@ -201,8 +205,11 @@ def upload():
|
|
@route('/upload/<filename:path>', method='GET')
|
|
@route('/upload/<filename:path>', method='GET')
|
|
def get_upload(filename):
|
|
def get_upload(filename):
|
|
filename = filename and normalize_base32(filename)
|
|
filename = filename and normalize_base32(filename)
|
|
|
|
+ download = True
|
|
|
|
+ if request.params.download == "false":
|
|
|
|
+ download = False
|
|
|
|
|
|
- return validate_file(filename)
|
|
|
|
|
|
+ return validate_file(filename, download=download)
|
|
|
|
|
|
|
|
|
|
@route('/goto', method=['GET', 'POST'])
|
|
@route('/goto', method=['GET', 'POST'])
|