mirror of
https://github.com/versia-pub/activitypub.git
synced 2025-12-06 06:38:20 +01:00
fmt: codebase
This commit is contained in:
parent
12dc5e89d0
commit
b666d339f2
|
|
@ -171,7 +171,6 @@ async fn save_follow(
|
||||||
}
|
}
|
||||||
// modify db entry
|
// modify db entry
|
||||||
let res = prelude::FollowRelation::update(query.unwrap());
|
let res = prelude::FollowRelation::update(query.unwrap());
|
||||||
|
|
||||||
|
|
||||||
Ok(model)
|
Ok(model)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -88,8 +88,6 @@ async fn lysand_inbox(
|
||||||
body: web::Bytes,
|
body: web::Bytes,
|
||||||
state: web::Data<State>,
|
state: web::Data<State>,
|
||||||
) -> actix_web::Result<HttpResponse, error::Error> {
|
) -> actix_web::Result<HttpResponse, error::Error> {
|
||||||
|
|
||||||
|
|
||||||
Ok(HttpResponse::Created().finish())
|
Ok(HttpResponse::Created().finish())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -212,13 +210,16 @@ pub async fn lysand_url_to_user(url: Url) -> anyhow::Result<super::objects::User
|
||||||
} else {
|
} else {
|
||||||
target = ObjectId::<user::Model>::from(url)
|
target = ObjectId::<user::Model>::from(url)
|
||||||
.dereference(&data.to_request_data())
|
.dereference(&data.to_request_data())
|
||||||
.await.unwrap();
|
.await
|
||||||
|
.unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(lysand_user_from_db(target).await?)
|
Ok(lysand_user_from_db(target).await?)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn lysand_url_to_user_and_model(url: Url) -> anyhow::Result<(super::objects::User, user::Model)> {
|
pub async fn lysand_url_to_user_and_model(
|
||||||
|
url: Url,
|
||||||
|
) -> anyhow::Result<(super::objects::User, user::Model)> {
|
||||||
let db = DB.get().unwrap();
|
let db = DB.get().unwrap();
|
||||||
let data = FEDERATION_CONFIG.get().unwrap();
|
let data = FEDERATION_CONFIG.get().unwrap();
|
||||||
|
|
||||||
|
|
@ -232,8 +233,9 @@ pub async fn lysand_url_to_user_and_model(url: Url) -> anyhow::Result<(super::ob
|
||||||
} else {
|
} else {
|
||||||
target = ObjectId::<user::Model>::from(url)
|
target = ObjectId::<user::Model>::from(url)
|
||||||
.dereference(&data.to_request_data())
|
.dereference(&data.to_request_data())
|
||||||
.await.unwrap();
|
.await
|
||||||
|
.unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok((lysand_user_from_db(target.clone()).await?, target))
|
Ok((lysand_user_from_db(target.clone()).await?, target))
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,13 +1,27 @@
|
||||||
|
use crate::{
|
||||||
use activitypub_federation::{activity_sending::SendActivityTask, fetch::object_id::ObjectId, protocol::context::WithContext};
|
activities::follow::Follow,
|
||||||
|
entities::{
|
||||||
|
self, follow_relation,
|
||||||
|
prelude::{self, FollowRelation},
|
||||||
|
user,
|
||||||
|
},
|
||||||
|
utils::generate_follow_req_id,
|
||||||
|
DB, FEDERATION_CONFIG,
|
||||||
|
};
|
||||||
|
use activitypub_federation::{
|
||||||
|
activity_sending::SendActivityTask, fetch::object_id::ObjectId, protocol::context::WithContext,
|
||||||
|
};
|
||||||
use activitystreams_kinds::activity::FollowType;
|
use activitystreams_kinds::activity::FollowType;
|
||||||
use anyhow::Result;
|
use anyhow::Result;
|
||||||
use sea_orm::{ActiveModelTrait, ColumnTrait, EntityOrSelect, EntityTrait, QueryFilter, Set};
|
use sea_orm::{ActiveModelTrait, ColumnTrait, EntityOrSelect, EntityTrait, QueryFilter, Set};
|
||||||
use serde::Deserialize;
|
use serde::Deserialize;
|
||||||
use url::Url;
|
use url::Url;
|
||||||
use crate::{activities::follow::Follow, entities::{self, follow_relation, prelude::{self, FollowRelation}, user}, utils::generate_follow_req_id, DB, FEDERATION_CONFIG};
|
|
||||||
|
|
||||||
use super::{conversion::lysand_user_from_db, http::{lysand_url_to_user, lysand_url_to_user_and_model}, objects::LysandType};
|
use super::{
|
||||||
|
conversion::lysand_user_from_db,
|
||||||
|
http::{lysand_url_to_user, lysand_url_to_user_and_model},
|
||||||
|
objects::LysandType,
|
||||||
|
};
|
||||||
|
|
||||||
pub async fn inbox_entry(json: &str) -> Result<()> {
|
pub async fn inbox_entry(json: &str) -> Result<()> {
|
||||||
// Deserialize the JSON string into a dynamic value
|
// Deserialize the JSON string into a dynamic value
|
||||||
|
|
@ -19,27 +33,25 @@ pub async fn inbox_entry(json: &str) -> Result<()> {
|
||||||
match json_type.as_str() {
|
match json_type.as_str() {
|
||||||
Some("Note") => {
|
Some("Note") => {
|
||||||
let note: super::objects::Note = serde_json::from_str(json)?;
|
let note: super::objects::Note = serde_json::from_str(json)?;
|
||||||
|
|
||||||
}
|
}
|
||||||
Some("Patch") => {
|
Some("Patch") => {
|
||||||
let patch: super::objects::Patch = serde_json::from_str(json)?;
|
let patch: super::objects::Patch = serde_json::from_str(json)?;
|
||||||
|
|
||||||
}
|
}
|
||||||
Some("Follow") => {
|
Some("Follow") => {
|
||||||
let follow_req: super::objects::Follow = serde_json::from_str(json)?;
|
let follow_req: super::objects::Follow = serde_json::from_str(json)?;
|
||||||
|
|
||||||
}
|
}
|
||||||
Some("FollowAccept") => {
|
Some("FollowAccept") => {
|
||||||
let follow_accept: super::objects::FollowResult = serde_json::from_str(json)?;
|
let follow_accept: super::objects::FollowResult = serde_json::from_str(json)?;
|
||||||
|
|
||||||
}
|
}
|
||||||
Some("FollowReject") => {
|
Some("FollowReject") => {
|
||||||
let follow_rej: super::objects::FollowResult = serde_json::from_str(json)?;
|
let follow_rej: super::objects::FollowResult = serde_json::from_str(json)?;
|
||||||
|
|
||||||
}
|
}
|
||||||
// Add more cases for other types as needed
|
// Add more cases for other types as needed
|
||||||
_ => {
|
_ => {
|
||||||
return Err(anyhow::anyhow!("Unknown 'type' field in JSON, it is {}", json_type));
|
return Err(anyhow::anyhow!(
|
||||||
|
"Unknown 'type' field in JSON, it is {}",
|
||||||
|
json_type
|
||||||
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -57,20 +69,29 @@ async fn follow_request(follow: super::objects::Follow) -> Result<()> {
|
||||||
.one(db)
|
.one(db)
|
||||||
.await?;
|
.await?;
|
||||||
if query.is_some() {
|
if query.is_some() {
|
||||||
return Err(anyhow::anyhow!("User is already follow requesting / following the followee"));
|
return Err(anyhow::anyhow!(
|
||||||
|
"User is already follow requesting / following the followee"
|
||||||
|
));
|
||||||
}
|
}
|
||||||
let data = FEDERATION_CONFIG.get().unwrap();
|
let data = FEDERATION_CONFIG.get().unwrap();
|
||||||
let author = lysand_url_to_user_and_model(follow.author.into()).await?;
|
let author = lysand_url_to_user_and_model(follow.author.into()).await?;
|
||||||
let followee = lysand_url_to_user_and_model(follow.followee.into()).await?;
|
let followee = lysand_url_to_user_and_model(follow.followee.into()).await?;
|
||||||
let serial_ap_author = serde_json::from_str::<crate::objects::person::Person>(&(author.1.ap_json.clone()).unwrap())?;
|
let serial_ap_author = serde_json::from_str::<crate::objects::person::Person>(
|
||||||
let serial_ap_followee = serde_json::from_str::<crate::objects::person::Person>(&(followee.1.ap_json.clone()).unwrap())?;
|
&(author.1.ap_json.clone()).unwrap(),
|
||||||
|
)?;
|
||||||
|
let serial_ap_followee = serde_json::from_str::<crate::objects::person::Person>(
|
||||||
|
&(followee.1.ap_json.clone()).unwrap(),
|
||||||
|
)?;
|
||||||
|
|
||||||
let id = uuid::Uuid::now_v7().to_string();
|
let id = uuid::Uuid::now_v7().to_string();
|
||||||
|
|
||||||
let followee_object: ObjectId<user::Model> = serial_ap_followee.url.into();
|
let followee_object: ObjectId<user::Model> = serial_ap_followee.url.into();
|
||||||
let localuser_object: ObjectId<user::Model> = serial_ap_author.url.into();
|
let localuser_object: ObjectId<user::Model> = serial_ap_author.url.into();
|
||||||
|
|
||||||
println!("Sending follow request to {}", &followee.0.display_name.unwrap_or(followee.0.username));
|
println!(
|
||||||
|
"Sending follow request to {}",
|
||||||
|
&followee.0.display_name.unwrap_or(followee.0.username)
|
||||||
|
);
|
||||||
let create = Follow {
|
let create = Follow {
|
||||||
actor: localuser_object.clone(),
|
actor: localuser_object.clone(),
|
||||||
object: followee_object.clone(),
|
object: followee_object.clone(),
|
||||||
|
|
@ -106,4 +127,4 @@ async fn follow_request(follow: super::objects::Follow) -> Result<()> {
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
pub mod conversion;
|
pub mod conversion;
|
||||||
pub mod funcs;
|
pub mod funcs;
|
||||||
pub mod http;
|
pub mod http;
|
||||||
|
pub mod inbox;
|
||||||
pub mod objects;
|
pub mod objects;
|
||||||
pub mod superx;
|
pub mod superx;
|
||||||
pub mod test;
|
pub mod test;
|
||||||
pub mod inbox;
|
|
||||||
|
|
@ -289,7 +289,10 @@ async fn main() -> actix_web::Result<(), anyhow::Error> {
|
||||||
.service(follow_manually)
|
.service(follow_manually)
|
||||||
.route("/{user}", web::get().to(http_get_user))
|
.route("/{user}", web::get().to(http_get_user))
|
||||||
.route("/{user}/inbox", web::post().to(http_post_user_inbox))
|
.route("/{user}/inbox", web::post().to(http_post_user_inbox))
|
||||||
.route("/apbridge/{user}/inbox", web::post().to(http_post_user_inbox))
|
.route(
|
||||||
|
"/apbridge/{user}/inbox",
|
||||||
|
web::post().to(http_post_user_inbox),
|
||||||
|
)
|
||||||
.route("/.well-known/webfinger", web::get().to(webfinger))
|
.route("/.well-known/webfinger", web::get().to(webfinger))
|
||||||
.service(index)
|
.service(index)
|
||||||
.service(fetch_post)
|
.service(fetch_post)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue