Skip to content

Commit

Permalink
[feat]diagnostic messages
Browse files Browse the repository at this point in the history
  • Loading branch information
CutestNekoAqua committed Apr 18, 2024
1 parent 775c119 commit 98732a5
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 3 deletions.
1 change: 1 addition & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ async fn main() -> actix_web::Result<(), anyhow::Error> {
let user = entities::user::ActiveModel {
id: Set(ap_id.into()),
username: Set(username),
name: Set("Test account <3".to_string()),
inbox: Set(inbox.to_string()),
public_key: Set(keypair.public_key.clone()),
private_key: Set(Some(keypair.private_key.clone())),
Expand Down
20 changes: 18 additions & 2 deletions src/objects/person.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ use activitypub_federation::{
use chrono::{prelude, DateTime, Utc};
use sea_orm::{ActiveModelTrait, ColumnTrait, EntityTrait, QueryFilter, Set};
use serde::{Deserialize, Serialize};
use tracing::info;
use std::fmt::Debug;
use url::Url;

Expand Down Expand Up @@ -64,6 +65,9 @@ pub struct Person {
#[serde(rename = "type")]
kind: PersonType,
preferred_username: String,
name: String,
summary: Option<String>,
url: Url,
id: ObjectId<user::Model>,
inbox: Url,
public_key: PublicKey,
Expand Down Expand Up @@ -97,6 +101,9 @@ impl Object for user::Model {
id: Url::parse(&self.id).unwrap().into(),
inbox: Url::parse(&self.inbox).unwrap(),
public_key: self.public_key(),
name: self.name.clone(),
summary: self.summary.clone(),
url: Url::parse(&self.url).unwrap(),
})
}

Expand All @@ -116,13 +123,22 @@ impl Object for user::Model {
let model = user::ActiveModel {
id: Set(json.id.to_string()),
username: Set(json.preferred_username),
name: Set(json.name),
inbox: Set(json.inbox.to_string()),
public_key: Set(json.public_key.public_key_pem),
local: Set(false),
summary: Set(json.summary),
url: Set(json.url.to_string()),
..Default::default()
};
let model = model.insert(_data.database_connection.as_ref()).await?;
Ok(model)
let model = model.insert(_data.database_connection.as_ref()).await;
if let Err(err) = model {
eprintln!("Error inserting user: {:?}", err);
Err(err.into())
} else {
info!("User inserted: {:?}", model.as_ref().unwrap());
Ok(model.unwrap())
}
}
}

Expand Down
11 changes: 10 additions & 1 deletion src/objects/post.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ use activitypub_federation::{
use activitystreams_kinds::link::MentionType;
use sea_orm::{ActiveModelTrait, Set};
use serde::{Deserialize, Serialize};
use tracing::info;
use url::Url;

#[derive(Clone, Debug, Serialize, Deserialize)]
Expand Down Expand Up @@ -88,7 +89,15 @@ impl Object for post::Model {
};
let post = post
.insert(data.app_data().database_connection.clone().as_ref())
.await?;
.await;

if let Err(err) = post {
eprintln!("Error inserting post: {:?}", err);
return Err(err.into());
}
info!("Post inserted: {:?}", post.as_ref().unwrap());

let post = post.unwrap();

let mention = Mention {
href: Url::parse(&creator.id)?,
Expand Down

0 comments on commit 98732a5

Please sign in to comment.