From 052acdb394190f684368b58ccc84d5b324a10d05 Mon Sep 17 00:00:00 2001 From: spitkov Date: Mon, 16 Sep 2024 13:02:12 +0200 Subject: [PATCH] minor fixes --- app.py | 21 +++++---------- templates/file_info.html | 11 ++++---- templates/og_file.html | 4 +-- templates/pastebin.html | 56 ++++++++++++++++++++-------------------- 4 files changed, 42 insertions(+), 50 deletions(-) diff --git a/app.py b/app.py index 42f4f61..9803563 100644 --- a/app.py +++ b/app.py @@ -242,9 +242,6 @@ def redirect_vanity(vanity, password=None): app.logger.info(f"Request URL: {request.url}") app.logger.info(f"Request endpoint: {request.endpoint}") app.logger.info(f"Request view args: {request.view_args}") - app.logger.info(f"All routes:") - for rule in app.url_map.iter_rules(): - app.logger.info(f" - {rule}") db = get_db() cursor = db.cursor() @@ -252,16 +249,9 @@ def redirect_vanity(vanity, password=None): is_download = 'download' in request.path is_raw = 'raw' in request.path - # First, try to find the content with the full vanity (including extension) cursor.execute("SELECT content.*, users.username FROM content LEFT JOIN users ON content.user_id = users.id WHERE content.vanity = ?", (vanity,)) content = cursor.fetchone() - # If not found, try without the extension - if not content: - vanity_without_extension = os.path.splitext(vanity)[0] - cursor.execute("SELECT content.*, users.username FROM content LEFT JOIN users ON content.user_id = users.id WHERE content.vanity LIKE ?", (f"{vanity_without_extension}%",)) - content = cursor.fetchone() - if content: content_type, content_data, created_at, user_id, is_private, stored_password, username = content[1], content[2], content[3], content[4], content[5], content[6], content[7] app.logger.info(f"Content found: type={content_type}, data={content_data}, is_private={is_private}") @@ -292,9 +282,9 @@ def redirect_vanity(vanity, password=None): is_embeddable = file_extension in ['.jpg', '.jpeg', '.png', '.gif', '.svg', '.pdf'] file_url = url_for('redirect_vanity', vanity=vanity, _external=True) - if is_download or (not is_embeddable and not is_raw): + if is_download: return send_file(file_path, as_attachment=True) - elif is_raw and is_embeddable: + elif is_raw: return send_file(file_path) else: return render_template('file_info.html', @@ -1129,10 +1119,11 @@ def upload_file(): app.logger.info(f"1. Calling url_for with: 'redirect_vanity', vanity={vanity_with_extension}") app.logger.info(f" Full parameters: endpoint='redirect_vanity', vanity={vanity_with_extension}, _external=True, _scheme={scheme}") - # Modify this line to remove the /raw suffix - short_url = url_for('redirect_vanity', vanity=vanity_with_extension, _external=True, _scheme=scheme).rstrip('/raw') + # Capture the result of url_for and remove the /raw suffix + short_url = url_for('redirect_vanity', vanity=vanity_with_extension, _external=True, _scheme=scheme) + short_url = short_url.rstrip('/raw') - app.logger.info(f"2. Result of url_for: {short_url}") + app.logger.info(f"2. Result of url_for (after removing /raw): {short_url}") app.logger.info(f"3. Inspecting short_url:") app.logger.info(f" - Base: {short_url.split('?')[0]}") app.logger.info(f" - Query parameters: {short_url.split('?')[1] if '?' in short_url else 'None'}") diff --git a/templates/file_info.html b/templates/file_info.html index 9f574cf..25f73fc 100644 --- a/templates/file_info.html +++ b/templates/file_info.html @@ -9,7 +9,7 @@ {% if is_embeddable %} - + {% endif %} @@ -110,20 +110,21 @@
File size: {{ file_size|filesizeformat }}
Uploaded by: {{ username }}
Date: {{ created_at.strftime('%Y-%m-%d %H:%M:%S') }}
+
File type: {{ filename.split('.')[-1].upper() if '.' in filename else 'Unknown' }}
{% if is_embeddable %}
{% if filename.lower().endswith(('.jpg', '.jpeg', '.png', '.gif', '.svg')) %} - {{ filename }} + {{ filename }} {% elif filename.lower().endswith('.pdf') %} - + {% endif %}
{% endif %}
- Download - View Raw + Download + View Raw {% if current_user.is_authenticated and current_user.id == user_id %} {% if filename.lower().endswith(('.txt', '.html', '.css', '.js', '.py', '.md')) or '.' not in filename %} Edit diff --git a/templates/og_file.html b/templates/og_file.html index 24b1a98..8f1dd8d 100644 --- a/templates/og_file.html +++ b/templates/og_file.html @@ -9,14 +9,14 @@ {% if is_embeddable %} - + {% endif %} \ No newline at end of file diff --git a/templates/pastebin.html b/templates/pastebin.html index c33cd32..4b48c14 100644 --- a/templates/pastebin.html +++ b/templates/pastebin.html @@ -3,11 +3,14 @@ - Pastebin {{ vanity }} - sxbin - + {{ filename }} - sxbin + - + + {% if is_embeddable %} + + {% endif %}