activitypub/src/utils.rs

19 lines
730 B
Rust
Raw Normal View History

2024-04-09 19:48:18 +02:00
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<Url, ParseError> {
let id: String = thread_rng()
.sample_iter(&Alphanumeric)
.take(7)
.map(char::from)
.collect();
Url::parse(&format!("https://{}/objects/{}", domain, id))
}
/// Generate a follow accept id
pub fn generate_follow_accept_id(domain: &str, db_id: i32) -> Result<Url, ParseError> {
Url::parse(&format!("https://{}/activities/follow/{}", domain, db_id))
}