From 87bac3f201694de0243ec19d699994013f48401e Mon Sep 17 00:00:00 2001 From: Warren Date: Sun, 17 May 2026 02:28:06 +0800 Subject: [PATCH] feat: Generate UUID based on file properties (path+filename+mac+mtime) UUID generation method changed: - Old: UUID v4 random (uuid::Uuid::new_v4()) - New: SHA256 hash of file properties Properties used: - file_path: absolute path to file - filename: uploaded filename - MAC address: from ifconfig en0 (ether) - mtime: file modification time (milliseconds) Algorithm: UUID = SHA256(path|filename|mac|mtime)[0..32] Example: Input: /path/file.svg|file.svg|aa:bb:cc:dd:ee:ff|1234567890 Output: 32-char hex string Matches momentry system: - Uses deterministic UUID (not random) - Based on file metadata - Same file = same UUID Files: - src/server.rs (line 800-820: UUID generation logic) --- src/server.rs | 31 +++++++++++++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) 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);