3 comment::get_apub_comment,
5 get_apub_community_followers,
6 get_apub_community_http,
7 get_apub_community_inbox,
8 get_apub_community_outbox,
12 user::{get_apub_user_http, get_apub_user_inbox, get_apub_user_outbox},
14 inbox::{community_inbox::community_inbox, shared_inbox::shared_inbox, user_inbox::user_inbox},
15 APUB_JSON_CONTENT_TYPE,
18 use http_signature_normalization_actix::digest::middleware::VerifyDigest;
19 use lemmy_utils::settings::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))
35 // TODO: compatibility with previous lemmy versions, remove this later
36 .or(guard::Header("Content-Type", "application/json"));
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),
58 .route("/u/{user_name}", web::get().to(get_apub_user_http))
59 .route("/u/{user_name}/outbox", web::get().to(get_apub_user_outbox))
60 .route("/u/{user_name}/inbox", web::get().to(get_apub_user_inbox))
61 .route("/post/{post_id}", web::get().to(get_apub_post))
62 .route("/comment/{comment_id}", web::get().to(get_apub_comment))
63 .route("/activities/{type_}/{id}", web::get().to(get_activity)),
65 // Inboxes dont work with the header guard for some reason.
68 .wrap(digest_verifier)
69 .guard(header_guard_content_type)
70 .route("/c/{community_name}/inbox", web::post().to(community_inbox))
71 .route("/u/{user_name}/inbox", web::post().to(user_inbox))
72 .route("/inbox", web::post().to(shared_inbox)),