A human-friendly DSL for ATProto Lexicons
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Add hash to .lexicon-cache.toml

+18 -2
+1
Cargo.lock
··· 1180 1180 "reqwest", 1181 1181 "serde", 1182 1182 "serde_json", 1183 + "sha2", 1183 1184 "thiserror 2.0.17", 1184 1185 "toml", 1185 1186 ]
+1
mlf-cli/Cargo.toml
··· 23 23 reqwest = { version = "0.12", features = ["blocking", "json"] } 24 24 chrono = { version = "0.4", features = ["serde"] } 25 25 hickory-resolver = "0.24" 26 + sha2 = "0.10" 26 27 27 28 # Optional code generator plugins 28 29 mlf-codegen-typescript = { path = "../codegen-plugins/mlf-codegen-typescript", optional = true }
+16 -2
mlf-cli/src/fetch.rs
··· 4 4 use hickory_resolver::Resolver; 5 5 use miette::Diagnostic; 6 6 use serde::{Deserialize, Serialize}; 7 + use sha2::{Digest, Sha256}; 7 8 use std::collections::HashMap; 8 9 use std::path::Path; 9 10 use thiserror::Error; ··· 62 63 pub nsid: String, 63 64 pub fetched_at: DateTime<Utc>, 64 65 pub did: String, 66 + #[serde(default)] 67 + pub hash: String, 65 68 } 66 69 67 70 impl LexiconCache { ··· 83 86 Ok(()) 84 87 } 85 88 86 - pub fn add_entry(&mut self, nsid: String, did: String) { 89 + pub fn add_entry(&mut self, nsid: String, did: String, hash: String) { 87 90 self.lexicons.insert( 88 91 nsid.clone(), 89 92 CacheEntry { 90 93 nsid, 91 94 fetched_at: Utc::now(), 92 95 did, 96 + hash, 93 97 }, 94 98 ); 95 99 } ··· 295 299 296 300 std::fs::write(&mlf_path, mlf_content)?; 297 301 println!(" → Converted to MLF at {}", mlf_path.display()); 302 + 303 + // Calculate hash of JSON content 304 + let hash = calculate_hash(&json_str); 298 305 299 306 // Update cache 300 - cache.add_entry(record_nsid.clone(), did.clone()); 307 + cache.add_entry(record_nsid.clone(), did.clone(), hash); 301 308 } 302 309 303 310 // Save cache ··· 459 466 record.uri 460 467 ))) 461 468 } 469 + 470 + /// Calculate SHA-256 hash of content 471 + fn calculate_hash(content: &str) -> String { 472 + let mut hasher = Sha256::new(); 473 + hasher.update(content.as_bytes()); 474 + format!("{:x}", hasher.finalize()) 475 + }