crier

RSS and Atom feed aggregator
Info | Log | Files | Refs | README

commit 7b2a220d645fc0c3ada372d5954c7eba7e8706ea
parent 1ee20288546a55a0757534d864c89b5ffd942d14
Author: lash <dev@holbrook.no>
Date:   Sun, 29 Sep 2024 02:32:21 +0100

Add deterministic guid param

Diffstat:
MCargo.lock | 8++++++++
MCargo.toml | 3+++
Mcrier-lib/Cargo.toml | 2+-
Mcrier-lib/src/lib.rs | 13++++++++++---
Msrc/main.rs | 22+++++++++++++++++++---
5 files changed, 41 insertions(+), 7 deletions(-)

diff --git a/Cargo.lock b/Cargo.lock @@ -163,6 +163,7 @@ dependencies = [ "crier", "env_logger", "log", + "uuid", ] [[package]] @@ -581,6 +582,12 @@ dependencies = [ ] [[package]] +name = "sha1_smol" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ae1a47186c03a32177042e55dbc5fd5aee900b8e0069a8d70fba96a9375cd012" + +[[package]] name = "strsim" version = "0.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -646,6 +653,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "81dfa00651efa65069b0b6b651f4aaa31ba9e3c3ce0137aaad053604ee7e0314" dependencies = [ "getrandom", + "sha1_smol", ] [[package]] diff --git a/Cargo.toml b/Cargo.toml @@ -13,6 +13,9 @@ crier = { path = "./crier-lib", features = ["fs"] } log = "^0.4" env_logger = "^0.9" +[dependencies.uuid] +version = "^1.9" +features = ["v4"] [patch.crates-io] #atom_syndication = { path = "/home/lash/src/contrib/atom_syndication" } diff --git a/crier-lib/Cargo.toml b/crier-lib/Cargo.toml @@ -23,7 +23,7 @@ env_logger = "^0.9" [dependencies.uuid] version = "^1.9" -features = ["v4"] +features = ["v4", "v5"] [dependencies.rss] version = "^2.0" diff --git a/crier-lib/src/lib.rs b/crier-lib/src/lib.rs @@ -6,8 +6,8 @@ use std::io::Write; use std::fmt::Debug; use std::io::BufWriter; use std::str::FromStr; - use log::error; +use uuid::Uuid; use rs_sha512::Sha512Hasher; use chrono::Local; @@ -23,6 +23,7 @@ use atom_syndication::Person; use atom_syndication::Generator; use itertools::Itertools; + pub mod io; pub mod mem; @@ -33,6 +34,8 @@ use meta::FeedMetadata; use mem::CacheWriter; use cache::Cache; +static NAMESPACE_URL_CRIER: &[u8] = b"defalsify.org/src/crier"; + #[derive(Debug)] pub enum Error { WriteError, @@ -49,6 +52,7 @@ pub struct Sequencer<'a> { limit: usize, default_cache: CacheWriter, //HashMap<String, Vec<u8>>, cache: Option<&'a mut dyn Cache>, + guuid: Uuid, } pub struct SequencerEntry { @@ -58,7 +62,8 @@ pub struct SequencerEntry { } impl<'a> Sequencer<'a> { - pub fn new() -> Sequencer<'a> { + pub fn new(guuid_value: Vec<u8>) -> Sequencer<'a> { + let namespace_crier = Uuid::new_v5(&Uuid::NAMESPACE_URL, NAMESPACE_URL_CRIER); let mut o = Sequencer { metadata: FeedMetadata::default(), items: HashMap::new(), @@ -67,6 +72,7 @@ impl<'a> Sequencer<'a> { item_keys: Vec::new(), default_cache: CacheWriter::new(), //HashMap::new(), cache: None, + guuid: Uuid::new_v5(&namespace_crier, guuid_value.as_ref()), }; #[cfg(test)] @@ -139,7 +145,8 @@ impl<'a> Sequencer<'a> { let mut entry: Entry; let mut entries: Vec<Entry>; let mut b: &str; - feed.set_id("urn:uuid:60a76c80-d399-11d9-b91C-0003939e0af6"); + let id: String = self.guuid.into(); + feed.set_id(id); feed.set_updated(Local::now().to_utc()); let g = Generator{ diff --git a/src/main.rs b/src/main.rs @@ -4,6 +4,8 @@ use std::process; use std::io::stdout; use std::str::from_utf8; +use uuid::Uuid; + use clap::Arg; use clap::App; @@ -17,19 +19,20 @@ use crier::mem::MemCache; use crier::io::fs::FsFeed; use crier::Error; - struct Config { urls: Vec<String>, author: String, title: String, + id: String, } impl Config { - fn new(title: String, author: String, urls: Vec<String>) -> Config { + fn new(id: String, title: String, author: String, urls: Vec<String>) -> Config { Config { urls: urls, title: title, author: author, + id: id, } } } @@ -57,6 +60,16 @@ fn parse() -> Config { .required(true) ); + // TODO: implement auto generate id when missing + o = o.arg( + Arg::with_name("id") + .long("id") + .short("i") + .value_name("Aggregated feed id uuid value") + .takes_value(true) + .required(true) + ); + o = o.arg(Arg::with_name("URLS") .multiple(true) .help("list of uris to merge")); @@ -64,6 +77,7 @@ fn parse() -> Config { let m = o.get_matches(); Config::new( + String::from(m.value_of("id").unwrap()), String::from(m.value_of("title").unwrap()), String::from(m.value_of("author").unwrap()), m.values_of("URLS").unwrap().map(|v| String::from(v)).collect()) @@ -110,7 +124,9 @@ fn process_entry(seq: &mut Sequencer, uri: String) -> Result<(), Error> { fn main() { let cfg = parse(); let mut cache = MemCache::new(); - let mut seq = Sequencer::new().with_cache(&mut cache); + + let id: Vec<u8> = cfg.id.into(); + let mut seq = Sequencer::new(id).with_cache(&mut cache); seq.set_title(cfg.title.as_str()); seq.set_author(cfg.author.as_str());