From 7b73facc163c898605d627d16edceb3588fcc059 Mon Sep 17 00:00:00 2001 From: lelo Date: Thu, 1 May 2025 21:37:29 +0200 Subject: [PATCH] update token generation gui --- app.py | 33 +++++++++++++-------- static/app.css | 8 +---- static/app.js | 48 +++++++++++++++++++++++++----- templates/view_token.html | 62 +++++++++++++++++++++++++++++++++++++++ 4 files changed, 124 insertions(+), 27 deletions(-) create mode 100644 templates/view_token.html diff --git a/app.py b/app.py index 2dd702b..be8c101 100755 --- a/app.py +++ b/app.py @@ -17,7 +17,8 @@ from functools import lru_cache from urllib.parse import urlparse, unquote from werkzeug.middleware.proxy_fix import ProxyFix import re - +import qrcode +import base64 import search import auth import analytics as a @@ -415,6 +416,7 @@ def get_transcript(subpath): @auth.require_secret def create_share(subpath): scheme = request.scheme # current scheme (http or https) + host = request.host if 'admin ' not in session and not session.get('admin'): return "Unauthorized", 403 @@ -440,20 +442,25 @@ def create_share(subpath): ] } - print (data) - token = auth.generate_secret_key_compressed(data) - - content = f"""Ordner:\\ -{foldername}\\ -\\ -GΓΌltig bis:\\ -{validity_date}\\ -\\ -Link:\\ -`{scheme}://{request.host}?token={token}`""" - return content, 200, {'Content-Type': 'text/markdown; charset=utf-8'} + url = f"{scheme}://{host}?token={token}" + qr = qrcode.QRCode(version=1, box_size=10, border=4) + qr.add_data(url) + qr.make(fit=True) + img = qr.make_image(fill_color="black", back_color="white") + buffer = io.BytesIO() + img.save(buffer, format="PNG") + buffer.seek(0) + img_base64 = base64.b64encode(buffer.getvalue()).decode('ascii') + token_item = auth.decode_secret_key_compressed(token) + + return render_template('view_token.html', + token_qr_code=img_base64, + token_folder=token_item.get('folders'), + token_url=url, + token_valid_to=token_item.get('validity', 'Unbekannt') + ) def query_recent_connections(): diff --git a/static/app.css b/static/app.css index 8bfd07f..57c34dc 100644 --- a/static/app.css +++ b/static/app.css @@ -100,17 +100,11 @@ div.directory-item a, li.directory-item a, li.file-item a, li.link-item a { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; -} -.directories-grid .directory-item { - background-color: #fff; - padding: 15px; - border-radius: 5px; text-align: center; - box-shadow: 0 1px 3px rgba(0,0,0,0.1); } /* File Item Styles (for both music and image files) */ -.file-item { +.file-item, .directory-item{ display: grid; grid-template-columns: 1fr auto; align-items: center; diff --git a/static/app.js b/static/app.js index f42c754..5f473e5 100644 --- a/static/app.js +++ b/static/app.js @@ -77,26 +77,30 @@ function renderContent(data) { share_link = ''; // Render directories normally if (data.directories.length > 0) { - const areAllShort = data.directories.every(dir => dir.name.length <= 15) && data.files.length === 0; + const areAllShort = data.directories.every(dir => dir.name.length <= 10) && data.files.length === 0; if (areAllShort && data.breadcrumbs.length !== 1) { contentHTML += '
'; data.directories.forEach(dir => { if (admin_enabled && data.breadcrumbs.length != 1) { - share_link = `🌐`; + share_link = `βš™οΈ`; } - contentHTML += `
πŸ“ ${dir.name}${share_link}
`; + contentHTML += `
πŸ“ ${dir.name} + ${share_link} +
`; }); contentHTML += '
'; } else { contentHTML += ''; } @@ -385,7 +389,7 @@ document.querySelectorAll('.play-file').forEach(link => { }) .then(data => { console.log(data); - document.getElementById('transcriptContent').innerHTML = marked.parse(data); + document.getElementById('transcriptContent').innerHTML = data; document.getElementById('transcriptModal').style.display = 'block'; }) .catch(error => { @@ -538,4 +542,34 @@ function syncThemeColor() { .forEach(svg => svg.setAttribute('fill', cssVar)); } + +function copyTokenUrl(url) { + if (navigator.clipboard && window.isSecureContext) { + // Modern approach + navigator.clipboard.writeText(url) + .then(() => { + alert('Token-URL in die Zwischenablage kopiert!'); + }) + .catch(err => { + console.error('Fehler beim Kopieren: ', err); + }); + } else { + // Fallback for older browsers + const textarea = document.createElement('textarea'); + textarea.value = url; + textarea.style.position = 'fixed'; // Verhindert Scrollen + textarea.style.opacity = '0'; + document.body.appendChild(textarea); + textarea.focus(); + textarea.select(); + try { + document.execCommand('copy'); + alert('Token-URL in die Zwischenablage kopiert!'); + } catch (err) { + console.error('Fallback: Kopieren fehlgeschlagen', err); + } + document.body.removeChild(textarea); + } +} + document.addEventListener('DOMContentLoaded', syncThemeColor); \ No newline at end of file diff --git a/templates/view_token.html b/templates/view_token.html new file mode 100644 index 0000000..7ae9a6c --- /dev/null +++ b/templates/view_token.html @@ -0,0 +1,62 @@ + + +
+
+
+
+ QR Code for token +
+
+

Token-Link:

+ Direct Link + +
+
+

GΓΌltig bis:

+ {{ token_valid_to }} +
+
+

Ordner:

+ {% for folder in token_folder %} + {{ folder.foldername }}
+ {% endfor %} +
+
+
+
+
+
+ + \ No newline at end of file