3 comment::get_apub_comment,
6 get_apub_community_followers,
7 get_apub_community_http,
8 get_apub_community_inbox,
9 get_apub_community_moderators,
10 get_apub_community_outbox,
13 person::{get_apub_person_http, get_apub_person_inbox, get_apub_person_outbox, person_inbox},
17 APUB_JSON_CONTENT_TYPE,
20 use http_signature_normalization_actix::digest::middleware::VerifyDigest;
21 use lemmy_utils::settings::structs::Settings;
22 use sha2::{Digest, Sha256};
24 static APUB_JSON_CONTENT_TYPE_LONG: &str =
25 "application/ld+json; profile=\"https://www.w3.org/ns/activitystreams\"";
27 pub fn config(cfg: &mut web::ServiceConfig) {
28 if Settings::get().federation.enabled {
29 println!("federation enabled, host is {}", Settings::get().hostname);
30 let digest_verifier = VerifyDigest::new(Sha256::new());
32 let header_guard_accept = guard::Any(guard::Header("Accept", APUB_JSON_CONTENT_TYPE))
33 .or(guard::Header("Accept", APUB_JSON_CONTENT_TYPE_LONG));
34 let header_guard_content_type =
35 guard::Any(guard::Header("Content-Type", APUB_JSON_CONTENT_TYPE))
36 .or(guard::Header("Content-Type", APUB_JSON_CONTENT_TYPE_LONG));
41 .guard(header_guard_accept)
43 "/c/{community_name}",
44 web::get().to(get_apub_community_http),
47 "/c/{community_name}/followers",
48 web::get().to(get_apub_community_followers),
51 "/c/{community_name}/outbox",
52 web::get().to(get_apub_community_outbox),
55 "/c/{community_name}/inbox",
56 web::get().to(get_apub_community_inbox),
59 "/c/{community_name}/moderators",
60 web::get().to(get_apub_community_moderators),
62 .route("/u/{user_name}", web::get().to(get_apub_person_http))
64 "/u/{user_name}/outbox",
65 web::get().to(get_apub_person_outbox),
67 .route("/u/{user_name}/inbox", web::get().to(get_apub_person_inbox))
68 .route("/post/{post_id}", web::get().to(get_apub_post))
69 .route("/comment/{comment_id}", web::get().to(get_apub_comment))
70 .route("/activities/{type_}/{id}", web::get().to(get_activity)),
72 // Inboxes dont work with the header guard for some reason.
75 .wrap(digest_verifier)
76 .guard(header_guard_content_type)
77 .route("/c/{community_name}/inbox", web::post().to(community_inbox))
78 .route("/u/{user_name}/inbox", web::post().to(person_inbox))
79 .route("/inbox", web::post().to(shared_inbox)),