diff options
author | clarkzjw <[email protected]> | 2023-07-26 12:37:38 -0700 |
---|---|---|
committer | clarkzjw <[email protected]> | 2023-07-26 12:37:38 -0700 |
commit | af2f09ea4cbb97d3ee91e30bb58e85508989d63a (patch) | |
tree | 671ead9c450a0abf71efc00ba1f2966ae6e60e02 /fedi/live_federation/utils.rs | |
parent | f847de64eb8f724fa512801b43a26522afff61ae (diff) | |
download | photo-af2f09ea4cbb97d3ee91e30bb58e85508989d63a.tar.gz |
add example from https://github.com/LemmyNet/activitypub-federation-rust
Diffstat (limited to 'fedi/live_federation/utils.rs')
-rw-r--r-- | fedi/live_federation/utils.rs | 13 |
1 files changed, 13 insertions, 0 deletions
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 @@ | |||
1 | use rand::{distributions::Alphanumeric, thread_rng, Rng}; | ||
2 | use url::{ParseError, Url}; | ||
3 | |||
4 | /// Just generate random url as object id. In a real project, you probably want to use | ||
5 | /// an url which contains the database id for easy retrieval (or store the random id in db). | ||
6 | pub fn generate_object_id(domain: &str) -> Result<Url, ParseError> { | ||
7 | let id: String = thread_rng() | ||
8 | .sample_iter(&Alphanumeric) | ||
9 | .take(7) | ||
10 | .map(char::from) | ||
11 | .collect(); | ||
12 | Url::parse(&format!("https://{}/objects/{}", domain, id)) | ||
13 | } | ||