This commit is contained in:
Felix Ableitner 2024-09-12 10:10:18 +02:00
parent bff0567c27
commit b6e461a51b
2 changed files with 6 additions and 3 deletions

View file

@ -19,7 +19,7 @@ pub struct DbPost {
impl DbPost {
pub fn new(text: String, creator: ObjectId<DbUser>) -> Result<DbPost, Error> {
let ap_id = generate_object_id(creator.inner().domain())?.try_into()?;
let ap_id = generate_object_id(creator.inner().domain())?.into();
Ok(DbPost {
text,
ap_id,

View file

@ -1,5 +1,8 @@
use std::str::FromStr;
use activitypub_federation::url::Url;
use rand::{distributions::Alphanumeric, thread_rng, Rng};
use url::{ParseError, Url};
use url::ParseError;
/// 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).
@ -9,5 +12,5 @@ pub fn generate_object_id(domain: &str) -> Result<Url, ParseError> {
.take(7)
.map(char::from)
.collect();
Url::parse(&format!("http://{}/objects/{}", domain, id))
Url::from_str(&format!("http://{}/objects/{}", domain, id))
}