|
@@ -17,7 +17,6 @@ from psycopg import Cursor, connect
|
|
from psycopg.rows import TupleRow
|
|
from psycopg.rows import TupleRow
|
|
from linkpreview import link_preview
|
|
from linkpreview import link_preview
|
|
|
|
|
|
-from .qr import get_qr_code
|
|
|
|
from .validate import get_file_mimetype, get_file_size, get_filename, validate, validate_file, validate_parameter, validate_url
|
|
from .validate import get_file_mimetype, get_file_size, 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
|
|
@@ -165,8 +164,7 @@ def get_clip(filename):
|
|
path = f'{filename}/{filename}.{ext}'
|
|
path = f'{filename}/{filename}.{ext}'
|
|
|
|
|
|
if ext == 'qr':
|
|
if ext == 'qr':
|
|
- mimetype = 'image/svg+xml'
|
|
|
|
- return static_file(path, root='app/rest/static', mimetype=mimetype)
|
|
|
|
|
|
+ return static_file(path, root='app/rest/static', mimetype='image/svg+xml')
|
|
|
|
|
|
filename = filename and normalize_base32(filename)
|
|
filename = filename and normalize_base32(filename)
|
|
if not request.params.raw.lower() == 'true':
|
|
if not request.params.raw.lower() == 'true':
|
|
@@ -198,12 +196,11 @@ def upload():
|
|
response.content_type = 'text/html; charset=utf-8'
|
|
response.content_type = 'text/html; charset=utf-8'
|
|
disabled = True if _hash else False
|
|
disabled = True if _hash else False
|
|
form = template('file-form', action='/upload', method='post', disabled=disabled)
|
|
form = template('file-form', action='/upload', method='post', disabled=disabled)
|
|
- svg = get_qr_code(link)
|
|
|
|
|
|
|
|
return template(
|
|
return template(
|
|
'upload',
|
|
'upload',
|
|
form=form,
|
|
form=form,
|
|
- svg=svg,
|
|
|
|
|
|
+ qr=f'{LOCATION}/upload/{_hash}.qr' if _hash else f'{LOCATION}/grocery/static/upload-qr.svg',
|
|
link=link,
|
|
link=link,
|
|
mimetype=mimetype,
|
|
mimetype=mimetype,
|
|
disabled=disabled
|
|
disabled=disabled
|
|
@@ -218,13 +215,22 @@ def upload():
|
|
if len(upload.file.read()) == 0:
|
|
if len(upload.file.read()) == 0:
|
|
return abort(400, "File is empty")
|
|
return abort(400, "File is empty")
|
|
|
|
|
|
- _b32 = save_upload(upload.raw_filename , upload.file, root='app/rest/static')
|
|
|
|
|
|
+ _b32 = save_upload(upload.raw_filename, LOCATION, upload.file, root='app/rest/static')
|
|
return redirect(f'/upload?hash={_b32}')
|
|
return redirect(f'/upload?hash={_b32}')
|
|
|
|
|
|
|
|
|
|
@route('/upload/<filename:path>', method='GET')
|
|
@route('/upload/<filename:path>', method='GET')
|
|
def get_upload(filename):
|
|
def get_upload(filename):
|
|
|
|
+ ext = 'file'
|
|
|
|
+ if filename and filename.endswith('.qr'):
|
|
|
|
+ filename, ext = filename.split('.', 1)
|
|
|
|
+
|
|
filename = filename and normalize_base32(filename)
|
|
filename = filename and normalize_base32(filename)
|
|
|
|
+ path = f'{filename}/{filename}.{ext}'
|
|
|
|
+
|
|
|
|
+ if ext == 'qr':
|
|
|
|
+ return static_file(path, root='app/rest/static', mimetype='image/svg+xml')
|
|
|
|
+
|
|
download = True
|
|
download = True
|
|
mimetype = True
|
|
mimetype = True
|
|
if request.params.download == "false":
|
|
if request.params.download == "false":
|
|
@@ -250,7 +256,6 @@ def goto():
|
|
return redirect(target)
|
|
return redirect(target)
|
|
|
|
|
|
link = f'{LOCATION}/goto/{_hash}' if content else f'{LOCATION}/goto'
|
|
link = f'{LOCATION}/goto/{_hash}' if content else f'{LOCATION}/goto'
|
|
- svg = get_qr_code(content, fallback=link)
|
|
|
|
disabled = True if content else False
|
|
disabled = True if content else False
|
|
response.content_type = 'text/html; charset=utf-8'
|
|
response.content_type = 'text/html; charset=utf-8'
|
|
form = template(
|
|
form = template(
|
|
@@ -274,7 +279,7 @@ def goto():
|
|
return template(
|
|
return template(
|
|
'goto',
|
|
'goto',
|
|
form=form,
|
|
form=form,
|
|
- svg=svg,
|
|
|
|
|
|
+ qr=f'{LOCATION}/goto/{_hash}.qr' if content else f'{LOCATION}/grocery/static/goto-qr.svg',
|
|
link=link,
|
|
link=link,
|
|
disabled=disabled,
|
|
disabled=disabled,
|
|
preview=preview,
|
|
preview=preview,
|
|
@@ -282,7 +287,7 @@ def goto():
|
|
|
|
|
|
if request.method == 'POST':
|
|
if request.method == 'POST':
|
|
content = validate_parameter(request, 'url')
|
|
content = validate_parameter(request, 'url')
|
|
- _b32 = save(content)
|
|
|
|
|
|
+ _b32 = save(content, LOCATION)
|
|
|
|
|
|
# validate but save content unmodified
|
|
# validate but save content unmodified
|
|
_ = validate_url(content.decode('utf-8'))
|
|
_ = validate_url(content.decode('utf-8'))
|
|
@@ -291,7 +296,16 @@ def goto():
|
|
|
|
|
|
@route('/goto/<filename:path>', method='GET')
|
|
@route('/goto/<filename:path>', method='GET')
|
|
def redirect_goto(filename):
|
|
def redirect_goto(filename):
|
|
|
|
+ ext = 'file'
|
|
|
|
+ if filename and filename.endswith('.qr'):
|
|
|
|
+ filename, ext = filename.split('.', 1)
|
|
|
|
+
|
|
filename = filename and normalize_base32(filename)
|
|
filename = filename and normalize_base32(filename)
|
|
|
|
+ path = f'{filename}/{filename}.{ext}'
|
|
|
|
+
|
|
|
|
+ if ext == 'qr':
|
|
|
|
+ return static_file(path, root='app/rest/static', mimetype='image/svg+xml')
|
|
|
|
+
|
|
return redirect(f'/goto?hash={filename}&go=true')
|
|
return redirect(f'/goto?hash={filename}&go=true')
|
|
|
|
|
|
@route('/<any>/', method='GET')
|
|
@route('/<any>/', method='GET')
|