]> Untitled Git - lemmy.git/blobdiff - src/api_routes_http.rs
feat: re-added captcha checks (#3249)
[lemmy.git] / src / api_routes_http.rs
index 882efc8ce477e0d0952d75c5bef45f0e27c85393..375630a9243fc529c7227740e600746d3e7c2d39 100644 (file)
@@ -1,4 +1,3 @@
-use crate::api_routes_websocket::websocket;
 use actix_web::{guard, web, Error, HttpResponse, Result};
 use lemmy_api::Perform;
 use lemmy_api_common::{
@@ -31,6 +30,7 @@ use lemmy_api_common::{
     TransferCommunity,
   },
   context::LemmyContext,
+  custom_emoji::{CreateCustomEmoji, DeleteCustomEmoji, EditCustomEmoji},
   person::{
     AddAdmin,
     BanPerson,
@@ -85,6 +85,7 @@ use lemmy_api_common::{
     ApproveRegistrationApplication,
     CreateSite,
     EditSite,
+    GetFederatedInstances,
     GetModlog,
     GetSite,
     GetUnreadRegistrationApplicationCount,
@@ -97,7 +98,6 @@ use lemmy_api_common::{
     ResolveObject,
     Search,
   },
-  websocket::structs::{CommunityJoin, ModJoin, PostJoin, UserJoin},
 };
 use lemmy_api_crud::PerformCrud;
 use lemmy_apub::{api::PerformApub, SendActivity};
@@ -107,8 +107,6 @@ use serde::Deserialize;
 pub fn config(cfg: &mut web::ServiceConfig, rate_limit: &RateLimitCell) {
   cfg.service(
     web::scope("/api/v3")
-      // Websocket
-      .service(web::resource("/ws").to(websocket))
       // Site
       .service(
         web::scope("/site")
@@ -160,9 +158,12 @@ pub fn config(cfg: &mut web::ServiceConfig, rate_limit: &RateLimitCell) {
           )
           .route("/transfer", web::post().to(route_post::<TransferCommunity>))
           .route("/ban_user", web::post().to(route_post::<BanFromCommunity>))
-          .route("/mod", web::post().to(route_post::<AddModToCommunity>))
-          .route("/join", web::post().to(route_post::<CommunityJoin>))
-          .route("/mod/join", web::post().to(route_post::<ModJoin>)),
+          .route("/mod", web::post().to(route_post::<AddModToCommunity>)),
+      )
+      .service(
+        web::scope("/federated_instances")
+          .wrap(rate_limit.message())
+          .route("", web::get().to(route_get::<GetFederatedInstances>)),
       )
       // Post
       .service(
@@ -188,7 +189,6 @@ pub fn config(cfg: &mut web::ServiceConfig, rate_limit: &RateLimitCell) {
           .route("/list", web::get().to(route_get_apub::<GetPosts>))
           .route("/like", web::post().to(route_post::<CreatePostLike>))
           .route("/save", web::put().to(route_post::<SavePost>))
-          .route("/join", web::post().to(route_post::<PostJoin>))
           .route("/report", web::post().to(route_post::<CreatePostReport>))
           .route(
             "/report/resolve",
@@ -290,7 +290,6 @@ pub fn config(cfg: &mut web::ServiceConfig, rate_limit: &RateLimitCell) {
             web::post().to(route_post::<MarkPersonMentionAsRead>),
           )
           .route("/replies", web::get().to(route_get::<GetReplies>))
-          .route("/join", web::post().to(route_post::<UserJoin>))
           // Admin action. I don't like that it's in /user
           .route("/ban", web::post().to(route_post::<BanPerson>))
           .route("/banned", web::get().to(route_get::<GetBannedPersons>))
@@ -343,15 +342,24 @@ pub fn config(cfg: &mut web::ServiceConfig, rate_limit: &RateLimitCell) {
           .route(
             "/registration_application/approve",
             web::put().to(route_post::<ApproveRegistrationApplication>),
+          )
+          .service(
+            web::scope("/purge")
+              .route("/person", web::post().to(route_post::<PurgePerson>))
+              .route("/community", web::post().to(route_post::<PurgeCommunity>))
+              .route("/post", web::post().to(route_post::<PurgePost>))
+              .route("/comment", web::post().to(route_post::<PurgeComment>)),
           ),
       )
       .service(
-        web::scope("/admin/purge")
+        web::scope("/custom_emoji")
           .wrap(rate_limit.message())
-          .route("/person", web::post().to(route_post::<PurgePerson>))
-          .route("/community", web::post().to(route_post::<PurgeCommunity>))
-          .route("/post", web::post().to(route_post::<PurgePost>))
-          .route("/comment", web::post().to(route_post::<PurgeComment>)),
+          .route("", web::post().to(route_post_crud::<CreateCustomEmoji>))
+          .route("", web::put().to(route_post_crud::<EditCustomEmoji>))
+          .route(
+            "/delete",
+            web::post().to(route_post_crud::<DeleteCustomEmoji>),
+          ),
       ),
   );
 }
@@ -359,6 +367,7 @@ pub fn config(cfg: &mut web::ServiceConfig, rate_limit: &RateLimitCell) {
 async fn perform<'a, Data>(
   data: Data,
   context: web::Data<LemmyContext>,
+  apub_data: activitypub_federation::config::Data<LemmyContext>,
 ) -> Result<HttpResponse, Error>
 where
   Data: Perform
@@ -368,14 +377,15 @@ where
     + Send
     + 'static,
 {
-  let res = data.perform(&context, None).await?;
-  SendActivity::send_activity(&data, &res, &context).await?;
+  let res = data.perform(&context).await?;
+  SendActivity::send_activity(&data, &res, &apub_data).await?;
   Ok(HttpResponse::Ok().json(res))
 }
 
 async fn route_get<'a, Data>(
   data: web::Query<Data>,
   context: web::Data<LemmyContext>,
+  apub_data: activitypub_federation::config::Data<LemmyContext>,
 ) -> Result<HttpResponse, Error>
 where
   Data: Perform
@@ -385,12 +395,12 @@ where
     + Send
     + 'static,
 {
-  perform::<Data>(data.0, context).await
+  perform::<Data>(data.0, context, apub_data).await
 }
 
 async fn route_get_apub<'a, Data>(
   data: web::Query<Data>,
-  context: web::Data<LemmyContext>,
+  context: activitypub_federation::config::Data<LemmyContext>,
 ) -> Result<HttpResponse, Error>
 where
   Data: PerformApub
@@ -400,7 +410,7 @@ where
     + Send
     + 'static,
 {
-  let res = data.perform(&context, None).await?;
+  let res = data.perform(&context).await?;
   SendActivity::send_activity(&data.0, &res, &context).await?;
   Ok(HttpResponse::Ok().json(res))
 }
@@ -408,6 +418,7 @@ where
 async fn route_post<'a, Data>(
   data: web::Json<Data>,
   context: web::Data<LemmyContext>,
+  apub_data: activitypub_federation::config::Data<LemmyContext>,
 ) -> Result<HttpResponse, Error>
 where
   Data: Perform
@@ -417,12 +428,13 @@ where
     + Send
     + 'static,
 {
-  perform::<Data>(data.0, context).await
+  perform::<Data>(data.0, context, apub_data).await
 }
 
 async fn perform_crud<'a, Data>(
   data: Data,
   context: web::Data<LemmyContext>,
+  apub_data: activitypub_federation::config::Data<LemmyContext>,
 ) -> Result<HttpResponse, Error>
 where
   Data: PerformCrud
@@ -432,14 +444,15 @@ where
     + Send
     + 'static,
 {
-  let res = data.perform(&context, None).await?;
-  SendActivity::send_activity(&data, &res, &context).await?;
+  let res = data.perform(&context).await?;
+  SendActivity::send_activity(&data, &res, &apub_data).await?;
   Ok(HttpResponse::Ok().json(res))
 }
 
 async fn route_get_crud<'a, Data>(
   data: web::Query<Data>,
   context: web::Data<LemmyContext>,
+  apub_data: activitypub_federation::config::Data<LemmyContext>,
 ) -> Result<HttpResponse, Error>
 where
   Data: PerformCrud
@@ -449,12 +462,13 @@ where
     + Send
     + 'static,
 {
-  perform_crud::<Data>(data.0, context).await
+  perform_crud::<Data>(data.0, context, apub_data).await
 }
 
 async fn route_post_crud<'a, Data>(
   data: web::Json<Data>,
   context: web::Data<LemmyContext>,
+  apub_data: activitypub_federation::config::Data<LemmyContext>,
 ) -> Result<HttpResponse, Error>
 where
   Data: PerformCrud
@@ -464,5 +478,5 @@ where
     + Send
     + 'static,
 {
-  perform_crud::<Data>(data.0, context).await
+  perform_crud::<Data>(data.0, context, apub_data).await
 }