fixed that insatnt upload doesnt go on top of fiel upload model and other minor bugfixes

This commit is contained in:
spitkov 2024-09-16 12:09:50 +02:00
parent 740300edaf
commit a2544633e6
2 changed files with 57 additions and 13 deletions

26
app.py
View File

@ -238,6 +238,9 @@ def redirect_vanity(vanity, password=None):
db = get_db() db = get_db()
cursor = db.cursor() 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) # 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,)) cursor.execute("SELECT content.*, users.username FROM content LEFT JOIN users ON content.user_id = users.id WHERE content.vanity = ?", (vanity,))
content = cursor.fetchone() 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] 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}") 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 is_private and stored_password:
if password: if password:
if password != stored_password: if password != stored_password:
@ -268,16 +278,12 @@ def redirect_vanity(vanity, password=None):
elif content_type == 'file': elif content_type == 'file':
file_path = os.path.join(app.config['UPLOAD_FOLDER'], content_data) file_path = os.path.join(app.config['UPLOAD_FOLDER'], content_data)
if os.path.exists(file_path): if os.path.exists(file_path):
file_size = os.path.getsize(file_path) if is_download:
file_extension = os.path.splitext(content_data)[1].lower() # Force download
is_image = file_extension in ['.jpg', '.jpeg', '.png', '.gif'] return send_file(file_path, as_attachment=True, download_name=content_data)
return render_template('og_file.html', else:
filename=content_data, # Serve the file for viewing/embedding
file_size=file_size, return send_file(file_path)
username=username,
created_at=created_at,
is_image=is_image,
file_url=url_for('redirect_vanity', vanity=vanity, _external=True))
elif content_type == 'pastebin': elif content_type == 'pastebin':
first_lines = '\n'.join(content_data.split('\n')[:5]) # Get first 5 lines first_lines = '\n'.join(content_data.split('\n')[:5]) # Get first 5 lines
return render_template('og_pastebin.html', return render_template('og_pastebin.html',

View File

@ -296,6 +296,26 @@
z-index: 10000; z-index: 10000;
display: none; 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;
}
</style> </style>
</head> </head>
<body> <body>
@ -385,11 +405,12 @@
</div> </div>
</div> </div>
<div class="instant-upload-overlay"></div>
<div class="instant-upload-result"> <div class="instant-upload-result">
<span class="close-btn" onclick="closeInstantUploadResult()">&times;</span>
<h3>File Uploaded</h3> <h3>File Uploaded</h3>
<p>Direct download URL: <a id="directDownloadUrl" href="#" target="_blank"></a></p> <p>Direct download URL: <a id="directDownloadUrl" href="#" target="_blank"></a></p>
<p>Normal URL: <a id="normalUrl" href="#" target="_blank"></a></p> <p>Normal URL: <a id="normalUrl" href="#" target="_blank"></a></p>
<button onclick="closeInstantUploadResult()">Close</button>
</div> </div>
<footer class="footer"> <footer class="footer">
@ -434,6 +455,8 @@
}); });
}); });
let isFileModalOpen = false;
function openModal(modalId) { function openModal(modalId) {
const modal = document.getElementById(modalId); const modal = document.getElementById(modalId);
const button = document.querySelector(`button[onclick="openModal('${modalId}')"]`); const button = document.querySelector(`button[onclick="openModal('${modalId}')"]`);
@ -458,6 +481,10 @@
clearInterval(fadeIn); clearInterval(fadeIn);
} }
}, 30); }, 30);
if (modalId === 'fileModal') {
isFileModalOpen = true;
}
} }
function closeModal(modalId) { function closeModal(modalId) {
@ -477,11 +504,18 @@
modal.style.display = "none"; modal.style.display = "none";
} }
}, 30); }, 30);
if (modalId === 'fileModal') {
isFileModalOpen = false;
}
} }
window.onclick = function(event) { window.onclick = function(event) {
if (event.target.className === "modal") { if (event.target.className === "modal") {
event.target.style.display = "none"; event.target.style.display = "none";
if (event.target.id === 'fileModal') {
isFileModalOpen = false;
}
} }
} }
@ -714,7 +748,9 @@
// Global drag and drop // Global drag and drop
document.addEventListener('dragover', function(e) { document.addEventListener('dragover', function(e) {
e.preventDefault(); e.preventDefault();
if (!isFileModalOpen) {
document.querySelector('.global-drop-area').style.display = 'flex'; document.querySelector('.global-drop-area').style.display = 'flex';
}
}); });
document.addEventListener('dragleave', function(e) { document.addEventListener('dragleave', function(e) {
@ -726,7 +762,7 @@
document.addEventListener('drop', function(e) { document.addEventListener('drop', function(e) {
e.preventDefault(); e.preventDefault();
document.querySelector('.global-drop-area').style.display = 'none'; document.querySelector('.global-drop-area').style.display = 'none';
if (e.dataTransfer.files.length > 0) { if (!isFileModalOpen && e.dataTransfer.files.length > 0) {
instantUploadFile(e.dataTransfer.files[0]); instantUploadFile(e.dataTransfer.files[0]);
} }
}); });
@ -746,6 +782,7 @@
document.getElementById('directDownloadUrl').textContent = data.download_url; document.getElementById('directDownloadUrl').textContent = data.download_url;
document.getElementById('normalUrl').href = data.url; document.getElementById('normalUrl').href = data.url;
document.getElementById('normalUrl').textContent = data.url; document.getElementById('normalUrl').textContent = data.url;
document.querySelector('.instant-upload-overlay').style.display = 'block';
document.querySelector('.instant-upload-result').style.display = 'block'; document.querySelector('.instant-upload-result').style.display = 'block';
} else { } else {
alert('Error uploading file: ' + data.error); alert('Error uploading file: ' + data.error);
@ -758,6 +795,7 @@
} }
function closeInstantUploadResult() { function closeInstantUploadResult() {
document.querySelector('.instant-upload-overlay').style.display = 'none';
document.querySelector('.instant-upload-result').style.display = 'none'; document.querySelector('.instant-upload-result').style.display = 'none';
} }