Change apub IDs to be consistent with html urls

This commit is contained in:
Felix 2020-04-21 22:45:01 +02:00
parent 4e80543edb
commit 957e4a2611
3 changed files with 30 additions and 33 deletions

View file

@ -73,7 +73,7 @@ where
// TODO: this function should return a future // TODO: this function should return a future
let timeout = Duration::from_secs(60); let timeout = Duration::from_secs(60);
let text = Request::get(url.as_str()) let text = Request::get(url.as_str())
.header("Accept", APUB_JSON_CONTENT_TYPE) .header("Content-Type", APUB_JSON_CONTENT_TYPE)
.connect_timeout(timeout) .connect_timeout(timeout)
.timeout(timeout) .timeout(timeout)
.body(())? .body(())?

View file

@ -18,7 +18,7 @@ use url::Url;
type GroupExt = Ext<Ext<Group, ApActorProperties>, PublicKeyExtension>; type GroupExt = Ext<Ext<Group, ApActorProperties>, PublicKeyExtension>;
type PersonExt = Ext<Ext<Person, ApActorProperties>, PublicKeyExtension>; type PersonExt = Ext<Ext<Person, ApActorProperties>, PublicKeyExtension>;
static APUB_JSON_CONTENT_TYPE: &str = "application/activity+json"; pub static APUB_JSON_CONTENT_TYPE: &str = "application/activity+json";
pub enum EndpointType { pub enum EndpointType {
Community, Community,
@ -47,14 +47,14 @@ pub fn make_apub_endpoint(endpoint_type: EndpointType, name: &str) -> Url {
let point = match endpoint_type { let point = match endpoint_type {
EndpointType::Community => "c", EndpointType::Community => "c",
EndpointType::User => "u", EndpointType::User => "u",
EndpointType::Post => "p", EndpointType::Post => "post",
// TODO I have to change this else my update advanced_migrations crashes the // TODO I have to change this else my update advanced_migrations crashes the
// server if a comment exists. // server if a comment exists.
EndpointType::Comment => "comment", EndpointType::Comment => "comment",
}; };
Url::parse(&format!( Url::parse(&format!(
"{}://{}/federation/{}/{}", "{}://{}/{}/{}",
get_apub_protocol_string(), get_apub_protocol_string(),
Settings::get().hostname, Settings::get().hostname,
point, point,

View file

@ -1,38 +1,35 @@
use super::*; use super::*;
use crate::apub; use crate::apub::community::*;
use crate::apub::community_inbox::community_inbox;
use crate::apub::post::get_apub_post;
use crate::apub::user::*;
use crate::apub::user_inbox::user_inbox;
use crate::apub::APUB_JSON_CONTENT_TYPE;
pub fn config(cfg: &mut web::ServiceConfig) { pub fn config(cfg: &mut web::ServiceConfig) {
if Settings::get().federation.enabled { if Settings::get().federation.enabled {
println!("federation enabled, host is {}", Settings::get().hostname); println!("federation enabled, host is {}", Settings::get().hostname);
cfg cfg
// TODO: check the user/community params for these .service(
web::scope("/")
.guard(guard::Header("Content-Type", APUB_JSON_CONTENT_TYPE))
.route( .route(
"/federation/c/{community_name}/inbox", "/c/{community_name}",
web::post().to(apub::community_inbox::community_inbox), web::get().to(get_apub_community_http),
) )
.route( .route(
"/federation/u/{user_name}/inbox", "/c/{community_name}/followers",
web::post().to(apub::user_inbox::user_inbox), web::get().to(get_apub_community_followers),
) )
.route( .route(
"/federation/c/{community_name}", "/c/{community_name}/outbox",
web::get().to(apub::community::get_apub_community_http), web::get().to(get_apub_community_outbox),
) )
.route( .route("/u/{user_name}", web::get().to(get_apub_user))
"/federation/c/{community_name}/followers", .route("/post/{post_id}", web::get().to(get_apub_post)),
web::get().to(apub::community::get_apub_community_followers),
) )
.route( // Inboxes dont work with the header guard for some reason.
"/federation/c/{community_name}/outbox", .route("/c/{community_name}/inbox", web::post().to(community_inbox))
web::get().to(apub::community::get_apub_community_outbox), .route("/u/{user_name}/inbox", web::post().to(user_inbox));
)
.route(
"/federation/u/{user_name}",
web::get().to(apub::user::get_apub_user),
)
.route(
"/federation/p/{post_id}",
web::get().to(apub::post::get_apub_post),
);
} }
} }