2 comment::get_apub_comment,
5 get_apub_community_followers,
6 get_apub_community_http,
7 get_apub_community_inbox,
8 get_apub_community_moderators,
9 get_apub_community_outbox,
12 person::{get_apub_person_http, get_apub_person_inbox, get_apub_person_outbox, person_inbox},
17 use http_signature_normalization_actix::digest::middleware::VerifyDigest;
18 use lemmy_apub::APUB_JSON_CONTENT_TYPE;
19 use lemmy_utils::settings::structs::Settings;
20 use sha2::{Digest, Sha256};
22 static APUB_JSON_CONTENT_TYPE_LONG: &str =
23 "application/ld+json; profile=\"https://www.w3.org/ns/activitystreams\"";
25 pub fn config(cfg: &mut web::ServiceConfig) {
26 if Settings::get().federation().enabled {
27 println!("federation enabled, host is {}", Settings::get().hostname());
28 let digest_verifier = VerifyDigest::new(Sha256::new());
30 let header_guard_accept = guard::Any(guard::Header("Accept", APUB_JSON_CONTENT_TYPE))
31 .or(guard::Header("Accept", APUB_JSON_CONTENT_TYPE_LONG));
32 let header_guard_content_type =
33 guard::Any(guard::Header("Content-Type", APUB_JSON_CONTENT_TYPE))
34 .or(guard::Header("Content-Type", APUB_JSON_CONTENT_TYPE_LONG));
39 .guard(header_guard_accept)
41 "/c/{community_name}",
42 web::get().to(get_apub_community_http),
45 "/c/{community_name}/followers",
46 web::get().to(get_apub_community_followers),
49 "/c/{community_name}/outbox",
50 web::get().to(get_apub_community_outbox),
53 "/c/{community_name}/inbox",
54 web::get().to(get_apub_community_inbox),
57 "/c/{community_name}/moderators",
58 web::get().to(get_apub_community_moderators),
60 .route("/u/{user_name}", web::get().to(get_apub_person_http))
62 "/u/{user_name}/outbox",
63 web::get().to(get_apub_person_outbox),
65 .route("/u/{user_name}/inbox", web::get().to(get_apub_person_inbox))
66 .route("/post/{post_id}", web::get().to(get_apub_post))
67 .route("/comment/{comment_id}", web::get().to(get_apub_comment))
68 .route("/activities/{type_}/{id}", web::get().to(get_activity)),
70 // Inboxes dont work with the header guard for some reason.
73 .wrap(digest_verifier)
74 .guard(header_guard_content_type)
75 .route("/c/{community_name}/inbox", web::post().to(community_inbox))
76 .route("/u/{user_name}/inbox", web::post().to(person_inbox))
77 .route("/inbox", web::post().to(shared_inbox)),