fixed that insatnt upload doesnt go on top of fiel upload model and other minor bugfixes
This commit is contained in:
parent
740300edaf
commit
a2544633e6
26
app.py
26
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',
|
||||
|
@ -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;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
@ -385,11 +405,12 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="instant-upload-overlay"></div>
|
||||
<div class="instant-upload-result">
|
||||
<span class="close-btn" onclick="closeInstantUploadResult()">×</span>
|
||||
<h3>File Uploaded</h3>
|
||||
<p>Direct download URL: <a id="directDownloadUrl" href="#" target="_blank"></a></p>
|
||||
<p>Normal URL: <a id="normalUrl" href="#" target="_blank"></a></p>
|
||||
<button onclick="closeInstantUploadResult()">Close</button>
|
||||
</div>
|
||||
|
||||
<footer class="footer">
|
||||
@ -434,6 +455,8 @@
|
||||
});
|
||||
});
|
||||
|
||||
let isFileModalOpen = false;
|
||||
|
||||
function openModal(modalId) {
|
||||
const modal = document.getElementById(modalId);
|
||||
const button = document.querySelector(`button[onclick="openModal('${modalId}')"]`);
|
||||
@ -458,6 +481,10 @@
|
||||
clearInterval(fadeIn);
|
||||
}
|
||||
}, 30);
|
||||
|
||||
if (modalId === 'fileModal') {
|
||||
isFileModalOpen = true;
|
||||
}
|
||||
}
|
||||
|
||||
function closeModal(modalId) {
|
||||
@ -477,11 +504,18 @@
|
||||
modal.style.display = "none";
|
||||
}
|
||||
}, 30);
|
||||
|
||||
if (modalId === 'fileModal') {
|
||||
isFileModalOpen = false;
|
||||
}
|
||||
}
|
||||
|
||||
window.onclick = function(event) {
|
||||
if (event.target.className === "modal") {
|
||||
event.target.style.display = "none";
|
||||
if (event.target.id === 'fileModal') {
|
||||
isFileModalOpen = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -714,7 +748,9 @@
|
||||
// Global drag and drop
|
||||
document.addEventListener('dragover', function(e) {
|
||||
e.preventDefault();
|
||||
if (!isFileModalOpen) {
|
||||
document.querySelector('.global-drop-area').style.display = 'flex';
|
||||
}
|
||||
});
|
||||
|
||||
document.addEventListener('dragleave', function(e) {
|
||||
@ -726,7 +762,7 @@
|
||||
document.addEventListener('drop', function(e) {
|
||||
e.preventDefault();
|
||||
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]);
|
||||
}
|
||||
});
|
||||
@ -746,6 +782,7 @@
|
||||
document.getElementById('directDownloadUrl').textContent = data.download_url;
|
||||
document.getElementById('normalUrl').href = data.url;
|
||||
document.getElementById('normalUrl').textContent = data.url;
|
||||
document.querySelector('.instant-upload-overlay').style.display = 'block';
|
||||
document.querySelector('.instant-upload-result').style.display = 'block';
|
||||
} else {
|
||||
alert('Error uploading file: ' + data.error);
|
||||
@ -758,6 +795,7 @@
|
||||
}
|
||||
|
||||
function closeInstantUploadResult() {
|
||||
document.querySelector('.instant-upload-overlay').style.display = 'none';
|
||||
document.querySelector('.instant-upload-result').style.display = 'none';
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user