From: Felix Date: Fri, 17 Apr 2020 14:55:28 +0000 (+0200) Subject: Some code cleanup and better logging X-Git-Url: http://these/git/%7B%60https:/readmes/static/%7B%60/feeds/%7BimageUploadUrl%7D?a=commitdiff_plain;h=8908c8b1840f64f0bc82e37437703afed419f3f9;p=lemmy.git Some code cleanup and better logging --- diff --git a/server/src/apub/activities.rs b/server/src/apub/activities.rs index 2e35400d..8885f555 100644 --- a/server/src/apub/activities.rs +++ b/server/src/apub/activities.rs @@ -11,6 +11,7 @@ use diesel::PgConnection; use failure::Error; use failure::_core::fmt::Debug; use isahc::prelude::*; +use log::debug; use serde::Serialize; fn populate_object_props( @@ -34,14 +35,14 @@ where A: Serialize + Debug, { let json = serde_json::to_string(&activity)?; - println!("sending data {}", json); + debug!("Sending activitypub activity {}", json); for t in to { - println!("to: {}", t); + debug!("Sending activity to: {}", t); let res = Request::post(t) .header("Content-Type", "application/json") .body(json.to_owned())? .send()?; - dbg!(res); + debug!("Result for activity send: {:?}", res); } Ok(()) } diff --git a/server/src/apub/community_inbox.rs b/server/src/apub/community_inbox.rs index 0fe3fd70..caadecf1 100644 --- a/server/src/apub/community_inbox.rs +++ b/server/src/apub/community_inbox.rs @@ -7,28 +7,38 @@ use actix_web::{web, HttpResponse}; use diesel::r2d2::{ConnectionManager, Pool}; use diesel::PgConnection; use failure::Error; +use log::debug; +use serde::Deserialize; use url::Url; #[serde(untagged)] -#[derive(serde::Deserialize)] +#[derive(Deserialize, Debug)] pub enum CommunityAcceptedObjects { Follow(Follow), } +#[derive(Deserialize)] +pub struct Params { + community_name: String, +} + pub async fn community_inbox( input: web::Json, + params: web::Query, db: web::Data>>, ) -> Result { let input = input.into_inner(); let conn = &db.get().unwrap(); + debug!( + "Community {} received activity {:?}", + ¶ms.community_name, &input + ); match input { CommunityAcceptedObjects::Follow(f) => handle_follow(&f, conn), } } fn handle_follow(follow: &Follow, conn: &PgConnection) -> Result { - println!("received follow: {:?}", &follow); - // TODO: make sure this is a local community let community_uri = follow .follow_props @@ -42,7 +52,6 @@ fn handle_follow(follow: &Follow, conn: &PgConnection) -> Result, + params: web::Query, db: web::Data>>, ) -> Result { let input = input.into_inner(); let conn = &db.get().unwrap(); + debug!("User {} received activity: {:?}", ¶ms.user_name, &input); + match input { UserAcceptedObjects::Create(c) => handle_create(&c, conn), UserAcceptedObjects::Update(u) => handle_update(&u, conn), @@ -57,8 +67,8 @@ fn handle_update(update: &Update, conn: &PgConnection) -> Result Result { - println!("received accept: {:?}", &accept); +fn handle_accept(_accept: &Accept, _conn: &PgConnection) -> Result { + // TODO: make sure that we actually requested a follow // TODO: at this point, indicate to the user that they are following the community Ok(HttpResponse::Ok().finish()) } diff --git a/server/src/routes/federation.rs b/server/src/routes/federation.rs index ef7ba56f..d80759c3 100644 --- a/server/src/routes/federation.rs +++ b/server/src/routes/federation.rs @@ -8,11 +8,11 @@ pub fn config(cfg: &mut web::ServiceConfig) { cfg // TODO: check the user/community params for these .route( - "/federation/c/{_}/inbox", + "/federation/c/{community_name}/inbox", web::post().to(apub::community_inbox::community_inbox), ) .route( - "/federation/u/{_}/inbox", + "/federation/u/{user_name}/inbox", web::post().to(apub::user_inbox::user_inbox), ) .route(