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)
This commit is contained in:
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user