Daniel Sheffield 1 жил өмнө
parent
commit
a326bf8402

+ 13 - 9
app/rest/pyapi.py

@@ -132,7 +132,7 @@ def clip():
         if request.params.copy != 'true':
             _b32 = save(content)
             return redirect(f'/clip?hash={_b32}')
-        
+
         response.content_type = 'text/html; charset=utf-8'
         form = template(
             'clip-form',
@@ -170,7 +170,7 @@ def upload():
         _hash = request.params.hash
         if _hash:
             _hash = normalize_base32(_hash)
-        
+
         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')
@@ -179,7 +179,7 @@ def upload():
     if request.method == 'POST':
         if 'paste' not in request.files:
             return abort(400, "Parameter 'paste' must be specified")
-        
+
         upload = request.files['paste']
         if isinstance(upload.file, BytesIO):
             if len(upload.file.read()) == 0:
@@ -205,11 +205,11 @@ def goto():
             content = validate(_hash).decode('utf-8')
         else:
             content = None
-        
+
         if content and request.params.go == 'true':
             target = validate_url(content)
             return redirect(target)
-        
+
         link = f'{LOCATION}/goto/{_hash}' if content else f'{LOCATION}/goto'
         disabled = True if content else False
         response.content_type = 'text/html; charset=utf-8'
@@ -222,10 +222,14 @@ def goto():
         )
         preview = dict()
         if content:
-            page = link_preview(link, parser="lxml")
-            preview['title'] = page.title
-            preview['img'] = page.absolute_image
-            preview['domain'] = page.site_name
+            try:
+                page = link_preview(link, parser="lxml")
+                preview['title'] = page.title
+                preview['img'] = page.absolute_image
+                preview['domain'] = page.site_name
+                preview['link'] = content
+            except:
+                pass
 
         return template(
             'goto',

+ 22 - 0
app/rest/templates/card-goto.tpl

@@ -0,0 +1,22 @@
+<style>
+.card img {
+    color: floralwhite;
+    object-fit: cover;
+    width: 100%;
+    height: 100%;
+}
+</style>
+<a href="{{link}}">
+<article class="card">
+  <header>
+    <h2>{{title}}</h2>
+  </header>
+  <figure> 
+    <img src="{{img}}" alt="{{title}}">
+    <figcaption>{{domain}}</figcaption>
+  </figure>
+  <div class="content">
+    {{link}}
+  </div>       
+</article>
+</a>

+ 1 - 1
app/rest/templates/goto.tpl

@@ -40,7 +40,7 @@ body {
       <div class="pure-u-1-3"></div>
       <div class="pure-u-1-3">
       % if preview:
-      %   include('goto-preview', **preview)
+      %   include('card-goto', **preview)
       % end
       </div>
       <div class="pure-u-1-3"></div>