2 comment::get_apub_comment,
5 get_apub_community_followers,
6 get_apub_community_http,
7 get_apub_community_moderators,
8 get_apub_community_outbox,
11 person::{get_apub_person_http, get_apub_person_outbox, person_inbox},
16 use http_signature_normalization_actix::digest::middleware::VerifyDigest;
17 use lemmy_apub_lib::APUB_JSON_CONTENT_TYPE;
18 use lemmy_utils::settings::structs::Settings;
19 use sha2::{Digest, Sha256};
21 static APUB_JSON_CONTENT_TYPE_LONG: &str =
22 "application/ld+json; profile=\"https://www.w3.org/ns/activitystreams\"";
24 pub fn config(cfg: &mut web::ServiceConfig, settings: &Settings) {
25 if settings.federation.enabled {
26 println!("federation enabled, host is {}", settings.hostname);
27 let digest_verifier = VerifyDigest::new(Sha256::new());
29 let header_guard_accept = guard::Any(guard::Header("Accept", APUB_JSON_CONTENT_TYPE))
30 .or(guard::Header("Accept", APUB_JSON_CONTENT_TYPE_LONG));
31 let header_guard_content_type =
32 guard::Any(guard::Header("Content-Type", APUB_JSON_CONTENT_TYPE))
33 .or(guard::Header("Content-Type", APUB_JSON_CONTENT_TYPE_LONG));
38 .guard(header_guard_accept)
40 "/c/{community_name}",
41 web::get().to(get_apub_community_http),
44 "/c/{community_name}/followers",
45 web::get().to(get_apub_community_followers),
48 "/c/{community_name}/outbox",
49 web::get().to(get_apub_community_outbox),
52 "/c/{community_name}/moderators",
53 web::get().to(get_apub_community_moderators),
55 .route("/u/{user_name}", web::get().to(get_apub_person_http))
57 "/u/{user_name}/outbox",
58 web::get().to(get_apub_person_outbox),
60 .route("/post/{post_id}", web::get().to(get_apub_post))
61 .route("/comment/{comment_id}", web::get().to(get_apub_comment))
62 .route("/activities/{type_}/{id}", web::get().to(get_activity)),
64 // Inboxes dont work with the header guard for some reason.
67 .wrap(digest_verifier)
68 .guard(header_guard_content_type)
69 .route("/c/{community_name}/inbox", web::post().to(community_inbox))
70 .route("/u/{user_name}/inbox", web::post().to(person_inbox))
71 .route("/inbox", web::post().to(shared_inbox)),