fix
This commit is contained in:
parent
bff0567c27
commit
b6e461a51b
2 changed files with 6 additions and 3 deletions
|
|
@ -19,7 +19,7 @@ pub struct DbPost {
|
||||||
|
|
||||||
impl DbPost {
|
impl DbPost {
|
||||||
pub fn new(text: String, creator: ObjectId<DbUser>) -> Result<DbPost, Error> {
|
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 {
|
Ok(DbPost {
|
||||||
text,
|
text,
|
||||||
ap_id,
|
ap_id,
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,8 @@
|
||||||
|
use std::str::FromStr;
|
||||||
|
|
||||||
|
use activitypub_federation::url::Url;
|
||||||
use rand::{distributions::Alphanumeric, thread_rng, Rng};
|
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
|
/// 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).
|
/// 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)
|
.take(7)
|
||||||
.map(char::from)
|
.map(char::from)
|
||||||
.collect();
|
.collect();
|
||||||
Url::parse(&format!("http://{}/objects/{}", domain, id))
|
Url::from_str(&format!("http://{}/objects/{}", domain, id))
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue