diff --git a/src/server.rs b/src/server.rs index 5be190c..2242eb9 100644 --- a/src/server.rs +++ b/src/server.rs @@ -799,8 +799,35 @@ async fn upload_file( let file_path = format!("{}/{}", user_dir, filename); - // Generate file_uuid locally (no external API dependency) - let file_uuid = uuid::Uuid::new_v4().to_string().replace('-', ""); + // Generate file_uuid based on file properties (path + filename + mac + mtime) + // Get MAC address + let mac_output = std::process::Command::new("ifconfig") + .arg("en0") + .output() + .map(|o| String::from_utf8_lossy(&o.stdout).to_string()) + .unwrap_or_default(); + + let mac = mac_output + .lines() + .find(|l| l.contains("ether")) + .and_then(|l| l.split_whitespace().nth(1)) + .unwrap_or("00:00:00:00:00:00"); + + // Get file mtime (milliseconds) + let mtime = std::fs::metadata(&file_path) + .ok() + .and_then(|m| m.modified().ok()) + .and_then(|t| t.duration_since(std::time::UNIX_EPOCH).ok()) + .map(|d| d.as_millis() as u64) + .unwrap_or(0); + + // Generate UUID: SHA256(path|filename|mac|mtime) + let input = format!("{}|{}|{}|{}", file_path, filename, mac, mtime); + let mut hasher = sha2::Sha256::new(); + hasher.update(input.as_bytes()); + let hash = hasher.finalize(); + let hex = format!("{:x}", hash); + let file_uuid = hex[0..32].to_string(); // Save to database (user-specific SQLite) let db_path = crate::filetree::FileTree::user_db_path(&user_id);