diff options
author | Vika <vika@fireburn.ru> | 2025-04-09 23:06:25 +0300 |
---|---|---|
committer | Vika <vika@fireburn.ru> | 2025-04-09 23:31:57 +0300 |
commit | fa6e3fef17de18f80b5148b443d5f79f35d2dde2 (patch) | |
tree | 30d71a5fc640f4e5e24b57e6a78956feeb02d4d9 /src/micropub/mod.rs | |
parent | 6f47cd5b5ed220f3fcfe6566166f774ccd26d0c3 (diff) | |
download | kittybox-fa6e3fef17de18f80b5148b443d5f79f35d2dde2.tar.zst |
Replace tuple from `normalize_mf2` with `NormalizedPost` struct
This is a little bit more idiomatic. Perhaps I should consider doing the same with other tuples I return? Change-Id: I85f0e5dc76b8212ab6d192376d8c38ce2048ae85
Diffstat (limited to 'src/micropub/mod.rs')
-rw-r--r-- | src/micropub/mod.rs | 21 |
1 files changed, 11 insertions, 10 deletions
diff --git a/src/micropub/mod.rs b/src/micropub/mod.rs index 719fbf0..8505ae5 100644 --- a/src/micropub/mod.rs +++ b/src/micropub/mod.rs @@ -1,5 +1,6 @@ use std::collections::HashMap; use url::Url; +use util::NormalizedPost; use std::sync::Arc; use crate::database::{MicropubChannel, Storage, StorageError}; @@ -39,7 +40,7 @@ impl From<StorageError> for MicropubError { } } -mod util; +pub(crate) mod util; pub(crate) use util::normalize_mf2; #[derive(Debug)] @@ -591,8 +592,8 @@ pub(crate) async fn post<D: Storage + 'static, A: AuthBackend>( Err(err) => err.into_response(), }, Ok(PostBody::MF2(mf2)) => { - let (uid, mf2) = normalize_mf2(mf2, &user); - match _post(&user, uid, mf2, db, http, jobset).await { + let NormalizedPost { id, post } = normalize_mf2(mf2, &user); + match _post(&user, id, post, db, http, jobset).await { Ok(response) => response, Err(err) => err.into_response(), } @@ -764,7 +765,7 @@ impl MicropubQuery { mod tests { use std::sync::Arc; - use crate::{database::Storage, micropub::MicropubError}; + use crate::{database::Storage, micropub::{util::NormalizedPost, MicropubError}}; use bytes::Bytes; use futures::StreamExt; use serde_json::json; @@ -831,10 +832,10 @@ mod tests { scope: Scopes::new(vec![Scope::Profile]), iat: None, exp: None }; - let (uid, mf2) = super::normalize_mf2(post, &user); + let NormalizedPost { id, post } = super::normalize_mf2(post, &user); let err = super::_post( - &user, uid, mf2, db.clone(), + &user, id, post, db.clone(), reqwest_middleware::ClientWithMiddleware::new( reqwest::Client::new(), Box::default() @@ -868,10 +869,10 @@ mod tests { scope: Scopes::new(vec![Scope::Profile, Scope::Create, Scope::Update, Scope::Media]), iat: None, exp: None }; - let (uid, mf2) = super::normalize_mf2(post, &user); + let NormalizedPost { id, post } = super::normalize_mf2(post, &user); let err = super::_post( - &user, uid, mf2, db.clone(), + &user, id, post, db.clone(), reqwest_middleware::ClientWithMiddleware::new( reqwest::Client::new(), Box::default() @@ -903,10 +904,10 @@ mod tests { scope: Scopes::new(vec![Scope::Profile, Scope::Create]), iat: None, exp: None }; - let (uid, mf2) = super::normalize_mf2(post, &user); + let NormalizedPost { id, post } = super::normalize_mf2(post, &user); let res = super::_post( - &user, uid, mf2, db.clone(), + &user, id, post, db.clone(), reqwest_middleware::ClientWithMiddleware::new( reqwest::Client::new(), Box::default() |