From af2f09ea4cbb97d3ee91e30bb58e85508989d63a Mon Sep 17 00:00:00 2001 From: clarkzjw Date: Wed, 26 Jul 2023 12:37:38 -0700 Subject: add example from https://github.com/LemmyNet/activitypub-federation-rust --- fedi/live_federation/utils.rs | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 fedi/live_federation/utils.rs (limited to 'fedi/live_federation/utils.rs') diff --git a/fedi/live_federation/utils.rs b/fedi/live_federation/utils.rs new file mode 100644 index 0000000..0b2b098 --- /dev/null +++ b/fedi/live_federation/utils.rs @@ -0,0 +1,13 @@ +use rand::{distributions::Alphanumeric, thread_rng, Rng}; +use url::{ParseError, Url}; + +/// Just generate random url as object id. In a real project, you probably want to use +/// an url which contains the database id for easy retrieval (or store the random id in db). +pub fn generate_object_id(domain: &str) -> Result { + let id: String = thread_rng() + .sample_iter(&Alphanumeric) + .take(7) + .map(char::from) + .collect(); + Url::parse(&format!("https://{}/objects/{}", domain, id)) +} -- cgit v1.2.3