Daniel Sheffield vor 1 Jahr
Ursprung
Commit
e18c389d5f

+ 13 - 2
app/rest/pyapi.py

@@ -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,

+ 1 - 0
app/rest/requirements.txt

@@ -6,3 +6,4 @@ cherrypy
 base32-lib
 lxml
 linkpreview
+qrcode

+ 7 - 0
app/rest/templates/goto.tpl

@@ -12,6 +12,12 @@ html {
 body {
   background-color: #080808;
   color: #cccccc;
+}
+svg {
+  background-color: floralwhite;
+  color: black;
+  max-height: min(100vh, calc(100vw * 9 / 16));
+  max-width: calc(100vw - 2em);
 }
     </style>
     <title>Go to ...</title>
@@ -35,6 +41,7 @@ body {
         </div>
       </div>
       <div class="pure-u-1">
+        <p><details><summary> Show QR code ...</summary>{{!svg}}</details></p>
 {{!form}}
       </div>
       <div class="pure-u-1-3"></div>

+ 8 - 1
app/rest/templates/paste.tpl

@@ -13,6 +13,12 @@ html {
 body {
   background-color: #080808;
   color: #cccccc;
+}
+svg {
+  background-color: floralwhite;
+  color: black;
+  max-height: min(100vh, calc(100vw * 9 / 16));
+  max-width: calc(100vw - 2em);
 }
     </style>
     <title>Paste</title>
@@ -33,11 +39,12 @@ body {
         </div>
       </div>
       <div class="pure-u-1">
-        <div class="pure-button" style="margin: 1em 0 1em; background: #4f8f4f;">
+        <div class="pure-button" style="margin: 1em 0 0; background: #4f8f4f;">
           <a href="{{!link}}" style="color: floralwhite;">{{ link }}</a>
         </div>
       </div>
       <div class="pure-u-1">
+        <p><details><summary> Show QR code ...</summary>{{!svg}}</details></p>
 {{!form}}
 <form id="download" method="get" action="{{ download }}">
 <input name="raw" type="text" hidden="true" value="true" />

+ 7 - 0
app/rest/templates/upload.tpl

@@ -13,6 +13,12 @@ html {
 body {
   background-color: #080808;
   color: #cccccc;
+}
+svg {
+  background-color: floralwhite;
+  color: black;
+  max-height: min(100vh, calc(100vw * 9 / 16));
+  max-width: calc(100vw - 2em);
 }
     </style>
     <title>Upload</title>
@@ -35,6 +41,7 @@ body {
         </div>
       </div>
       <div class="pure-u-1">
+        <p><details><summary> Show QR code ...</summary>{{!svg}}</details></p>
 {{!form}}
       </div>
     </div>