|
@@ -17,6 +17,7 @@ from psycopg import Cursor, connect
|
|
|
from psycopg.rows import TupleRow
|
|
|
from linkpreview import link_preview
|
|
|
|
|
|
+from .qr import get_qr_code
|
|
|
from .validate import validate, validate_file, validate_parameter, validate_url
|
|
|
from .hash_util import normalize_base32
|
|
|
from .route_decorators import normalize, poison, cursor
|
|
@@ -102,6 +103,7 @@ LOCATION = SCHEME + (f"{HOST}." if HOST else "") + DOMAIN + (f":{PORT}" if PORT
|
|
|
|
|
|
@route('/clip', method=['GET', 'POST'])
|
|
|
def clip():
|
|
|
+
|
|
|
if request.method == 'GET':
|
|
|
_hash = request.params.hash
|
|
|
if _hash:
|
|
@@ -110,6 +112,8 @@ def clip():
|
|
|
else:
|
|
|
content = None
|
|
|
link = f'{LOCATION}/clip/{_hash}' if content else f'{LOCATION}/clip'
|
|
|
+ svg = get_qr_code(link if not content or len(content) > 300 else content)
|
|
|
+
|
|
|
response.content_type = 'text/html; charset=utf-8'
|
|
|
form = template(
|
|
|
'clip-form',
|
|
@@ -121,6 +125,7 @@ def clip():
|
|
|
return template(
|
|
|
'paste',
|
|
|
form=form,
|
|
|
+ svg=svg,
|
|
|
link=link,
|
|
|
disabled=True if content else False,
|
|
|
download=f'/clip/{_hash}' if content else None
|
|
@@ -128,7 +133,6 @@ def clip():
|
|
|
|
|
|
if request.method == 'POST':
|
|
|
content = validate_parameter(request, 'paste')
|
|
|
-
|
|
|
if request.params.copy != 'true':
|
|
|
_b32 = save(content)
|
|
|
return redirect(f'/clip?hash={_b32}')
|
|
@@ -141,9 +145,11 @@ def clip():
|
|
|
content=content,
|
|
|
disabled=False
|
|
|
)
|
|
|
+ svg = get_qr_code(link if not content or len(content) > 300 else content)
|
|
|
return template(
|
|
|
'paste',
|
|
|
form=form,
|
|
|
+ svg=svg,
|
|
|
link=f'{LOCATION}/clip',
|
|
|
disabled=False,
|
|
|
download=None
|
|
@@ -166,6 +172,7 @@ def get_clip(filename):
|
|
|
|
|
|
@route('/upload', method=['GET', 'POST'])
|
|
|
def upload():
|
|
|
+
|
|
|
if request.method == 'GET':
|
|
|
_hash = request.params.hash
|
|
|
if _hash:
|
|
@@ -174,7 +181,8 @@ def upload():
|
|
|
link = f'{LOCATION}/upload/{_hash}' if _hash else f'{LOCATION}/upload'
|
|
|
response.content_type = 'text/html; charset=utf-8'
|
|
|
form = template('file-form', action='/upload', method='post')
|
|
|
- return template('upload', form=form, link=link)
|
|
|
+ svg = get_qr_code(link)
|
|
|
+ return template('upload', form=form, svg=svg, link=link)
|
|
|
|
|
|
if request.method == 'POST':
|
|
|
if 'paste' not in request.files:
|
|
@@ -198,6 +206,7 @@ def get_upload(filename):
|
|
|
|
|
|
@route('/goto', method=['GET', 'POST'])
|
|
|
def goto():
|
|
|
+
|
|
|
if request.method == 'GET':
|
|
|
_hash = request.params.hash
|
|
|
if _hash:
|
|
@@ -211,6 +220,7 @@ def goto():
|
|
|
return redirect(target)
|
|
|
|
|
|
link = f'{LOCATION}/goto/{_hash}' if content else f'{LOCATION}/goto'
|
|
|
+ svg = get_qr_code(link if not content or len(content) > 300 else content)
|
|
|
disabled = True if content else False
|
|
|
response.content_type = 'text/html; charset=utf-8'
|
|
|
form = template(
|
|
@@ -234,6 +244,7 @@ def goto():
|
|
|
return template(
|
|
|
'goto',
|
|
|
form=form,
|
|
|
+ svg=svg,
|
|
|
link=link,
|
|
|
disabled=disabled,
|
|
|
preview=preview,
|