diff --git a/app.py b/app.py index 598e6ad..d33c226 100644 --- a/app.py +++ b/app.py @@ -238,6 +238,9 @@ def redirect_vanity(vanity, password=None): db = get_db() cursor = db.cursor() + # Check if it's a download request + is_download = 'download' 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() @@ -252,6 +255,13 @@ def redirect_vanity(vanity, password=None): 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}") + # Convert created_at to datetime object, including microseconds + try: + created_at = datetime.strptime(created_at, '%Y-%m-%d %H:%M:%S.%f') + except ValueError: + # If the above fails, try without microseconds + created_at = datetime.strptime(created_at, '%Y-%m-%d %H:%M:%S') + if is_private and stored_password: if password: if password != stored_password: @@ -268,16 +278,12 @@ def redirect_vanity(vanity, password=None): elif content_type == 'file': file_path = os.path.join(app.config['UPLOAD_FOLDER'], content_data) if os.path.exists(file_path): - file_size = os.path.getsize(file_path) - file_extension = os.path.splitext(content_data)[1].lower() - is_image = file_extension in ['.jpg', '.jpeg', '.png', '.gif'] - return render_template('og_file.html', - filename=content_data, - file_size=file_size, - username=username, - created_at=created_at, - is_image=is_image, - file_url=url_for('redirect_vanity', vanity=vanity, _external=True)) + if is_download: + # Force download + return send_file(file_path, as_attachment=True, download_name=content_data) + else: + # Serve the file for viewing/embedding + return send_file(file_path) elif content_type == 'pastebin': first_lines = '\n'.join(content_data.split('\n')[:5]) # Get first 5 lines return render_template('og_pastebin.html', diff --git a/templates/index.html b/templates/index.html index ddfa102..479e2a9 100644 --- a/templates/index.html +++ b/templates/index.html @@ -296,6 +296,26 @@ z-index: 10000; display: none; } + + .instant-upload-overlay { + position: fixed; + top: 0; + left: 0; + width: 100%; + height: 100%; + background-color: rgba(0, 0, 0, 0.5); + z-index: 9999; + display: none; + } + + .instant-upload-result .close-btn { + position: absolute; + top: 10px; + right: 10px; + color: white; + font-size: 24px; + cursor: pointer; + } @@ -385,11 +405,12 @@ +
+ ×

File Uploaded

Direct download URL:

Normal URL:

-