]> Untitled Git - lemmy.git/blob - crates/apub/src/http/routes.rs
add enable_federated_downvotes site option
[lemmy.git] / crates / apub / src / http / routes.rs
1 use crate::http::{
2   comment::get_apub_comment,
3   community::{
4     community_inbox,
5     get_apub_community_featured,
6     get_apub_community_followers,
7     get_apub_community_http,
8     get_apub_community_moderators,
9     get_apub_community_outbox,
10   },
11   get_activity,
12   person::{get_apub_person_http, get_apub_person_outbox, person_inbox},
13   post::get_apub_post,
14   shared_inbox,
15   site::{get_apub_site_http, get_apub_site_inbox, get_apub_site_outbox},
16 };
17 use actix_web::{
18   guard::{Guard, GuardContext},
19   http::{header, Method},
20   web,
21 };
22
23 pub fn config(cfg: &mut web::ServiceConfig) {
24   cfg
25     .route("/", web::get().to(get_apub_site_http))
26     .route("/site_outbox", web::get().to(get_apub_site_outbox))
27     .route(
28       "/c/{community_name}",
29       web::get().to(get_apub_community_http),
30     )
31     .route(
32       "/c/{community_name}/followers",
33       web::get().to(get_apub_community_followers),
34     )
35     .route(
36       "/c/{community_name}/outbox",
37       web::get().to(get_apub_community_outbox),
38     )
39     .route(
40       "/c/{community_name}/featured",
41       web::get().to(get_apub_community_featured),
42     )
43     .route(
44       "/c/{community_name}/moderators",
45       web::get().to(get_apub_community_moderators),
46     )
47     .route("/u/{user_name}", web::get().to(get_apub_person_http))
48     .route(
49       "/u/{user_name}/outbox",
50       web::get().to(get_apub_person_outbox),
51     )
52     .route("/post/{post_id}", web::get().to(get_apub_post))
53     .route("/comment/{comment_id}", web::get().to(get_apub_comment))
54     .route("/activities/{type_}/{id}", web::get().to(get_activity));
55
56   cfg.service(
57     web::scope("")
58       .guard(InboxRequestGuard)
59       .route("/c/{community_name}/inbox", web::post().to(community_inbox))
60       .route("/u/{user_name}/inbox", web::post().to(person_inbox))
61       .route("/inbox", web::post().to(shared_inbox))
62       .route("/site_inbox", web::post().to(get_apub_site_inbox)),
63   );
64 }
65
66 /// Without this, things like webfinger or RSS feeds stop working, as all requests seem to get
67 /// routed into the inbox service (because it covers the root path). So we filter out anything that
68 /// definitely can't be an inbox request (based on Accept header and request method).
69 struct InboxRequestGuard;
70
71 impl Guard for InboxRequestGuard {
72   fn check(&self, ctx: &GuardContext) -> bool {
73     if ctx.head().method != Method::POST {
74       return false;
75     }
76     if let Some(val) = ctx.head().headers.get(header::CONTENT_TYPE) {
77       return val.as_bytes().starts_with(b"application/");
78     }
79     false
80   }
81 }