feat: enhance upload handling and logging improvements

This commit is contained in:
2026-01-16 15:17:57 +01:00
parent e0d1f263dd
commit c7c5c5f135
4 changed files with 21 additions and 7 deletions

View File

@@ -62,6 +62,7 @@
<script>
let currentContentData = null;
let uploadCompleted = false;
const fileInput = document.getElementById("fileInput");
const uploadZone = document.getElementById("uploadZone");
const uploadContainer = document.querySelector(".upload-container");
@@ -165,6 +166,9 @@
return;
}
// Mark upload as completed to prevent further pastes
uploadCompleted = true;
// Hide duration controls and buttons
document.querySelector('label[for="durationSlider"]').style.display =
"none";
@@ -220,6 +224,7 @@
// Reset to initial state
resetBtn.addEventListener("click", function () {
currentContentData = null;
uploadCompleted = false;
uploadZone.innerHTML =
"<p>Click to select file, paste image data, or drag & drop</p>";
uploadContainer.style.height = "180px";
@@ -302,6 +307,7 @@
// Open file picker on container click (ONLY IF EMPTY)
uploadContainer.addEventListener("click", function (e) {
if (
!uploadCompleted &&
uploadContainer.style.pointerEvents !== "none" &&
!uploadZone.querySelector(".text-content") &&
!uploadZone.querySelector("img")
@@ -311,6 +317,7 @@
});
fileInput.addEventListener("change", function (e) {
if (uploadCompleted) return;
const file = e.target.files[0];
if (file) {
const reader = new FileReader();
@@ -323,6 +330,10 @@
// Handle paste from clipboard
uploadZone.addEventListener("paste", function (e) {
if (uploadCompleted) {
e.preventDefault();
return;
}
e.preventDefault();
const items = e.clipboardData.items;
@@ -350,6 +361,7 @@
function handleDrop(e) {
e.preventDefault();
if (uploadCompleted) return;
const file = e.dataTransfer.files[0];
if (file && file.type.startsWith("image/")) {
const reader = new FileReader();
@@ -436,4 +448,4 @@
</script>
</body>
</html>
</html>

View File

@@ -1,4 +1,3 @@
use actix_web::http::header;
use actix_web::{HttpRequest, HttpResponse, get, post, web};
use base64::{Engine, engine::general_purpose};

View File

@@ -111,8 +111,7 @@ impl AssetStorage {
}
pub async fn add_asset(&self, asset: Asset) {
print!("[{}] Adding asset: {}", chrono::Local::now().to_rfc3339(), asset.id());
println!("[{}] Adding asset: {}", chrono::Local::now().to_rfc3339(), asset.id());
self.assets.lock().await.push(asset);
self.show_assets().await;
}
@@ -156,7 +155,8 @@ impl AssetStorage {
pub async fn show_assets(&self) {
for asset in self.assets.lock().await.iter() {
println!(
"Asset ID: {}, Expires At: {}, MIME: {}, Size: {} bytes",
"[{}] Asset ID: {}, Expires At: {}, Mime: {}, Size: {} bytes",
chrono::Local::now().to_rfc3339(),
asset.id(),
asset.expires_at(),
asset.mime(),
@@ -192,11 +192,15 @@ impl RateLimiter {
entry.push(asset_exp_time);
(true, None)
} else {
println!(
"[{}] Rate limit exceeded for IP: {}",
chrono::Local::now().to_rfc3339(),
client_ip
);
let first_to_expire = entry.iter().min().copied().unwrap();
let retry_after_ms = (first_to_expire - now).max(1);
(false, Some(retry_after_ms))
};
println!("{:?}", clients);
ret_val
}

View File

@@ -76,7 +76,6 @@ async fn view_asset(req: HttpRequest) -> actix_web::Result<NamedFile> {
#[route("/{tail:.*}", method = "GET", method = "POST")]
async fn catch_all(req: HttpRequest, _payload: Option<web::Json<Value>>) -> actix_web::Result<NamedFile> {
println!("Catch-all route triggered for path: {}", req.uri().path());
let response = match req.uri().path() {
path if STATIC_PAGES.contains(&path[1..].into()) => {
let file_path = HTML_DIR.to_string() + path;