From 9072bb365ce79d0ba14faba4dc5243ae84676a8a Mon Sep 17 00:00:00 2001 From: Felix Ableitner Date: Wed, 20 Nov 2024 14:41:15 +0100 Subject: [PATCH 01/26] Reorganize api endpoints (fixes #2022) --- src/api_routes_http.rs | 50 +++++++++++++++++++----------------------- 1 file changed, 23 insertions(+), 27 deletions(-) diff --git a/src/api_routes_http.rs b/src/api_routes_http.rs index 2f431419c0..ac99828bd5 100644 --- a/src/api_routes_http.rs +++ b/src/api_routes_http.rs @@ -161,7 +161,7 @@ use lemmy_utils::rate_limit::RateLimitCell; pub fn config(cfg: &mut web::ServiceConfig, rate_limit: &RateLimitCell) { cfg.service( - web::scope("/api/v3") + web::scope("/api/v4") .route("/image_proxy", web::get().to(image_proxy)) // Site .service( @@ -295,74 +295,62 @@ pub fn config(cfg: &mut web::ServiceConfig, rate_limit: &RateLimitCell) { .service( // Account action, I don't like that it's in /user maybe /accounts // Handle /user/register separately to add the register() rate limiter - web::resource("/user/register") + web::resource("/account/register") .guard(guard::Post()) .wrap(rate_limit.register()) .route(web::post().to(register)), ) // User .service( - // Handle /user/login separately to add the register() rate limiter + // Handle /account/login separately to add the register() rate limiter // TODO: pretty annoying way to apply rate limits for register and login, we should // group them under a common path so that rate limit is only applied once (eg under // /account). - web::resource("/user/login") + web::resource("/account/login") .guard(guard::Post()) .wrap(rate_limit.register()) .route(web::post().to(login)), ) .service( - web::resource("/user/password_reset") + web::resource("/account/password_reset") .wrap(rate_limit.register()) .route(web::post().to(reset_password)), ) .service( // Handle captcha separately - web::resource("/user/get_captcha") + web::resource("/account/get_captcha") .wrap(rate_limit.post()) .route(web::get().to(get_captcha)), ) .service( - web::resource("/user/export_settings") + web::resource("/account/export_settings") .wrap(rate_limit.import_user_settings()) .route(web::get().to(export_settings)), ) .service( - web::resource("/user/import_settings") + web::resource("/account/import_settings") .wrap(rate_limit.import_user_settings()) .route(web::post().to(import_settings)), ) - // TODO, all the current account related actions under /user need to get moved here eventually .service( web::scope("/account") .wrap(rate_limit.message()) - .route("/list_media", web::get().to(list_media)), - ) - // User actions - .service( - web::scope("/user") - .wrap(rate_limit.message()) - .route("", web::get().to(read_person)) + .route("/list_media", web::get().to(list_media)) .route("/mention", web::get().to(list_mentions)) - .route( - "/mention/mark_as_read", - web::post().to(mark_person_mention_as_read), - ) .route("/replies", web::get().to(list_replies)) - // Admin action. I don't like that it's in /user - .route("/ban", web::post().to(ban_from_site)) - .route("/banned", web::get().to(list_banned_users)) .route("/block", web::post().to(block_person)) - // TODO Account actions. I don't like that they're in /user maybe /accounts .route("/logout", web::post().to(logout)) .route("/delete_account", web::post().to(delete_account)) .route( "/password_change", web::post().to(change_password_after_reset), ) - // TODO mark_all_as_read feels off being in this section as well .route( - "/mark_all_as_read", + "/mention/mark_as_read", + web::post().to(mark_person_mention_as_read), + ) + .route( + "/mention/mark_all_as_read", web::post().to(mark_all_notifications_read), ) .route("/save_user_settings", web::put().to(save_user_settings)) @@ -376,6 +364,12 @@ pub fn config(cfg: &mut web::ServiceConfig, rate_limit: &RateLimitCell) { .route("/list_logins", web::get().to(list_logins)) .route("/validate_auth", web::get().to(validate_auth)), ) + // User actions + .service( + web::scope("/user") + .wrap(rate_limit.message()) + .route("", web::get().to(read_person)), + ) // Admin Actions .service( web::scope("/admin") @@ -412,7 +406,9 @@ pub fn config(cfg: &mut web::ServiceConfig, rate_limit: &RateLimitCell) { .route("", web::put().to(update_tagline)) .route("/delete", web::post().to(delete_tagline)) .route("/list", web::get().to(list_taglines)), - ), + ) + .route("/ban", web::post().to(ban_from_site)) + .route("/banned", web::get().to(list_banned_users)), ) .service( web::scope("/custom_emoji") From 48e817bacc246515d8d773e5310ee94d9ad561d4 Mon Sep 17 00:00:00 2001 From: Felix Ableitner Date: Thu, 21 Nov 2024 12:09:37 +0100 Subject: [PATCH 02/26] scopes --- src/api_routes_http.rs | 57 ++++++++++++------------------------------ 1 file changed, 16 insertions(+), 41 deletions(-) diff --git a/src/api_routes_http.rs b/src/api_routes_http.rs index ac99828bd5..32080c6702 100644 --- a/src/api_routes_http.rs +++ b/src/api_routes_http.rs @@ -293,43 +293,25 @@ pub fn config(cfg: &mut web::ServiceConfig, rate_limit: &RateLimitCell) { ) // User .service( - // Account action, I don't like that it's in /user maybe /accounts - // Handle /user/register separately to add the register() rate limiter - web::resource("/account/register") + web::scope("/account/auth") .guard(guard::Post()) .wrap(rate_limit.register()) - .route(web::post().to(register)), - ) - // User - .service( - // Handle /account/login separately to add the register() rate limiter - // TODO: pretty annoying way to apply rate limits for register and login, we should - // group them under a common path so that rate limit is only applied once (eg under - // /account). - web::resource("/account/login") - .guard(guard::Post()) - .wrap(rate_limit.register()) - .route(web::post().to(login)), - ) - .service( - web::resource("/account/password_reset") - .wrap(rate_limit.register()) - .route(web::post().to(reset_password)), - ) - .service( - // Handle captcha separately - web::resource("/account/get_captcha") - .wrap(rate_limit.post()) - .route(web::get().to(get_captcha)), - ) - .service( - web::resource("/account/export_settings") - .wrap(rate_limit.import_user_settings()) - .route(web::get().to(export_settings)), + .route("register", web::post().to(register)) + .route("login", web::post().to(login)) + .route("password_reset", web::post().to(reset_password)) + .route("get_captcha", web::get().to(get_captcha)) + .route( + "/password_change", + web::post().to(change_password_after_reset), + ) + .route("/change_password", web::put().to(change_password)) + .route("/totp/generate", web::post().to(generate_totp_secret)) + .route("/totp/update", web::post().to(update_totp)), ) .service( - web::resource("/account/import_settings") + web::resource("/account/export") .wrap(rate_limit.import_user_settings()) + .route(web::get().to(export_settings)) .route(web::post().to(import_settings)), ) .service( @@ -341,10 +323,6 @@ pub fn config(cfg: &mut web::ServiceConfig, rate_limit: &RateLimitCell) { .route("/block", web::post().to(block_person)) .route("/logout", web::post().to(logout)) .route("/delete_account", web::post().to(delete_account)) - .route( - "/password_change", - web::post().to(change_password_after_reset), - ) .route( "/mention/mark_as_read", web::post().to(mark_person_mention_as_read), @@ -354,13 +332,9 @@ pub fn config(cfg: &mut web::ServiceConfig, rate_limit: &RateLimitCell) { web::post().to(mark_all_notifications_read), ) .route("/save_user_settings", web::put().to(save_user_settings)) - .route("/change_password", web::put().to(change_password)) .route("/report_count", web::get().to(report_count)) .route("/unread_count", web::get().to(unread_count)) .route("/verify_email", web::post().to(verify_email)) - .route("/leave_admin", web::post().to(leave_admin)) - .route("/totp/generate", web::post().to(generate_totp_secret)) - .route("/totp/update", web::post().to(update_totp)) .route("/list_logins", web::get().to(list_logins)) .route("/validate_auth", web::get().to(validate_auth)), ) @@ -408,7 +382,8 @@ pub fn config(cfg: &mut web::ServiceConfig, rate_limit: &RateLimitCell) { .route("/list", web::get().to(list_taglines)), ) .route("/ban", web::post().to(ban_from_site)) - .route("/banned", web::get().to(list_banned_users)), + .route("/banned", web::get().to(list_banned_users)) + .route("/leave", web::post().to(leave_admin)), ) .service( web::scope("/custom_emoji") From 12ef9a0771891c81dcad23aad3203fd499ec6816 Mon Sep 17 00:00:00 2001 From: Felix Ableitner Date: Thu, 21 Nov 2024 12:21:20 +0100 Subject: [PATCH 03/26] move message rate limit --- src/api_routes_http.rs | 44 ++++++++---------------------------------- src/lib.rs | 1 + 2 files changed, 9 insertions(+), 36 deletions(-) diff --git a/src/api_routes_http.rs b/src/api_routes_http.rs index 32080c6702..42979eb6fe 100644 --- a/src/api_routes_http.rs +++ b/src/api_routes_http.rs @@ -166,28 +166,19 @@ pub fn config(cfg: &mut web::ServiceConfig, rate_limit: &RateLimitCell) { // Site .service( web::scope("/site") - .wrap(rate_limit.message()) .route("", web::get().to(get_site)) // Admin Actions .route("", web::post().to(create_site)) .route("", web::put().to(update_site)) .route("/block", web::post().to(block_instance)), ) - .service( - web::resource("/modlog") - .wrap(rate_limit.message()) - .route(web::get().to(get_mod_log)), - ) + .route("/modlog", web::get().to(get_mod_log)) .service( web::resource("/search") .wrap(rate_limit.search()) .route(web::get().to(search)), ) - .service( - web::resource("/resolve_object") - .wrap(rate_limit.message()) - .route(web::get().to(resolve_object)), - ) + .route("/resolve_object", web::get().to(resolve_object)) // Community .service( web::resource("/community") @@ -197,7 +188,6 @@ pub fn config(cfg: &mut web::ServiceConfig, rate_limit: &RateLimitCell) { ) .service( web::scope("/community") - .wrap(rate_limit.message()) .route("", web::get().to(get_community)) .route("", web::put().to(update_community)) .route("/random", web::get().to(get_random_community)) @@ -213,16 +203,14 @@ pub fn config(cfg: &mut web::ServiceConfig, rate_limit: &RateLimitCell) { .route("/mod", web::post().to(add_mod_to_community)) .service( web::scope("/pending_follows") - .wrap(rate_limit.message()) .route("/count", web::get().to(get_pending_follows_count)) .route("/list", web::get().to(get_pending_follows_list)) .route("/approve", web::post().to(post_pending_follows_approve)), ), ) - .service( - web::scope("/federated_instances") - .wrap(rate_limit.message()) - .route("", web::get().to(get_federated_instances)), + .route( + "/federated_instances", + web::get().to(get_federated_instances), ) // Post .service( @@ -234,7 +222,6 @@ pub fn config(cfg: &mut web::ServiceConfig, rate_limit: &RateLimitCell) { ) .service( web::scope("/post") - .wrap(rate_limit.message()) .route("", web::get().to(get_post)) .route("", web::put().to(update_post)) .route("/delete", web::post().to(delete_post)) @@ -263,7 +250,6 @@ pub fn config(cfg: &mut web::ServiceConfig, rate_limit: &RateLimitCell) { ) .service( web::scope("/comment") - .wrap(rate_limit.message()) .route("", web::get().to(get_comment)) .route("", web::put().to(update_comment)) .route("/delete", web::post().to(delete_comment)) @@ -281,7 +267,6 @@ pub fn config(cfg: &mut web::ServiceConfig, rate_limit: &RateLimitCell) { // Private Message .service( web::scope("/private_message") - .wrap(rate_limit.message()) .route("/list", web::get().to(get_private_message)) .route("", web::post().to(create_private_message)) .route("", web::put().to(update_private_message)) @@ -316,7 +301,6 @@ pub fn config(cfg: &mut web::ServiceConfig, rate_limit: &RateLimitCell) { ) .service( web::scope("/account") - .wrap(rate_limit.message()) .route("/list_media", web::get().to(list_media)) .route("/mention", web::get().to(list_mentions)) .route("/replies", web::get().to(list_replies)) @@ -339,15 +323,10 @@ pub fn config(cfg: &mut web::ServiceConfig, rate_limit: &RateLimitCell) { .route("/validate_auth", web::get().to(validate_auth)), ) // User actions - .service( - web::scope("/user") - .wrap(rate_limit.message()) - .route("", web::get().to(read_person)), - ) + .route("/user", web::get().to(read_person)) // Admin Actions .service( web::scope("/admin") - .wrap(rate_limit.message()) .route("/add", web::post().to(add_admin)) .route( "/registration_application/count", @@ -375,7 +354,6 @@ pub fn config(cfg: &mut web::ServiceConfig, rate_limit: &RateLimitCell) { ) .service( web::scope("/tagline") - .wrap(rate_limit.message()) .route("", web::post().to(create_tagline)) .route("", web::put().to(update_tagline)) .route("/delete", web::post().to(delete_tagline)) @@ -387,7 +365,6 @@ pub fn config(cfg: &mut web::ServiceConfig, rate_limit: &RateLimitCell) { ) .service( web::scope("/custom_emoji") - .wrap(rate_limit.message()) .route("", web::post().to(create_custom_emoji)) .route("", web::put().to(update_custom_emoji)) .route("/delete", web::post().to(delete_custom_emoji)) @@ -395,7 +372,6 @@ pub fn config(cfg: &mut web::ServiceConfig, rate_limit: &RateLimitCell) { ) .service( web::scope("/oauth_provider") - .wrap(rate_limit.message()) .route("", web::post().to(create_oauth_provider)) .route("", web::put().to(update_oauth_provider)) .route("/delete", web::post().to(delete_oauth_provider)), @@ -404,11 +380,7 @@ pub fn config(cfg: &mut web::ServiceConfig, rate_limit: &RateLimitCell) { web::scope("/oauth") .wrap(rate_limit.register()) .route("/authenticate", web::post().to(authenticate_with_oauth)), - ), - ); - cfg.service( - web::scope("/sitemap.xml") - .wrap(rate_limit.message()) - .route("", web::get().to(get_sitemap)), + ) + .route("/sitemap.xml", web::get().to(get_sitemap)), ); } diff --git a/src/lib.rs b/src/lib.rs index 319efd2246..4539c6094a 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -297,6 +297,7 @@ fn create_http_server( let server = HttpServer::new(move || { let cors_config = cors_config(&settings); let app = App::new() + .wrap(rate_limit_cell.message()) .wrap(middleware::Logger::new( // This is the default log format save for the usage of %{r}a over %a to guarantee to // record the client's (forwarded) IP and not the last peer address, since the latter is From b59e19de1b91e6336de31a0d5a6646a8599dc681 Mon Sep 17 00:00:00 2001 From: Felix Ableitner Date: Thu, 21 Nov 2024 14:47:31 +0100 Subject: [PATCH 04/26] move rate limit --- src/api_routes_http.rs | 1 + src/lib.rs | 1 - 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/src/api_routes_http.rs b/src/api_routes_http.rs index 42979eb6fe..b667132c23 100644 --- a/src/api_routes_http.rs +++ b/src/api_routes_http.rs @@ -162,6 +162,7 @@ use lemmy_utils::rate_limit::RateLimitCell; pub fn config(cfg: &mut web::ServiceConfig, rate_limit: &RateLimitCell) { cfg.service( web::scope("/api/v4") + .wrap(rate_limit.message()) .route("/image_proxy", web::get().to(image_proxy)) // Site .service( diff --git a/src/lib.rs b/src/lib.rs index 4539c6094a..319efd2246 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -297,7 +297,6 @@ fn create_http_server( let server = HttpServer::new(move || { let cors_config = cors_config(&settings); let app = App::new() - .wrap(rate_limit_cell.message()) .wrap(middleware::Logger::new( // This is the default log format save for the usage of %{r}a over %a to guarantee to // record the client's (forwarded) IP and not the last peer address, since the latter is From 0c580887d7a7bbba48738665de5120140374467b Mon Sep 17 00:00:00 2001 From: Felix Ableitner Date: Thu, 21 Nov 2024 14:53:31 +0100 Subject: [PATCH 05/26] apply suggestions --- src/api_routes_http.rs | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/api_routes_http.rs b/src/api_routes_http.rs index b667132c23..795ae3a1bf 100644 --- a/src/api_routes_http.rs +++ b/src/api_routes_http.rs @@ -284,6 +284,7 @@ pub fn config(cfg: &mut web::ServiceConfig, rate_limit: &RateLimitCell) { .wrap(rate_limit.register()) .route("register", web::post().to(register)) .route("login", web::post().to(login)) + .route("/logout", web::post().to(logout)) .route("password_reset", web::post().to(reset_password)) .route("get_captcha", web::get().to(get_captcha)) .route( @@ -292,13 +293,14 @@ pub fn config(cfg: &mut web::ServiceConfig, rate_limit: &RateLimitCell) { ) .route("/change_password", web::put().to(change_password)) .route("/totp/generate", web::post().to(generate_totp_secret)) - .route("/totp/update", web::post().to(update_totp)), + .route("/totp/update", web::post().to(update_totp)) + .route("/verify_email", web::post().to(verify_email)), ) .service( - web::resource("/account/export") + web::scope("/account/settings") .wrap(rate_limit.import_user_settings()) - .route(web::get().to(export_settings)) - .route(web::post().to(import_settings)), + .route("/export", web::get().to(export_settings)) + .route("/import", web::post().to(import_settings)), ) .service( web::scope("/account") @@ -306,8 +308,7 @@ pub fn config(cfg: &mut web::ServiceConfig, rate_limit: &RateLimitCell) { .route("/mention", web::get().to(list_mentions)) .route("/replies", web::get().to(list_replies)) .route("/block", web::post().to(block_person)) - .route("/logout", web::post().to(logout)) - .route("/delete_account", web::post().to(delete_account)) + .route("/delete", web::post().to(delete_account)) .route( "/mention/mark_as_read", web::post().to(mark_person_mention_as_read), @@ -316,15 +317,14 @@ pub fn config(cfg: &mut web::ServiceConfig, rate_limit: &RateLimitCell) { "/mention/mark_all_as_read", web::post().to(mark_all_notifications_read), ) - .route("/save_user_settings", web::put().to(save_user_settings)) + .route("/settings/save", web::put().to(save_user_settings)) .route("/report_count", web::get().to(report_count)) .route("/unread_count", web::get().to(unread_count)) - .route("/verify_email", web::post().to(verify_email)) .route("/list_logins", web::get().to(list_logins)) .route("/validate_auth", web::get().to(validate_auth)), ) // User actions - .route("/user", web::get().to(read_person)) + .route("/person", web::get().to(read_person)) // Admin Actions .service( web::scope("/admin") From 88b0aba1013172599eb3e17772a39fecfc09a7be Mon Sep 17 00:00:00 2001 From: Felix Ableitner Date: Fri, 22 Nov 2024 09:55:18 +0100 Subject: [PATCH 06/26] move my_user to separate endpoint --- crates/api/src/site/leave_admin.rs | 1 - crates/api_common/src/site.rs | 2 -- crates/api_crud/src/site/read.rs | 51 +++-------------------------- crates/api_crud/src/user/mod.rs | 1 + crates/api_crud/src/user/my_user.rs | 43 ++++++++++++++++++++++++ src/api_routes_http.rs | 2 ++ 6 files changed, 50 insertions(+), 50 deletions(-) create mode 100644 crates/api_crud/src/user/my_user.rs diff --git a/crates/api/src/site/leave_admin.rs b/crates/api/src/site/leave_admin.rs index 97ad7e2e5d..9f94e06db7 100644 --- a/crates/api/src/site/leave_admin.rs +++ b/crates/api/src/site/leave_admin.rs @@ -69,7 +69,6 @@ pub async fn leave_admin( site_view, admins, version: VERSION.to_string(), - my_user: None, all_languages, discussion_languages, oauth_providers: Some(oauth_providers), diff --git a/crates/api_common/src/site.rs b/crates/api_common/src/site.rs index 91c6151d77..c030519399 100644 --- a/crates/api_common/src/site.rs +++ b/crates/api_common/src/site.rs @@ -448,8 +448,6 @@ pub struct GetSiteResponse { pub site_view: SiteView, pub admins: Vec, pub version: String, - #[cfg_attr(feature = "full", ts(optional))] - pub my_user: Option, pub all_languages: Vec, pub discussion_languages: Vec, /// deprecated, use field `tagline` or /api/v3/tagline/list diff --git a/crates/api_crud/src/site/read.rs b/crates/api_crud/src/site/read.rs index 47fd1f154d..a840cd3c3e 100644 --- a/crates/api_crud/src/site/read.rs +++ b/crates/api_crud/src/site/read.rs @@ -1,22 +1,16 @@ use actix_web::web::{Data, Json}; -use lemmy_api_common::{ - context::LemmyContext, - site::{GetSiteResponse, MyUserInfo}, -}; +use lemmy_api_common::{context::LemmyContext, site::GetSiteResponse}; use lemmy_db_schema::source::{ - actor_language::{LocalUserLanguage, SiteLanguage}, - community_block::CommunityBlock, - instance_block::InstanceBlock, + actor_language::SiteLanguage, language::Language, local_site_url_blocklist::LocalSiteUrlBlocklist, oauth_provider::OAuthProvider, - person_block::PersonBlock, tagline::Tagline, }; use lemmy_db_views::structs::{LocalUserView, SiteView}; -use lemmy_db_views_actor::structs::{CommunityFollowerView, CommunityModeratorView, PersonView}; +use lemmy_db_views_actor::structs::PersonView; use lemmy_utils::{ - error::{LemmyError, LemmyErrorExt, LemmyErrorType, LemmyResult}, + error::{LemmyError, LemmyResult}, CACHE_DURATION_API, VERSION, }; @@ -52,7 +46,6 @@ pub async fn get_site( site_view, admins, version: VERSION.to_string(), - my_user: None, all_languages, discussion_languages, blocked_urls, @@ -66,42 +59,6 @@ pub async fn get_site( .await .map_err(|e| anyhow::anyhow!("Failed to construct site response: {e}"))?; - // Build the local user with parallel queries and add it to site response - site_response.my_user = if let Some(ref local_user_view) = local_user_view { - let person_id = local_user_view.person.id; - let local_user_id = local_user_view.local_user.id; - let pool = &mut context.pool(); - - let ( - follows, - community_blocks, - instance_blocks, - person_blocks, - moderates, - discussion_languages, - ) = lemmy_db_schema::try_join_with_pool!(pool => ( - |pool| CommunityFollowerView::for_person(pool, person_id), - |pool| CommunityBlock::for_person(pool, person_id), - |pool| InstanceBlock::for_person(pool, person_id), - |pool| PersonBlock::for_person(pool, person_id), - |pool| CommunityModeratorView::for_person(pool, person_id, Some(&local_user_view.local_user)), - |pool| LocalUserLanguage::read(pool, local_user_id) - )) - .with_lemmy_type(LemmyErrorType::SystemErrLogin)?; - - Some(MyUserInfo { - local_user_view: local_user_view.clone(), - follows, - moderates, - community_blocks, - instance_blocks, - person_blocks, - discussion_languages, - }) - } else { - None - }; - // filter oauth_providers for public access if !local_user_view .map(|l| l.local_user.admin) diff --git a/crates/api_crud/src/user/mod.rs b/crates/api_crud/src/user/mod.rs index da1aa3ace2..e6e88e6cd2 100644 --- a/crates/api_crud/src/user/mod.rs +++ b/crates/api_crud/src/user/mod.rs @@ -1,2 +1,3 @@ pub mod create; pub mod delete; +pub mod my_user; diff --git a/crates/api_crud/src/user/my_user.rs b/crates/api_crud/src/user/my_user.rs new file mode 100644 index 0000000000..805c9dabbf --- /dev/null +++ b/crates/api_crud/src/user/my_user.rs @@ -0,0 +1,43 @@ +use actix_web::web::{Data, Json}; +use lemmy_api_common::{context::LemmyContext, site::MyUserInfo}; +use lemmy_db_schema::source::{ + actor_language::LocalUserLanguage, + community_block::CommunityBlock, + instance_block::InstanceBlock, + person_block::PersonBlock, +}; +use lemmy_db_views::structs::LocalUserView; +use lemmy_db_views_actor::structs::{CommunityFollowerView, CommunityModeratorView}; +use lemmy_utils::error::{LemmyErrorExt, LemmyErrorType, LemmyResult}; + +#[tracing::instrument(skip(context))] +pub async fn get_my_user( + local_user_view: LocalUserView, + context: Data, +) -> LemmyResult> { + // Build the local user with parallel queries and add it to site response + let person_id = local_user_view.person.id; + let local_user_id = local_user_view.local_user.id; + let pool = &mut context.pool(); + + let (follows, community_blocks, instance_blocks, person_blocks, moderates, discussion_languages) = + lemmy_db_schema::try_join_with_pool!(pool => ( + |pool| CommunityFollowerView::for_person(pool, person_id), + |pool| CommunityBlock::for_person(pool, person_id), + |pool| InstanceBlock::for_person(pool, person_id), + |pool| PersonBlock::for_person(pool, person_id), + |pool| CommunityModeratorView::for_person(pool, person_id, Some(&local_user_view.local_user)), + |pool| LocalUserLanguage::read(pool, local_user_id) + )) + .with_lemmy_type(LemmyErrorType::SystemErrLogin)?; + + Ok(Json(MyUserInfo { + local_user_view: local_user_view.clone(), + follows, + moderates, + community_blocks, + instance_blocks, + person_blocks, + discussion_languages, + })) +} diff --git a/src/api_routes_http.rs b/src/api_routes_http.rs index 795ae3a1bf..42a2cf0ab5 100644 --- a/src/api_routes_http.rs +++ b/src/api_routes_http.rs @@ -145,6 +145,7 @@ use lemmy_api_crud::{ user::{ create::{authenticate_with_oauth, register}, delete::delete_account, + my_user::get_my_user, }, }; use lemmy_apub::api::{ @@ -304,6 +305,7 @@ pub fn config(cfg: &mut web::ServiceConfig, rate_limit: &RateLimitCell) { ) .service( web::scope("/account") + .route("/my_user", web::get().to(get_my_user)) .route("/list_media", web::get().to(list_media)) .route("/mention", web::get().to(list_mentions)) .route("/replies", web::get().to(list_replies)) From b365d7f96163cdc30365135fe8c36a8604397cb4 Mon Sep 17 00:00:00 2001 From: Felix Ableitner Date: Fri, 22 Nov 2024 09:56:27 +0100 Subject: [PATCH 07/26] remove taglines and custom emojis from siteview --- crates/api/src/site/leave_admin.rs | 2 -- crates/api_common/src/site.rs | 4 ---- crates/api_crud/src/site/read.rs | 2 -- 3 files changed, 8 deletions(-) diff --git a/crates/api/src/site/leave_admin.rs b/crates/api/src/site/leave_admin.rs index 9f94e06db7..a22b898c6d 100644 --- a/crates/api/src/site/leave_admin.rs +++ b/crates/api/src/site/leave_admin.rs @@ -75,7 +75,5 @@ pub async fn leave_admin( admin_oauth_providers: None, blocked_urls, tagline, - taglines: vec![], - custom_emojis: vec![], })) } diff --git a/crates/api_common/src/site.rs b/crates/api_common/src/site.rs index c030519399..8382144060 100644 --- a/crates/api_common/src/site.rs +++ b/crates/api_common/src/site.rs @@ -450,10 +450,6 @@ pub struct GetSiteResponse { pub version: String, pub all_languages: Vec, pub discussion_languages: Vec, - /// deprecated, use field `tagline` or /api/v3/tagline/list - pub taglines: Vec<()>, - /// deprecated, use /api/v3/custom_emoji/list - pub custom_emojis: Vec<()>, /// If the site has any taglines, a random one is included here for displaying #[cfg_attr(feature = "full", ts(optional))] pub tagline: Option, diff --git a/crates/api_crud/src/site/read.rs b/crates/api_crud/src/site/read.rs index a840cd3c3e..18f3dd3af7 100644 --- a/crates/api_crud/src/site/read.rs +++ b/crates/api_crud/src/site/read.rs @@ -52,8 +52,6 @@ pub async fn get_site( tagline, oauth_providers: Some(oauth_providers), admin_oauth_providers: Some(admin_oauth_providers), - taglines: vec![], - custom_emojis: vec![], }) }) .await From a6fd2136ee9408883fc5d0fe3771a1c84646b786 Mon Sep 17 00:00:00 2001 From: Felix Ableitner Date: Tue, 26 Nov 2024 14:51:07 +0100 Subject: [PATCH 08/26] routes for api v3 and v4 --- crates/api/src/site/leave_admin.rs | 1 + crates/api_common/src/site.rs | 2 + crates/api_crud/src/site/read.rs | 17 +- src/api_routes_v3.rs | 443 +++++++++++++++++++ src/{api_routes_http.rs => api_routes_v4.rs} | 6 +- src/lib.rs | 6 +- 6 files changed, 467 insertions(+), 8 deletions(-) create mode 100644 src/api_routes_v3.rs rename src/{api_routes_http.rs => api_routes_v4.rs} (98%) diff --git a/crates/api/src/site/leave_admin.rs b/crates/api/src/site/leave_admin.rs index a22b898c6d..cb59bb10dd 100644 --- a/crates/api/src/site/leave_admin.rs +++ b/crates/api/src/site/leave_admin.rs @@ -75,5 +75,6 @@ pub async fn leave_admin( admin_oauth_providers: None, blocked_urls, tagline, + my_user: None, })) } diff --git a/crates/api_common/src/site.rs b/crates/api_common/src/site.rs index 8382144060..f23fa27efa 100644 --- a/crates/api_common/src/site.rs +++ b/crates/api_common/src/site.rs @@ -448,6 +448,8 @@ pub struct GetSiteResponse { pub site_view: SiteView, pub admins: Vec, pub version: String, + #[cfg_attr(feature = "full", ts(optional))] + pub my_user: Option, pub all_languages: Vec, pub discussion_languages: Vec, /// If the site has any taglines, a random one is included here for displaying diff --git a/crates/api_crud/src/site/read.rs b/crates/api_crud/src/site/read.rs index 2954bbb14a..220fe1bd53 100644 --- a/crates/api_crud/src/site/read.rs +++ b/crates/api_crud/src/site/read.rs @@ -1,3 +1,4 @@ +use crate::user::my_user::get_my_user; use actix_web::web::{Data, Json}; use lemmy_api_common::{context::LemmyContext, site::GetSiteResponse}; use lemmy_db_schema::source::{ @@ -13,7 +14,19 @@ use lemmy_utils::{build_cache, error::LemmyResult, CacheLock, VERSION}; use std::sync::LazyLock; #[tracing::instrument(skip(context))] -pub async fn get_site( +pub async fn get_site_v3( + local_user_view: Option, + context: Data, +) -> LemmyResult> { + let mut site = get_site_v4(local_user_view.clone(), context.clone()).await?; + if let Some(local_user_view) = local_user_view { + site.my_user = Some(get_my_user(local_user_view, context).await?.0); + } + Ok(site) +} + +#[tracing::instrument(skip(context))] +pub async fn get_site_v4( local_user_view: Option, context: Data, ) -> LemmyResult> { @@ -56,7 +69,5 @@ async fn read_site(context: &LemmyContext) -> LemmyResult { tagline, oauth_providers: Some(oauth_providers), admin_oauth_providers: Some(admin_oauth_providers), - taglines: vec![], - custom_emojis: vec![], }) } diff --git a/src/api_routes_v3.rs b/src/api_routes_v3.rs new file mode 100644 index 0000000000..a36f8b7b19 --- /dev/null +++ b/src/api_routes_v3.rs @@ -0,0 +1,443 @@ +use actix_web::{guard, web}; +use lemmy_api::{ + comment::{ + distinguish::distinguish_comment, + like::like_comment, + list_comment_likes::list_comment_likes, + save::save_comment, + }, + comment_report::{ + create::create_comment_report, + list::list_comment_reports, + resolve::resolve_comment_report, + }, + community::{ + add_mod::add_mod_to_community, + ban::ban_from_community, + block::block_community, + follow::follow_community, + hide::hide_community, + pending_follows::{ + approve::post_pending_follows_approve, + count::get_pending_follows_count, + list::get_pending_follows_list, + }, + random::get_random_community, + transfer::transfer_community, + }, + local_user::{ + add_admin::add_admin, + ban_person::ban_from_site, + block::block_person, + change_password::change_password, + change_password_after_reset::change_password_after_reset, + generate_totp_secret::generate_totp_secret, + get_captcha::get_captcha, + list_banned::list_banned_users, + list_logins::list_logins, + list_media::list_media, + login::login, + logout::logout, + notifications::{ + list_mentions::list_mentions, + list_replies::list_replies, + mark_all_read::mark_all_notifications_read, + mark_mention_read::mark_person_mention_as_read, + mark_reply_read::mark_reply_as_read, + unread_count::unread_count, + }, + report_count::report_count, + reset_password::reset_password, + save_settings::save_user_settings, + update_totp::update_totp, + validate_auth::validate_auth, + verify_email::verify_email, + }, + post::{ + feature::feature_post, + get_link_metadata::get_link_metadata, + hide::hide_post, + like::like_post, + list_post_likes::list_post_likes, + lock::lock_post, + mark_many_read::mark_posts_as_read, + mark_read::mark_post_as_read, + save::save_post, + }, + post_report::{ + create::create_post_report, + list::list_post_reports, + resolve::resolve_post_report, + }, + private_message::mark_read::mark_pm_as_read, + private_message_report::{ + create::create_pm_report, + list::list_pm_reports, + resolve::resolve_pm_report, + }, + site::{ + block::block_instance, + federated_instances::get_federated_instances, + leave_admin::leave_admin, + list_all_media::list_all_media, + mod_log::get_mod_log, + purge::{ + comment::purge_comment, + community::purge_community, + person::purge_person, + post::purge_post, + }, + registration_applications::{ + approve::approve_registration_application, + get::get_registration_application, + list::list_registration_applications, + unread_count::get_unread_registration_application_count, + }, + }, + sitemap::get_sitemap, +}; +use lemmy_api_crud::{ + comment::{ + create::create_comment, + delete::delete_comment, + read::get_comment, + remove::remove_comment, + update::update_comment, + }, + community::{ + create::create_community, + delete::delete_community, + list::list_communities, + remove::remove_community, + update::update_community, + }, + custom_emoji::{ + create::create_custom_emoji, + delete::delete_custom_emoji, + list::list_custom_emojis, + update::update_custom_emoji, + }, + oauth_provider::{ + create::create_oauth_provider, + delete::delete_oauth_provider, + update::update_oauth_provider, + }, + post::{ + create::create_post, + delete::delete_post, + read::get_post, + remove::remove_post, + update::update_post, + }, + private_message::{ + create::create_private_message, + delete::delete_private_message, + read::get_private_message, + update::update_private_message, + }, + site::{create::create_site, read::get_site_v3, update::update_site}, + tagline::{ + create::create_tagline, + delete::delete_tagline, + list::list_taglines, + update::update_tagline, + }, + user::{ + create::{authenticate_with_oauth, register}, + delete::delete_account, + }, +}; +use lemmy_apub::api::{ + list_comments::list_comments, + list_posts::list_posts, + read_community::get_community, + read_person::read_person, + resolve_object::resolve_object, + search::search, + user_settings_backup::{export_settings, import_settings}, +}; +use lemmy_routes::images::image_proxy; +use lemmy_utils::rate_limit::RateLimitCell; + +pub fn config(cfg: &mut web::ServiceConfig, rate_limit: &RateLimitCell) { + cfg.service( + web::scope("/api/v3") + .route("/image_proxy", web::get().to(image_proxy)) + // Site + .service( + web::scope("/site") + .wrap(rate_limit.message()) + .route("", web::get().to(get_site_v3)) + // Admin Actions + .route("", web::post().to(create_site)) + .route("", web::put().to(update_site)) + .route("/block", web::post().to(block_instance)), + ) + .service( + web::resource("/modlog") + .wrap(rate_limit.message()) + .route(web::get().to(get_mod_log)), + ) + .service( + web::resource("/search") + .wrap(rate_limit.search()) + .route(web::get().to(search)), + ) + .service( + web::resource("/resolve_object") + .wrap(rate_limit.message()) + .route(web::get().to(resolve_object)), + ) + // Community + .service( + web::resource("/community") + .guard(guard::Post()) + .wrap(rate_limit.register()) + .route(web::post().to(create_community)), + ) + .service( + web::scope("/community") + .wrap(rate_limit.message()) + .route("", web::get().to(get_community)) + .route("", web::put().to(update_community)) + .route("/random", web::get().to(get_random_community)) + .route("/hide", web::put().to(hide_community)) + .route("/list", web::get().to(list_communities)) + .route("/follow", web::post().to(follow_community)) + .route("/block", web::post().to(block_community)) + .route("/delete", web::post().to(delete_community)) + // Mod Actions + .route("/remove", web::post().to(remove_community)) + .route("/transfer", web::post().to(transfer_community)) + .route("/ban_user", web::post().to(ban_from_community)) + .route("/mod", web::post().to(add_mod_to_community)) + .service( + web::scope("/pending_follows") + .wrap(rate_limit.message()) + .route("/count", web::get().to(get_pending_follows_count)) + .route("/list", web::get().to(get_pending_follows_list)) + .route("/approve", web::post().to(post_pending_follows_approve)), + ), + ) + .service( + web::scope("/federated_instances") + .wrap(rate_limit.message()) + .route("", web::get().to(get_federated_instances)), + ) + // Post + .service( + // Handle POST to /post separately to add the post() rate limitter + web::resource("/post") + .guard(guard::Post()) + .wrap(rate_limit.post()) + .route(web::post().to(create_post)), + ) + .service( + web::scope("/post") + .wrap(rate_limit.message()) + .route("", web::get().to(get_post)) + .route("", web::put().to(update_post)) + .route("/delete", web::post().to(delete_post)) + .route("/remove", web::post().to(remove_post)) + .route("/mark_as_read", web::post().to(mark_post_as_read)) + .route("/mark_many_as_read", web::post().to(mark_posts_as_read)) + .route("/hide", web::post().to(hide_post)) + .route("/lock", web::post().to(lock_post)) + .route("/feature", web::post().to(feature_post)) + .route("/list", web::get().to(list_posts)) + .route("/like", web::post().to(like_post)) + .route("/like/list", web::get().to(list_post_likes)) + .route("/save", web::put().to(save_post)) + .route("/report", web::post().to(create_post_report)) + .route("/report/resolve", web::put().to(resolve_post_report)) + .route("/report/list", web::get().to(list_post_reports)) + .route("/site_metadata", web::get().to(get_link_metadata)), + ) + // Comment + .service( + // Handle POST to /comment separately to add the comment() rate limitter + web::resource("/comment") + .guard(guard::Post()) + .wrap(rate_limit.comment()) + .route(web::post().to(create_comment)), + ) + .service( + web::scope("/comment") + .wrap(rate_limit.message()) + .route("", web::get().to(get_comment)) + .route("", web::put().to(update_comment)) + .route("/delete", web::post().to(delete_comment)) + .route("/remove", web::post().to(remove_comment)) + .route("/mark_as_read", web::post().to(mark_reply_as_read)) + .route("/distinguish", web::post().to(distinguish_comment)) + .route("/like", web::post().to(like_comment)) + .route("/like/list", web::get().to(list_comment_likes)) + .route("/save", web::put().to(save_comment)) + .route("/list", web::get().to(list_comments)) + .route("/report", web::post().to(create_comment_report)) + .route("/report/resolve", web::put().to(resolve_comment_report)) + .route("/report/list", web::get().to(list_comment_reports)), + ) + // Private Message + .service( + web::scope("/private_message") + .wrap(rate_limit.message()) + .route("/list", web::get().to(get_private_message)) + .route("", web::post().to(create_private_message)) + .route("", web::put().to(update_private_message)) + .route("/delete", web::post().to(delete_private_message)) + .route("/mark_as_read", web::post().to(mark_pm_as_read)) + .route("/report", web::post().to(create_pm_report)) + .route("/report/resolve", web::put().to(resolve_pm_report)) + .route("/report/list", web::get().to(list_pm_reports)), + ) + // User + .service( + // Account action, I don't like that it's in /user maybe /accounts + // Handle /user/register separately to add the register() rate limiter + web::resource("/user/register") + .guard(guard::Post()) + .wrap(rate_limit.register()) + .route(web::post().to(register)), + ) + // User + .service( + // Handle /user/login separately to add the register() rate limiter + // TODO: pretty annoying way to apply rate limits for register and login, we should + // group them under a common path so that rate limit is only applied once (eg under + // /account). + web::resource("/user/login") + .guard(guard::Post()) + .wrap(rate_limit.register()) + .route(web::post().to(login)), + ) + .service( + web::resource("/user/password_reset") + .wrap(rate_limit.register()) + .route(web::post().to(reset_password)), + ) + .service( + // Handle captcha separately + web::resource("/user/get_captcha") + .wrap(rate_limit.post()) + .route(web::get().to(get_captcha)), + ) + .service( + web::resource("/user/export_settings") + .wrap(rate_limit.import_user_settings()) + .route(web::get().to(export_settings)), + ) + .service( + web::resource("/user/import_settings") + .wrap(rate_limit.import_user_settings()) + .route(web::post().to(import_settings)), + ) + // TODO, all the current account related actions under /user need to get moved here eventually + .service( + web::scope("/account") + .wrap(rate_limit.message()) + .route("/list_media", web::get().to(list_media)), + ) + // User actions + .service( + web::scope("/user") + .wrap(rate_limit.message()) + .route("", web::get().to(read_person)) + .route("/mention", web::get().to(list_mentions)) + .route( + "/mention/mark_as_read", + web::post().to(mark_person_mention_as_read), + ) + .route("/replies", web::get().to(list_replies)) + // Admin action. I don't like that it's in /user + .route("/ban", web::post().to(ban_from_site)) + .route("/banned", web::get().to(list_banned_users)) + .route("/block", web::post().to(block_person)) + // TODO Account actions. I don't like that they're in /user maybe /accounts + .route("/logout", web::post().to(logout)) + .route("/delete_account", web::post().to(delete_account)) + .route( + "/password_change", + web::post().to(change_password_after_reset), + ) + // TODO mark_all_as_read feels off being in this section as well + .route( + "/mark_all_as_read", + web::post().to(mark_all_notifications_read), + ) + .route("/save_user_settings", web::put().to(save_user_settings)) + .route("/change_password", web::put().to(change_password)) + .route("/report_count", web::get().to(report_count)) + .route("/unread_count", web::get().to(unread_count)) + .route("/verify_email", web::post().to(verify_email)) + .route("/leave_admin", web::post().to(leave_admin)) + .route("/totp/generate", web::post().to(generate_totp_secret)) + .route("/totp/update", web::post().to(update_totp)) + .route("/list_logins", web::get().to(list_logins)) + .route("/validate_auth", web::get().to(validate_auth)), + ) + // Admin Actions + .service( + web::scope("/admin") + .wrap(rate_limit.message()) + .route("/add", web::post().to(add_admin)) + .route( + "/registration_application/count", + web::get().to(get_unread_registration_application_count), + ) + .route( + "/registration_application/list", + web::get().to(list_registration_applications), + ) + .route( + "/registration_application/approve", + web::put().to(approve_registration_application), + ) + .route( + "/registration_application", + web::get().to(get_registration_application), + ) + .route("/list_all_media", web::get().to(list_all_media)) + .service( + web::scope("/purge") + .route("/person", web::post().to(purge_person)) + .route("/community", web::post().to(purge_community)) + .route("/post", web::post().to(purge_post)) + .route("/comment", web::post().to(purge_comment)), + ) + .service( + web::scope("/tagline") + .wrap(rate_limit.message()) + .route("", web::post().to(create_tagline)) + .route("", web::put().to(update_tagline)) + .route("/delete", web::post().to(delete_tagline)) + .route("/list", web::get().to(list_taglines)), + ), + ) + .service( + web::scope("/custom_emoji") + .wrap(rate_limit.message()) + .route("", web::post().to(create_custom_emoji)) + .route("", web::put().to(update_custom_emoji)) + .route("/delete", web::post().to(delete_custom_emoji)) + .route("/list", web::get().to(list_custom_emojis)), + ) + .service( + web::scope("/oauth_provider") + .wrap(rate_limit.message()) + .route("", web::post().to(create_oauth_provider)) + .route("", web::put().to(update_oauth_provider)) + .route("/delete", web::post().to(delete_oauth_provider)), + ) + .service( + web::scope("/oauth") + .wrap(rate_limit.register()) + .route("/authenticate", web::post().to(authenticate_with_oauth)), + ), + ); + cfg.service( + web::scope("/sitemap.xml") + .wrap(rate_limit.message()) + .route("", web::get().to(get_sitemap)), + ); +} diff --git a/src/api_routes_http.rs b/src/api_routes_v4.rs similarity index 98% rename from src/api_routes_http.rs rename to src/api_routes_v4.rs index 42a2cf0ab5..42f25628fb 100644 --- a/src/api_routes_http.rs +++ b/src/api_routes_v4.rs @@ -135,7 +135,7 @@ use lemmy_api_crud::{ read::get_private_message, update::update_private_message, }, - site::{create::create_site, read::get_site, update::update_site}, + site::{create::create_site, read::get_site_v4, update::update_site}, tagline::{ create::create_tagline, delete::delete_tagline, @@ -162,13 +162,13 @@ use lemmy_utils::rate_limit::RateLimitCell; pub fn config(cfg: &mut web::ServiceConfig, rate_limit: &RateLimitCell) { cfg.service( - web::scope("/api/v4") + web::scope("/api/v3") .wrap(rate_limit.message()) .route("/image_proxy", web::get().to(image_proxy)) // Site .service( web::scope("/site") - .route("", web::get().to(get_site)) + .route("", web::get().to(get_site_v4)) // Admin Actions .route("", web::post().to(create_site)) .route("", web::put().to(update_site)) diff --git a/src/lib.rs b/src/lib.rs index 319efd2246..5586b61592 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,4 +1,5 @@ -pub mod api_routes_http; +pub mod api_routes_v3; +pub mod api_routes_v4; pub mod code_migrations; pub mod prometheus_metrics; pub mod scheduled_tasks; @@ -318,7 +319,8 @@ fn create_http_server( // The routes app - .configure(|cfg| api_routes_http::config(cfg, &rate_limit_cell)) + .configure(|cfg| api_routes_v3::config(cfg, &rate_limit_cell)) + .configure(|cfg| api_routes_v4::config(cfg, &rate_limit_cell)) .configure(|cfg| { if federation_enabled { lemmy_apub::http::routes::config(cfg); From b7fdc41417f044961a934e2e4c2a13244f4234ea Mon Sep 17 00:00:00 2001 From: Felix Ableitner Date: Tue, 26 Nov 2024 15:25:05 +0100 Subject: [PATCH 09/26] remove new features from api v3 --- src/api_routes_v3.rs | 58 +++----------------------------------------- 1 file changed, 3 insertions(+), 55 deletions(-) diff --git a/src/api_routes_v3.rs b/src/api_routes_v3.rs index a36f8b7b19..65d50e1b6f 100644 --- a/src/api_routes_v3.rs +++ b/src/api_routes_v3.rs @@ -17,12 +17,6 @@ use lemmy_api::{ block::block_community, follow::follow_community, hide::hide_community, - pending_follows::{ - approve::post_pending_follows_approve, - count::get_pending_follows_count, - list::get_pending_follows_list, - }, - random::get_random_community, transfer::transfer_community, }, local_user::{ @@ -60,7 +54,6 @@ use lemmy_api::{ like::like_post, list_post_likes::list_post_likes, lock::lock_post, - mark_many_read::mark_posts_as_read, mark_read::mark_post_as_read, save::save_post, }, @@ -114,14 +107,8 @@ use lemmy_api_crud::{ custom_emoji::{ create::create_custom_emoji, delete::delete_custom_emoji, - list::list_custom_emojis, update::update_custom_emoji, }, - oauth_provider::{ - create::create_oauth_provider, - delete::delete_oauth_provider, - update::update_oauth_provider, - }, post::{ create::create_post, delete::delete_post, @@ -136,16 +123,7 @@ use lemmy_api_crud::{ update::update_private_message, }, site::{create::create_site, read::get_site_v3, update::update_site}, - tagline::{ - create::create_tagline, - delete::delete_tagline, - list::list_taglines, - update::update_tagline, - }, - user::{ - create::{authenticate_with_oauth, register}, - delete::delete_account, - }, + user::{create::register, delete::delete_account}, }; use lemmy_apub::api::{ list_comments::list_comments, @@ -200,7 +178,6 @@ pub fn config(cfg: &mut web::ServiceConfig, rate_limit: &RateLimitCell) { .wrap(rate_limit.message()) .route("", web::get().to(get_community)) .route("", web::put().to(update_community)) - .route("/random", web::get().to(get_random_community)) .route("/hide", web::put().to(hide_community)) .route("/list", web::get().to(list_communities)) .route("/follow", web::post().to(follow_community)) @@ -210,14 +187,7 @@ pub fn config(cfg: &mut web::ServiceConfig, rate_limit: &RateLimitCell) { .route("/remove", web::post().to(remove_community)) .route("/transfer", web::post().to(transfer_community)) .route("/ban_user", web::post().to(ban_from_community)) - .route("/mod", web::post().to(add_mod_to_community)) - .service( - web::scope("/pending_follows") - .wrap(rate_limit.message()) - .route("/count", web::get().to(get_pending_follows_count)) - .route("/list", web::get().to(get_pending_follows_list)) - .route("/approve", web::post().to(post_pending_follows_approve)), - ), + .route("/mod", web::post().to(add_mod_to_community)), ) .service( web::scope("/federated_instances") @@ -240,7 +210,6 @@ pub fn config(cfg: &mut web::ServiceConfig, rate_limit: &RateLimitCell) { .route("/delete", web::post().to(delete_post)) .route("/remove", web::post().to(remove_post)) .route("/mark_as_read", web::post().to(mark_post_as_read)) - .route("/mark_many_as_read", web::post().to(mark_posts_as_read)) .route("/hide", web::post().to(hide_post)) .route("/lock", web::post().to(lock_post)) .route("/feature", web::post().to(feature_post)) @@ -404,14 +373,6 @@ pub fn config(cfg: &mut web::ServiceConfig, rate_limit: &RateLimitCell) { .route("/community", web::post().to(purge_community)) .route("/post", web::post().to(purge_post)) .route("/comment", web::post().to(purge_comment)), - ) - .service( - web::scope("/tagline") - .wrap(rate_limit.message()) - .route("", web::post().to(create_tagline)) - .route("", web::put().to(update_tagline)) - .route("/delete", web::post().to(delete_tagline)) - .route("/list", web::get().to(list_taglines)), ), ) .service( @@ -419,20 +380,7 @@ pub fn config(cfg: &mut web::ServiceConfig, rate_limit: &RateLimitCell) { .wrap(rate_limit.message()) .route("", web::post().to(create_custom_emoji)) .route("", web::put().to(update_custom_emoji)) - .route("/delete", web::post().to(delete_custom_emoji)) - .route("/list", web::get().to(list_custom_emojis)), - ) - .service( - web::scope("/oauth_provider") - .wrap(rate_limit.message()) - .route("", web::post().to(create_oauth_provider)) - .route("", web::put().to(update_oauth_provider)) - .route("/delete", web::post().to(delete_oauth_provider)), - ) - .service( - web::scope("/oauth") - .wrap(rate_limit.register()) - .route("/authenticate", web::post().to(authenticate_with_oauth)), + .route("/delete", web::post().to(delete_custom_emoji)), ), ); cfg.service( From d2a39ccffa1373c7316d769900bff25e0d2a9675 Mon Sep 17 00:00:00 2001 From: Felix Ableitner Date: Tue, 26 Nov 2024 15:49:13 +0100 Subject: [PATCH 10/26] js client --- api_tests/package.json | 2 +- api_tests/pnpm-lock.yaml | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/api_tests/package.json b/api_tests/package.json index 57173595a9..90e63a1e7a 100644 --- a/api_tests/package.json +++ b/api_tests/package.json @@ -28,7 +28,7 @@ "eslint": "^9.14.0", "eslint-plugin-prettier": "^5.1.3", "jest": "^29.5.0", - "lemmy-js-client": "0.20.0-alpha.18", + "lemmy-js-client": "0.20.0-api-v4.0", "prettier": "^3.2.5", "ts-jest": "^29.1.0", "typescript": "^5.5.4", diff --git a/api_tests/pnpm-lock.yaml b/api_tests/pnpm-lock.yaml index 01d4a8e74a..2ecf2a2213 100644 --- a/api_tests/pnpm-lock.yaml +++ b/api_tests/pnpm-lock.yaml @@ -30,8 +30,8 @@ importers: specifier: ^29.5.0 version: 29.7.0(@types/node@22.9.0) lemmy-js-client: - specifier: 0.20.0-alpha.18 - version: 0.20.0-alpha.18 + specifier: 0.20.0-api-v4.0 + version: 0.20.0-api-v4.0 prettier: specifier: ^3.2.5 version: 3.3.3 @@ -1167,8 +1167,8 @@ packages: resolution: {integrity: sha512-eTIzlVOSUR+JxdDFepEYcBMtZ9Qqdef+rnzWdRZuMbOywu5tO2w2N7rqjoANZ5k9vywhL6Br1VRjUIgTQx4E8w==} engines: {node: '>=6'} - lemmy-js-client@0.20.0-alpha.18: - resolution: {integrity: sha512-oZy8DboTWfUar4mPWpi7SYrOEjTBJxkvd1e6QaVwoA5UhqQV1WhxEYbzrpi/gXnEokaVQ0i5sjtL/Y2PHMO3MQ==} + lemmy-js-client@0.20.0-api-v4.0: + resolution: {integrity: sha512-oS02mNzLYWcDIk3FJj1YvBmgpZJQWr34uuxharPd5jQyU8/Yub4XNHrQnjPX5wrXEC6am5ebR8iQmRuQsPQDmw==} leven@3.1.0: resolution: {integrity: sha512-qsda+H8jTaUaN/x5vzW2rzc+8Rw4TAQ/4KjB46IwK5VH+IlVeeeje/EoZRpiXvIqjFgK84QffqPztGI3VBLG1A==} @@ -3077,7 +3077,7 @@ snapshots: kleur@3.0.3: {} - lemmy-js-client@0.20.0-alpha.18: {} + lemmy-js-client@0.20.0-api-v4.0: {} leven@3.1.0: {} From 1dc544107a3179cd46b490af8c538cec57e535e4 Mon Sep 17 00:00:00 2001 From: Felix Ableitner Date: Thu, 28 Nov 2024 11:43:25 +0100 Subject: [PATCH 11/26] replace occurences of `v3`, fix routes --- api_tests/prepare-drone-federation-test.sh | 10 +++++----- api_tests/src/image.spec.ts | 12 ++++++------ crates/api_common/README.md | 2 +- crates/api_common/src/site.rs | 2 +- crates/api_common/src/utils.rs | 6 +++--- crates/utils/src/settings/structs.rs | 2 +- crates/utils/src/utils/markdown/image_links.rs | 14 +++++++------- crates/utils/src/utils/markdown/mod.rs | 10 +++++----- src/api_routes_v4.rs | 10 +++++----- 9 files changed, 34 insertions(+), 34 deletions(-) diff --git a/api_tests/prepare-drone-federation-test.sh b/api_tests/prepare-drone-federation-test.sh index 65c4827d9f..e5a4bc6041 100755 --- a/api_tests/prepare-drone-federation-test.sh +++ b/api_tests/prepare-drone-federation-test.sh @@ -82,13 +82,13 @@ LEMMY_CONFIG_LOCATION=./docker/federation/lemmy_epsilon.hjson \ target/lemmy_server >$LOG_DIR/lemmy_epsilon.out 2>&1 & echo "wait for all instances to start" -while [[ "$(curl -s -o /dev/null -w '%{http_code}' 'lemmy-alpha:8541/api/v3/site')" != "200" ]]; do sleep 1; done +while [[ "$(curl -s -o /dev/null -w '%{http_code}' 'lemmy-alpha:8541/api/v4/site')" != "200" ]]; do sleep 1; done echo "alpha started" -while [[ "$(curl -s -o /dev/null -w '%{http_code}' 'lemmy-beta:8551/api/v3/site')" != "200" ]]; do sleep 1; done +while [[ "$(curl -s -o /dev/null -w '%{http_code}' 'lemmy-beta:8551/api/v4/site')" != "200" ]]; do sleep 1; done echo "beta started" -while [[ "$(curl -s -o /dev/null -w '%{http_code}' 'lemmy-gamma:8561/api/v3/site')" != "200" ]]; do sleep 1; done +while [[ "$(curl -s -o /dev/null -w '%{http_code}' 'lemmy-gamma:8561/api/v4/site')" != "200" ]]; do sleep 1; done echo "gamma started" -while [[ "$(curl -s -o /dev/null -w '%{http_code}' 'lemmy-delta:8571/api/v3/site')" != "200" ]]; do sleep 1; done +while [[ "$(curl -s -o /dev/null -w '%{http_code}' 'lemmy-delta:8571/api/v4/site')" != "200" ]]; do sleep 1; done echo "delta started" -while [[ "$(curl -s -o /dev/null -w '%{http_code}' 'lemmy-epsilon:8581/api/v3/site')" != "200" ]]; do sleep 1; done +while [[ "$(curl -s -o /dev/null -w '%{http_code}' 'lemmy-epsilon:8581/api/v4/site')" != "200" ]]; do sleep 1; done echo "epsilon started. All started" diff --git a/api_tests/src/image.spec.ts b/api_tests/src/image.spec.ts index 7ac6e7221d..ede04294d6 100644 --- a/api_tests/src/image.spec.ts +++ b/api_tests/src/image.spec.ts @@ -199,11 +199,11 @@ test("Images in remote image post are proxied if setting enabled", async () => { // remote image gets proxied after upload expect( post.thumbnail_url?.startsWith( - "http://lemmy-gamma:8561/api/v3/image_proxy?url", + "http://lemmy-gamma:8561/api/v4/image_proxy?url", ), ).toBeTruthy(); expect( - post.body?.startsWith("![](http://lemmy-gamma:8561/api/v3/image_proxy?url"), + post.body?.startsWith("![](http://lemmy-gamma:8561/api/v4/image_proxy?url"), ).toBeTruthy(); // Make sure that it ends with jpg, to be sure its an image @@ -222,12 +222,12 @@ test("Images in remote image post are proxied if setting enabled", async () => { expect( epsilonPost.thumbnail_url?.startsWith( - "http://lemmy-epsilon:8581/api/v3/image_proxy?url", + "http://lemmy-epsilon:8581/api/v4/image_proxy?url", ), ).toBeTruthy(); expect( epsilonPost.body?.startsWith( - "![](http://lemmy-epsilon:8581/api/v3/image_proxy?url", + "![](http://lemmy-epsilon:8581/api/v4/image_proxy?url", ), ).toBeTruthy(); @@ -249,7 +249,7 @@ test("Thumbnail of remote image link is proxied if setting enabled", async () => // remote image gets proxied after upload expect( post.thumbnail_url?.startsWith( - "http://lemmy-gamma:8561/api/v3/image_proxy?url", + "http://lemmy-gamma:8561/api/v4/image_proxy?url", ), ).toBeTruthy(); @@ -267,7 +267,7 @@ test("Thumbnail of remote image link is proxied if setting enabled", async () => expect( epsilonPost.thumbnail_url?.startsWith( - "http://lemmy-epsilon:8581/api/v3/image_proxy?url", + "http://lemmy-epsilon:8581/api/v4/image_proxy?url", ), ).toBeTruthy(); diff --git a/crates/api_common/README.md b/crates/api_common/README.md index b4e7ad63b3..ded59d34a9 100644 --- a/crates/api_common/README.md +++ b/crates/api_common/README.md @@ -11,7 +11,7 @@ Here is an example using [reqwest](https://crates.io/crates/reqwest): }; let client = Client::new(); let response = client - .get("https://lemmy.ml/api/v3/post/list") + .get("https://lemmy.ml/api/v4/post/list") .query(¶ms) .send() .await?; diff --git a/crates/api_common/src/site.rs b/crates/api_common/src/site.rs index f23fa27efa..68aedc49e9 100644 --- a/crates/api_common/src/site.rs +++ b/crates/api_common/src/site.rs @@ -435,7 +435,7 @@ pub struct EditSite { /// The response for a site. pub struct SiteResponse { pub site_view: SiteView, - /// deprecated, use field `tagline` or /api/v3/tagline/list + /// deprecated, use field `tagline` or /api/4/tagline/list pub taglines: Vec<()>, } diff --git a/crates/api_common/src/utils.rs b/crates/api_common/src/utils.rs index d46e577491..688c131869 100644 --- a/crates/api_common/src/utils.rs +++ b/crates/api_common/src/utils.rs @@ -1120,7 +1120,7 @@ async fn proxy_image_link_internal( } } -/// Rewrite a link to go through `/api/v3/image_proxy` endpoint. This is only for remote urls and +/// Rewrite a link to go through `/api/v4/image_proxy` endpoint. This is only for remote urls and /// if image_proxy setting is enabled. pub async fn proxy_image_link(link: Url, context: &LemmyContext) -> LemmyResult { proxy_image_link_internal( @@ -1172,7 +1172,7 @@ fn build_proxied_image_url( protocol_and_hostname: &str, ) -> Result { Url::parse(&format!( - "{}/api/v3/image_proxy?url={}", + "{}/api/v4/image_proxy?url={}", protocol_and_hostname, encode(link.as_str()) )) @@ -1251,7 +1251,7 @@ mod tests { ) .await?; assert_eq!( - "https://lemmy-alpha/api/v3/image_proxy?url=http%3A%2F%2Flemmy-beta%2Fimage.png", + "https://lemmy-alpha/api/v4/image_proxy?url=http%3A%2F%2Flemmy-beta%2Fimage.png", proxied.as_str() ); diff --git a/crates/utils/src/settings/structs.rs b/crates/utils/src/settings/structs.rs index fdbec4a953..e908fa4124 100644 --- a/crates/utils/src/settings/structs.rs +++ b/crates/utils/src/settings/structs.rs @@ -111,7 +111,7 @@ pub enum PictrsImageMode { #[default] StoreLinkPreviews, /// If enabled, all images from remote domains are rewritten to pass through - /// `/api/v3/image_proxy`, including embedded images in markdown. Images are stored temporarily + /// `/api/v4/image_proxy`, including embedded images in markdown. Images are stored temporarily /// in pict-rs for caching. This improves privacy as users don't expose their IP to untrusted /// servers, and decreases load on other servers. However it increases bandwidth use for the /// local server. diff --git a/crates/utils/src/utils/markdown/image_links.rs b/crates/utils/src/utils/markdown/image_links.rs index 9dcea8da79..0990b1bc70 100644 --- a/crates/utils/src/utils/markdown/image_links.rs +++ b/crates/utils/src/utils/markdown/image_links.rs @@ -4,7 +4,7 @@ use markdown_it::{plugins::cmark::inline::image::Image, NodeValue}; use url::Url; use urlencoding::encode; -/// Rewrites all links to remote domains in markdown, so they go through `/api/v3/image_proxy`. +/// Rewrites all links to remote domains in markdown, so they go through `/api/v4/image_proxy`. pub fn markdown_rewrite_image_links(mut src: String) -> (String, Vec) { let links_offsets = find_urls::(&src); @@ -18,7 +18,7 @@ pub fn markdown_rewrite_image_links(mut src: String) -> (String, Vec) { // If link points to remote domain, replace with proxied link if parsed.domain() != Some(&SETTINGS.hostname) { let mut proxied = format!( - "{}/api/v3/image_proxy?url={}", + "{}/api/v4/image_proxy?url={}", SETTINGS.get_protocol_and_hostname(), encode(url), ); @@ -115,7 +115,7 @@ mod tests { ( "remote image proxied", "![link](http://example.com/image.jpg)", - "![link](https://lemmy-alpha/api/v3/image_proxy?url=http%3A%2F%2Fexample.com%2Fimage.jpg)", + "![link](https://lemmy-alpha/api/v4/image_proxy?url=http%3A%2F%2Fexample.com%2Fimage.jpg)", ), ( "local image unproxied", @@ -125,7 +125,7 @@ mod tests { ( "multiple image links", "![link](http://example.com/image1.jpg) ![link](http://example.com/image2.jpg)", - "![link](https://lemmy-alpha/api/v3/image_proxy?url=http%3A%2F%2Fexample.com%2Fimage1.jpg) ![link](https://lemmy-alpha/api/v3/image_proxy?url=http%3A%2F%2Fexample.com%2Fimage2.jpg)", + "![link](https://lemmy-alpha/api/v4/image_proxy?url=http%3A%2F%2Fexample.com%2Fimage1.jpg) ![link](https://lemmy-alpha/api/v4/image_proxy?url=http%3A%2F%2Fexample.com%2Fimage2.jpg)", ), ( "empty link handled", @@ -135,7 +135,7 @@ mod tests { ( "empty label handled", "![](http://example.com/image.jpg)", - "![](https://lemmy-alpha/api/v3/image_proxy?url=http%3A%2F%2Fexample.com%2Fimage.jpg)" + "![](https://lemmy-alpha/api/v4/image_proxy?url=http%3A%2F%2Fexample.com%2Fimage.jpg)" ), ( "invalid image link removed", @@ -145,12 +145,12 @@ mod tests { ( "label with nested markdown handled", "![a *b* c](http://example.com/image.jpg)", - "![a *b* c](https://lemmy-alpha/api/v3/image_proxy?url=http%3A%2F%2Fexample.com%2Fimage.jpg)" + "![a *b* c](https://lemmy-alpha/api/v4/image_proxy?url=http%3A%2F%2Fexample.com%2Fimage.jpg)" ), ( "custom emoji support", r#"![party-blob](https://www.hexbear.net/pictrs/image/83405746-0620-4728-9358-5f51b040ffee.gif "emoji party-blob")"#, - r#"![party-blob](https://lemmy-alpha/api/v3/image_proxy?url=https%3A%2F%2Fwww.hexbear.net%2Fpictrs%2Fimage%2F83405746-0620-4728-9358-5f51b040ffee.gif "emoji party-blob")"# + r#"![party-blob](https://lemmy-alpha/api/v4/image_proxy?url=https%3A%2F%2Fwww.hexbear.net%2Fpictrs%2Fimage%2F83405746-0620-4728-9358-5f51b040ffee.gif "emoji party-blob")"# ) ]; diff --git a/crates/utils/src/utils/markdown/mod.rs b/crates/utils/src/utils/markdown/mod.rs index 3dfa8e9f19..ba509596ef 100644 --- a/crates/utils/src/utils/markdown/mod.rs +++ b/crates/utils/src/utils/markdown/mod.rs @@ -141,7 +141,7 @@ mod tests { ( "remote image proxied", "![link](http://example.com/image.jpg)", - "![link](https://lemmy-alpha/api/v3/image_proxy?url=http%3A%2F%2Fexample.com%2Fimage.jpg)", + "![link](https://lemmy-alpha/api/v4/image_proxy?url=http%3A%2F%2Fexample.com%2Fimage.jpg)", ), ( "local image unproxied", @@ -151,7 +151,7 @@ mod tests { ( "multiple image links", "![link](http://example.com/image1.jpg) ![link](http://example.com/image2.jpg)", - "![link](https://lemmy-alpha/api/v3/image_proxy?url=http%3A%2F%2Fexample.com%2Fimage1.jpg) ![link](https://lemmy-alpha/api/v3/image_proxy?url=http%3A%2F%2Fexample.com%2Fimage2.jpg)", + "![link](https://lemmy-alpha/api/v4/image_proxy?url=http%3A%2F%2Fexample.com%2Fimage1.jpg) ![link](https://lemmy-alpha/api/v4/image_proxy?url=http%3A%2F%2Fexample.com%2Fimage2.jpg)", ), ( "empty link handled", @@ -161,7 +161,7 @@ mod tests { ( "empty label handled", "![](http://example.com/image.jpg)", - "![](https://lemmy-alpha/api/v3/image_proxy?url=http%3A%2F%2Fexample.com%2Fimage.jpg)" + "![](https://lemmy-alpha/api/v4/image_proxy?url=http%3A%2F%2Fexample.com%2Fimage.jpg)" ), ( "invalid image link removed", @@ -171,12 +171,12 @@ mod tests { ( "label with nested markdown handled", "![a *b* c](http://example.com/image.jpg)", - "![a *b* c](https://lemmy-alpha/api/v3/image_proxy?url=http%3A%2F%2Fexample.com%2Fimage.jpg)" + "![a *b* c](https://lemmy-alpha/api/v4/image_proxy?url=http%3A%2F%2Fexample.com%2Fimage.jpg)" ), ( "custom emoji support", r#"![party-blob](https://www.hexbear.net/pictrs/image/83405746-0620-4728-9358-5f51b040ffee.gif "emoji party-blob")"#, - r#"![party-blob](https://lemmy-alpha/api/v3/image_proxy?url=https%3A%2F%2Fwww.hexbear.net%2Fpictrs%2Fimage%2F83405746-0620-4728-9358-5f51b040ffee.gif "emoji party-blob")"# + r#"![party-blob](https://lemmy-alpha/api/v4/image_proxy?url=https%3A%2F%2Fwww.hexbear.net%2Fpictrs%2Fimage%2F83405746-0620-4728-9358-5f51b040ffee.gif "emoji party-blob")"# ) ]; diff --git a/src/api_routes_v4.rs b/src/api_routes_v4.rs index 42f25628fb..a25c03bca6 100644 --- a/src/api_routes_v4.rs +++ b/src/api_routes_v4.rs @@ -162,7 +162,7 @@ use lemmy_utils::rate_limit::RateLimitCell; pub fn config(cfg: &mut web::ServiceConfig, rate_limit: &RateLimitCell) { cfg.service( - web::scope("/api/v3") + web::scope("/api/v4") .wrap(rate_limit.message()) .route("/image_proxy", web::get().to(image_proxy)) // Site @@ -283,11 +283,11 @@ pub fn config(cfg: &mut web::ServiceConfig, rate_limit: &RateLimitCell) { web::scope("/account/auth") .guard(guard::Post()) .wrap(rate_limit.register()) - .route("register", web::post().to(register)) - .route("login", web::post().to(login)) + .route("/register", web::post().to(register)) + .route("/login", web::post().to(login)) .route("/logout", web::post().to(logout)) - .route("password_reset", web::post().to(reset_password)) - .route("get_captcha", web::get().to(get_captcha)) + .route("/password_reset", web::post().to(reset_password)) + .route("/get_captcha", web::get().to(get_captcha)) .route( "/password_change", web::post().to(change_password_after_reset), From 0583505320dc130e1830e9d0d02b4131343dc231 Mon Sep 17 00:00:00 2001 From: Felix Ableitner Date: Thu, 28 Nov 2024 12:05:15 +0100 Subject: [PATCH 12/26] replace getSite().my_user with getMyUser() --- api_tests/package.json | 2 +- api_tests/pnpm-lock.yaml | 10 ++++----- api_tests/src/comment.spec.ts | 4 ++-- api_tests/src/community.spec.ts | 3 ++- api_tests/src/follow.spec.ts | 9 ++++---- api_tests/src/image.spec.ts | 5 +++-- api_tests/src/post.spec.ts | 7 +++--- api_tests/src/shared.ts | 14 +++++++----- api_tests/src/user.spec.ts | 39 +++++++++++++++------------------ crates/api_common/src/site.rs | 2 +- 10 files changed, 50 insertions(+), 45 deletions(-) diff --git a/api_tests/package.json b/api_tests/package.json index 90e63a1e7a..dffa7d44fe 100644 --- a/api_tests/package.json +++ b/api_tests/package.json @@ -28,7 +28,7 @@ "eslint": "^9.14.0", "eslint-plugin-prettier": "^5.1.3", "jest": "^29.5.0", - "lemmy-js-client": "0.20.0-api-v4.0", + "lemmy-js-client": "0.20.0-api-v4.5", "prettier": "^3.2.5", "ts-jest": "^29.1.0", "typescript": "^5.5.4", diff --git a/api_tests/pnpm-lock.yaml b/api_tests/pnpm-lock.yaml index 2ecf2a2213..a7d8690ec4 100644 --- a/api_tests/pnpm-lock.yaml +++ b/api_tests/pnpm-lock.yaml @@ -30,8 +30,8 @@ importers: specifier: ^29.5.0 version: 29.7.0(@types/node@22.9.0) lemmy-js-client: - specifier: 0.20.0-api-v4.0 - version: 0.20.0-api-v4.0 + specifier: 0.20.0-api-v4.5 + version: 0.20.0-api-v4.5 prettier: specifier: ^3.2.5 version: 3.3.3 @@ -1167,8 +1167,8 @@ packages: resolution: {integrity: sha512-eTIzlVOSUR+JxdDFepEYcBMtZ9Qqdef+rnzWdRZuMbOywu5tO2w2N7rqjoANZ5k9vywhL6Br1VRjUIgTQx4E8w==} engines: {node: '>=6'} - lemmy-js-client@0.20.0-api-v4.0: - resolution: {integrity: sha512-oS02mNzLYWcDIk3FJj1YvBmgpZJQWr34uuxharPd5jQyU8/Yub4XNHrQnjPX5wrXEC6am5ebR8iQmRuQsPQDmw==} + lemmy-js-client@0.20.0-api-v4.5: + resolution: {integrity: sha512-8Zdjb+oIYMUa5/hvS2zeGoIPLdjM+BODUCvP3/jAA/ipqEiSerJ9BdfIB61cnDE9gXnmjYvEtxnfqRZLlwdLfQ==} leven@3.1.0: resolution: {integrity: sha512-qsda+H8jTaUaN/x5vzW2rzc+8Rw4TAQ/4KjB46IwK5VH+IlVeeeje/EoZRpiXvIqjFgK84QffqPztGI3VBLG1A==} @@ -3077,7 +3077,7 @@ snapshots: kleur@3.0.3: {} - lemmy-js-client@0.20.0-api-v4.0: {} + lemmy-js-client@0.20.0-api-v4.5: {} leven@3.1.0: {} diff --git a/api_tests/src/comment.spec.ts b/api_tests/src/comment.spec.ts index c3f4b3efea..6c8595db64 100644 --- a/api_tests/src/comment.spec.ts +++ b/api_tests/src/comment.spec.ts @@ -702,9 +702,9 @@ test("Check that activity from another instance is sent to third instance", asyn test("Fetch in_reply_tos: A is unsubbed from B, B makes a post, and some embedded comments, A subs to B, B updates the lowest level comment, A fetches both the post and all the inreplyto comments for that post.", async () => { // Unfollow all remote communities - let site = await unfollowRemotes(alpha); + let my_user = await unfollowRemotes(alpha); expect( - site.my_user?.follows.filter(c => c.community.local == false).length, + my_user.follows.filter(c => c.community.local == false).length, ).toBe(0); // B creates a post, and two comments, should be invisible to A diff --git a/api_tests/src/community.spec.ts b/api_tests/src/community.spec.ts index 77b68e2fc5..9ccfb92a05 100644 --- a/api_tests/src/community.spec.ts +++ b/api_tests/src/community.spec.ts @@ -34,6 +34,7 @@ import { longDelay, editCommunity, unfollows, + getMyUser, } from "./shared"; import { EditCommunity, EditSite } from "lemmy-js-client"; @@ -226,7 +227,7 @@ test("Admin actions in remote community are not federated to origin", async () = if (!betaCommunity) { throw "Missing beta community"; } - let bannedUserInfo1 = (await getSite(gamma)).my_user?.local_user_view.person; + let bannedUserInfo1 = (await getMyUser(gamma)).local_user_view.person; if (!bannedUserInfo1) { throw "Missing banned user 1"; } diff --git a/api_tests/src/follow.spec.ts b/api_tests/src/follow.spec.ts index 22fdfa305d..936ce26065 100644 --- a/api_tests/src/follow.spec.ts +++ b/api_tests/src/follow.spec.ts @@ -12,6 +12,7 @@ import { registerUser, unfollows, delay, + getMyUser, } from "./shared"; beforeAll(setupLogins); @@ -85,8 +86,8 @@ test("Follow federated community", async () => { ); // Check it from local - let site = await getSite(alpha); - let remoteCommunityId = site.my_user?.follows.find( + let my_user = await getMyUser(alpha); + let remoteCommunityId = my_user?.follows.find( c => c.community.local == false && c.community.id === betaCommunityInitial.community.id, @@ -102,9 +103,9 @@ test("Follow federated community", async () => { expect(unfollow.community_view.subscribed).toBe("NotSubscribed"); // Make sure you are unsubbed locally - let siteUnfollowCheck = await getSite(alpha); + let siteUnfollowCheck = await getMyUser(alpha); expect( - siteUnfollowCheck.my_user?.follows.find( + siteUnfollowCheck.follows.find( c => c.community.id === betaCommunityInitial.community.id, ), ).toBe(undefined); diff --git a/api_tests/src/image.spec.ts b/api_tests/src/image.spec.ts index ede04294d6..a3478081ad 100644 --- a/api_tests/src/image.spec.ts +++ b/api_tests/src/image.spec.ts @@ -32,6 +32,7 @@ import { createPostWithThumbnail, sampleImage, sampleSite, + getMyUser, } from "./shared"; beforeAll(setupLogins); @@ -129,9 +130,9 @@ test("Purge user, uploaded image removed", async () => { expect(content.length).toBeGreaterThan(0); // purge user - let site = await getSite(user); + let my_user = await getMyUser(user); const purgeForm: PurgePerson = { - person_id: site.my_user!.local_user_view.person.id, + person_id: my_user.local_user_view.person.id, }; const delete_ = await alphaImage.purgePerson(purgeForm); expect(delete_.success).toBe(true); diff --git a/api_tests/src/post.spec.ts b/api_tests/src/post.spec.ts index 59e3d774e2..ce8c0ae93e 100644 --- a/api_tests/src/post.spec.ts +++ b/api_tests/src/post.spec.ts @@ -38,6 +38,7 @@ import { alphaUrl, loginUser, createCommunity, + getMyUser, } from "./shared"; import { PostView } from "lemmy-js-client/dist/types/PostView"; import { EditSite, ResolveObject } from "lemmy-js-client"; @@ -452,7 +453,7 @@ test("Enforce site ban federation for local user", async () => { // create a test user let alphaUserHttp = await registerUser(alpha, alphaUrl); - let alphaUserPerson = (await getSite(alphaUserHttp)).my_user?.local_user_view + let alphaUserPerson = (await getMyUser(alphaUserHttp)).local_user_view .person; let alphaUserActorId = alphaUserPerson?.actor_id; if (!alphaUserActorId) { @@ -533,7 +534,7 @@ test("Enforce site ban federation for federated user", async () => { // create a test user let alphaUserHttp = await registerUser(alpha, alphaUrl); - let alphaUserPerson = (await getSite(alphaUserHttp)).my_user?.local_user_view + let alphaUserPerson = (await getMyUser(alphaUserHttp)).local_user_view .person; let alphaUserActorId = alphaUserPerson?.actor_id; if (!alphaUserActorId) { @@ -564,7 +565,7 @@ test("Enforce site ban federation for federated user", async () => { expect(banAlphaOnBeta.banned).toBe(true); // The beta site ban should NOT be federated to alpha - let alphaPerson2 = (await getSite(alphaUserHttp)).my_user!.local_user_view + let alphaPerson2 = (await getMyUser(alphaUserHttp)).local_user_view .person; expect(alphaPerson2.banned).toBe(false); diff --git a/api_tests/src/shared.ts b/api_tests/src/shared.ts index 0b0a9862c5..f7b0acd5e7 100644 --- a/api_tests/src/shared.ts +++ b/api_tests/src/shared.ts @@ -17,6 +17,7 @@ import { LemmyHttp, ListCommunityPendingFollows, ListCommunityPendingFollowsResponse, + MyUserInfo, PersonId, PostView, PrivateMessageReportResponse, @@ -757,6 +758,10 @@ export async function getSite(api: LemmyHttp): Promise { return api.getSite(); } +export async function getMyUser(api: LemmyHttp): Promise { + return api.getMyUser(); +} + export async function listPrivateMessages( api: LemmyHttp, ): Promise { @@ -768,17 +773,16 @@ export async function listPrivateMessages( export async function unfollowRemotes( api: LemmyHttp, -): Promise { +): Promise { // Unfollow all remote communities - let site = await getSite(api); + let my_user = await getMyUser(api); let remoteFollowed = - site.my_user?.follows.filter(c => c.community.local == false) ?? []; + my_user.follows.filter(c => c.community.local == false) ?? []; await Promise.all( remoteFollowed.map(cu => followCommunity(api, false, cu.community.id)), ); - let siteRes = await getSite(api); - return siteRes; + return await getMyUser(api); } export async function followBeta(api: LemmyHttp): Promise { diff --git a/api_tests/src/user.spec.ts b/api_tests/src/user.spec.ts index 2edcf54ea8..944764ef10 100644 --- a/api_tests/src/user.spec.ts +++ b/api_tests/src/user.spec.ts @@ -22,6 +22,7 @@ import { alphaImage, unfollows, saveUserSettingsBio, + getMyUser, } from "./shared"; import { LemmyHttp, SaveUserSettings, UploadImage } from "lemmy-js-client"; import { GetPosts } from "lemmy-js-client/dist/types/GetPosts"; @@ -44,12 +45,9 @@ function assertUserFederation(userOne?: PersonView, userTwo?: PersonView) { test("Create user", async () => { let user = await registerUser(alpha, alphaUrl); - let site = await getSite(user); - expect(site.my_user).toBeDefined(); - if (!site.my_user) { - throw "Missing site user"; - } - apShortname = `${site.my_user.local_user_view.person.name}@lemmy-alpha:8541`; + let my_user = await getMyUser(user); + expect(my_user).toBeDefined(); + apShortname = `${my_user.local_user_view.person.name}@lemmy-alpha:8541`; }); test("Set some user settings, check that they are federated", async () => { @@ -64,8 +62,8 @@ test("Set some user settings, check that they are federated", async () => { }; await saveUserSettings(beta, form); - let site = await getSite(beta); - expect(site.my_user?.local_user_view.local_user.theme).toBe("test"); + let my_user = await getMyUser(beta); + expect(my_user.local_user_view.local_user.theme).toBe("test"); }); test("Delete user", async () => { @@ -121,8 +119,9 @@ test("Requests with invalid auth should be treated as unauthenticated", async () headers: { Authorization: "Bearer foobar" }, fetchFunction, }); + let my_user = await getMyUser(invalid_auth); + expect(my_user).toBeUndefined(); let site = await getSite(invalid_auth); - expect(site.my_user).toBeUndefined(); expect(site.site_view).toBeDefined(); let form: GetPosts = {}; @@ -137,12 +136,9 @@ test("Create user with Arabic name", async () => { "تجريب" + Math.random().toString().slice(2, 10), // less than actor_name_max_length ); - let site = await getSite(user); - expect(site.my_user).toBeDefined(); - if (!site.my_user) { - throw "Missing site user"; - } - apShortname = `${site.my_user.local_user_view.person.name}@lemmy-alpha:8541`; + let my_user = await getMyUser(user); + expect(my_user).toBeDefined(); + apShortname = `${my_user.local_user_view.person.name}@lemmy-alpha:8541`; let alphaPerson = (await resolvePerson(alpha, apShortname)).person; expect(alphaPerson).toBeDefined(); @@ -155,13 +151,14 @@ test("Create user with accept-language", async () => { }); let user = await registerUser(lemmy_http, alphaUrl); - let site = await getSite(user); - expect(site.my_user).toBeDefined(); - expect(site.my_user?.local_user_view.local_user.interface_language).toBe( + let my_user = await getMyUser(user); + expect(my_user).toBeDefined(); + expect(my_user?.local_user_view.local_user.interface_language).toBe( "fr", ); + let site = await getSite(user); let langs = site.all_languages - .filter(a => site.my_user?.discussion_languages.includes(a.id)) + .filter(a => my_user.discussion_languages.includes(a.id)) .map(l => l.code); // should have languages from accept header, as well as "undetermined" // which is automatically enabled by backend @@ -207,8 +204,8 @@ test("Set a new avatar, old avatar is deleted", async () => { // Now try to save a user settings, with the icon missing, // and make sure it doesn't clear the data, or delete the image await saveUserSettingsBio(alpha); - let site = await getSite(alpha); - expect(site.my_user?.local_user_view.person.avatar).toBe(upload2.url); + let my_user = await getMyUser(alpha); + expect(my_user.local_user_view.person.avatar).toBe(upload2.url); // make sure only the new avatar is kept const listMediaRes4 = await alphaImage.listMedia(); diff --git a/crates/api_common/src/site.rs b/crates/api_common/src/site.rs index 68aedc49e9..84d5c4e349 100644 --- a/crates/api_common/src/site.rs +++ b/crates/api_common/src/site.rs @@ -448,7 +448,7 @@ pub struct GetSiteResponse { pub site_view: SiteView, pub admins: Vec, pub version: String, - #[cfg_attr(feature = "full", ts(optional))] + #[cfg_attr(feature = "full", ts(skip))] pub my_user: Option, pub all_languages: Vec, pub discussion_languages: Vec, From 6eaa569d13a9c973477643c34ee57b3390a38856 Mon Sep 17 00:00:00 2001 From: Felix Ableitner Date: Thu, 28 Nov 2024 12:17:48 +0100 Subject: [PATCH 13/26] update --- api_tests/package.json | 2 +- api_tests/src/comment.spec.ts | 6 +++--- api_tests/src/post.spec.ts | 9 +++------ api_tests/src/shared.ts | 4 +--- api_tests/src/user.spec.ts | 4 +--- 5 files changed, 9 insertions(+), 16 deletions(-) diff --git a/api_tests/package.json b/api_tests/package.json index dffa7d44fe..0c8e8990b6 100644 --- a/api_tests/package.json +++ b/api_tests/package.json @@ -28,7 +28,7 @@ "eslint": "^9.14.0", "eslint-plugin-prettier": "^5.1.3", "jest": "^29.5.0", - "lemmy-js-client": "0.20.0-api-v4.5", + "lemmy-js-client": "0.20.0-api-v4.6", "prettier": "^3.2.5", "ts-jest": "^29.1.0", "typescript": "^5.5.4", diff --git a/api_tests/src/comment.spec.ts b/api_tests/src/comment.spec.ts index 6c8595db64..4a179009d2 100644 --- a/api_tests/src/comment.spec.ts +++ b/api_tests/src/comment.spec.ts @@ -703,9 +703,9 @@ test("Check that activity from another instance is sent to third instance", asyn test("Fetch in_reply_tos: A is unsubbed from B, B makes a post, and some embedded comments, A subs to B, B updates the lowest level comment, A fetches both the post and all the inreplyto comments for that post.", async () => { // Unfollow all remote communities let my_user = await unfollowRemotes(alpha); - expect( - my_user.follows.filter(c => c.community.local == false).length, - ).toBe(0); + expect(my_user.follows.filter(c => c.community.local == false).length).toBe( + 0, + ); // B creates a post, and two comments, should be invisible to A let postOnBetaRes = await createPost(beta, 2); diff --git a/api_tests/src/post.spec.ts b/api_tests/src/post.spec.ts index ce8c0ae93e..17a1a26996 100644 --- a/api_tests/src/post.spec.ts +++ b/api_tests/src/post.spec.ts @@ -453,8 +453,7 @@ test("Enforce site ban federation for local user", async () => { // create a test user let alphaUserHttp = await registerUser(alpha, alphaUrl); - let alphaUserPerson = (await getMyUser(alphaUserHttp)).local_user_view - .person; + let alphaUserPerson = (await getMyUser(alphaUserHttp)).local_user_view.person; let alphaUserActorId = alphaUserPerson?.actor_id; if (!alphaUserActorId) { throw "Missing alpha user actor id"; @@ -534,8 +533,7 @@ test("Enforce site ban federation for federated user", async () => { // create a test user let alphaUserHttp = await registerUser(alpha, alphaUrl); - let alphaUserPerson = (await getMyUser(alphaUserHttp)).local_user_view - .person; + let alphaUserPerson = (await getMyUser(alphaUserHttp)).local_user_view.person; let alphaUserActorId = alphaUserPerson?.actor_id; if (!alphaUserActorId) { throw "Missing alpha user actor id"; @@ -565,8 +563,7 @@ test("Enforce site ban federation for federated user", async () => { expect(banAlphaOnBeta.banned).toBe(true); // The beta site ban should NOT be federated to alpha - let alphaPerson2 = (await getMyUser(alphaUserHttp)).local_user_view - .person; + let alphaPerson2 = (await getMyUser(alphaUserHttp)).local_user_view.person; expect(alphaPerson2.banned).toBe(false); // existing alpha post should be removed on beta diff --git a/api_tests/src/shared.ts b/api_tests/src/shared.ts index f7b0acd5e7..b348573af4 100644 --- a/api_tests/src/shared.ts +++ b/api_tests/src/shared.ts @@ -771,9 +771,7 @@ export async function listPrivateMessages( return api.getPrivateMessages(form); } -export async function unfollowRemotes( - api: LemmyHttp, -): Promise { +export async function unfollowRemotes(api: LemmyHttp): Promise { // Unfollow all remote communities let my_user = await getMyUser(api); let remoteFollowed = diff --git a/api_tests/src/user.spec.ts b/api_tests/src/user.spec.ts index 944764ef10..cee3947ff6 100644 --- a/api_tests/src/user.spec.ts +++ b/api_tests/src/user.spec.ts @@ -153,9 +153,7 @@ test("Create user with accept-language", async () => { let my_user = await getMyUser(user); expect(my_user).toBeDefined(); - expect(my_user?.local_user_view.local_user.interface_language).toBe( - "fr", - ); + expect(my_user?.local_user_view.local_user.interface_language).toBe("fr"); let site = await getSite(user); let langs = site.all_languages .filter(a => my_user.discussion_languages.includes(a.id)) From a7942e53a0c3947e8eb194cad26567184d354c97 Mon Sep 17 00:00:00 2001 From: Felix Ableitner Date: Thu, 28 Nov 2024 15:49:15 +0100 Subject: [PATCH 14/26] update config --- api_tests/pnpm-lock.yaml | 10 +++++----- config/defaults.hjson | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/api_tests/pnpm-lock.yaml b/api_tests/pnpm-lock.yaml index a7d8690ec4..192c89e400 100644 --- a/api_tests/pnpm-lock.yaml +++ b/api_tests/pnpm-lock.yaml @@ -30,8 +30,8 @@ importers: specifier: ^29.5.0 version: 29.7.0(@types/node@22.9.0) lemmy-js-client: - specifier: 0.20.0-api-v4.5 - version: 0.20.0-api-v4.5 + specifier: 0.20.0-api-v4.6 + version: 0.20.0-api-v4.6 prettier: specifier: ^3.2.5 version: 3.3.3 @@ -1167,8 +1167,8 @@ packages: resolution: {integrity: sha512-eTIzlVOSUR+JxdDFepEYcBMtZ9Qqdef+rnzWdRZuMbOywu5tO2w2N7rqjoANZ5k9vywhL6Br1VRjUIgTQx4E8w==} engines: {node: '>=6'} - lemmy-js-client@0.20.0-api-v4.5: - resolution: {integrity: sha512-8Zdjb+oIYMUa5/hvS2zeGoIPLdjM+BODUCvP3/jAA/ipqEiSerJ9BdfIB61cnDE9gXnmjYvEtxnfqRZLlwdLfQ==} + lemmy-js-client@0.20.0-api-v4.6: + resolution: {integrity: sha512-+M2kbk0a4beJ5Jpn2I0DBEqF7IHz90Mvl5q85EeaexhsdQvfRzhMi+OmViy6SY9qUEjEYAN5eJJKu479T/My0w==} leven@3.1.0: resolution: {integrity: sha512-qsda+H8jTaUaN/x5vzW2rzc+8Rw4TAQ/4KjB46IwK5VH+IlVeeeje/EoZRpiXvIqjFgK84QffqPztGI3VBLG1A==} @@ -3077,7 +3077,7 @@ snapshots: kleur@3.0.3: {} - lemmy-js-client@0.20.0-api-v4.5: {} + lemmy-js-client@0.20.0-api-v4.6: {} leven@3.1.0: {} diff --git a/config/defaults.hjson b/config/defaults.hjson index c12f879c70..00d5780a2d 100644 --- a/config/defaults.hjson +++ b/config/defaults.hjson @@ -66,7 +66,7 @@ # or # If enabled, all images from remote domains are rewritten to pass through - # `/api/v3/image_proxy`, including embedded images in markdown. Images are stored temporarily + # `/api/v4/image_proxy`, including embedded images in markdown. Images are stored temporarily # in pict-rs for caching. This improves privacy as users don't expose their IP to untrusted # servers, and decreases load on other servers. However it increases bandwidth use for the # local server. From 8ac9e2b2d468694eada268402a235dffd973f90d Mon Sep 17 00:00:00 2001 From: Felix Ableitner Date: Thu, 28 Nov 2024 15:56:34 +0100 Subject: [PATCH 15/26] remove web:: --- src/api_routes_v3.rs | 264 ++++++++++++++++++++-------------------- src/api_routes_v4.rs | 278 +++++++++++++++++++++---------------------- 2 files changed, 268 insertions(+), 274 deletions(-) diff --git a/src/api_routes_v3.rs b/src/api_routes_v3.rs index 65d50e1b6f..a10f885eeb 100644 --- a/src/api_routes_v3.rs +++ b/src/api_routes_v3.rs @@ -1,4 +1,4 @@ -use actix_web::{guard, web}; +use actix_web::{guard, web::*}; use lemmy_api::{ comment::{ distinguish::distinguish_comment, @@ -137,137 +137,137 @@ use lemmy_apub::api::{ use lemmy_routes::images::image_proxy; use lemmy_utils::rate_limit::RateLimitCell; -pub fn config(cfg: &mut web::ServiceConfig, rate_limit: &RateLimitCell) { +pub fn config(cfg: &mut ServiceConfig, rate_limit: &RateLimitCell) { cfg.service( - web::scope("/api/v3") - .route("/image_proxy", web::get().to(image_proxy)) + scope("/api/v3") + .route("/image_proxy", get().to(image_proxy)) // Site .service( - web::scope("/site") + scope("/site") .wrap(rate_limit.message()) - .route("", web::get().to(get_site_v3)) + .route("", get().to(get_site_v3)) // Admin Actions - .route("", web::post().to(create_site)) - .route("", web::put().to(update_site)) - .route("/block", web::post().to(block_instance)), + .route("", post().to(create_site)) + .route("", put().to(update_site)) + .route("/block", post().to(block_instance)), ) .service( - web::resource("/modlog") + resource("/modlog") .wrap(rate_limit.message()) - .route(web::get().to(get_mod_log)), + .route(get().to(get_mod_log)), ) .service( - web::resource("/search") + resource("/search") .wrap(rate_limit.search()) - .route(web::get().to(search)), + .route(get().to(search)), ) .service( - web::resource("/resolve_object") + resource("/resolve_object") .wrap(rate_limit.message()) - .route(web::get().to(resolve_object)), + .route(get().to(resolve_object)), ) // Community .service( - web::resource("/community") + resource("/community") .guard(guard::Post()) .wrap(rate_limit.register()) - .route(web::post().to(create_community)), + .route(post().to(create_community)), ) .service( - web::scope("/community") + scope("/community") .wrap(rate_limit.message()) - .route("", web::get().to(get_community)) - .route("", web::put().to(update_community)) - .route("/hide", web::put().to(hide_community)) - .route("/list", web::get().to(list_communities)) - .route("/follow", web::post().to(follow_community)) - .route("/block", web::post().to(block_community)) - .route("/delete", web::post().to(delete_community)) + .route("", get().to(get_community)) + .route("", put().to(update_community)) + .route("/hide", put().to(hide_community)) + .route("/list", get().to(list_communities)) + .route("/follow", post().to(follow_community)) + .route("/block", post().to(block_community)) + .route("/delete", post().to(delete_community)) // Mod Actions - .route("/remove", web::post().to(remove_community)) - .route("/transfer", web::post().to(transfer_community)) - .route("/ban_user", web::post().to(ban_from_community)) - .route("/mod", web::post().to(add_mod_to_community)), + .route("/remove", post().to(remove_community)) + .route("/transfer", post().to(transfer_community)) + .route("/ban_user", post().to(ban_from_community)) + .route("/mod", post().to(add_mod_to_community)), ) .service( - web::scope("/federated_instances") + scope("/federated_instances") .wrap(rate_limit.message()) - .route("", web::get().to(get_federated_instances)), + .route("", get().to(get_federated_instances)), ) // Post .service( // Handle POST to /post separately to add the post() rate limitter - web::resource("/post") + resource("/post") .guard(guard::Post()) .wrap(rate_limit.post()) - .route(web::post().to(create_post)), + .route(post().to(create_post)), ) .service( - web::scope("/post") + scope("/post") .wrap(rate_limit.message()) - .route("", web::get().to(get_post)) - .route("", web::put().to(update_post)) - .route("/delete", web::post().to(delete_post)) - .route("/remove", web::post().to(remove_post)) - .route("/mark_as_read", web::post().to(mark_post_as_read)) - .route("/hide", web::post().to(hide_post)) - .route("/lock", web::post().to(lock_post)) - .route("/feature", web::post().to(feature_post)) - .route("/list", web::get().to(list_posts)) - .route("/like", web::post().to(like_post)) - .route("/like/list", web::get().to(list_post_likes)) - .route("/save", web::put().to(save_post)) - .route("/report", web::post().to(create_post_report)) - .route("/report/resolve", web::put().to(resolve_post_report)) - .route("/report/list", web::get().to(list_post_reports)) - .route("/site_metadata", web::get().to(get_link_metadata)), + .route("", get().to(get_post)) + .route("", put().to(update_post)) + .route("/delete", post().to(delete_post)) + .route("/remove", post().to(remove_post)) + .route("/mark_as_read", post().to(mark_post_as_read)) + .route("/hide", post().to(hide_post)) + .route("/lock", post().to(lock_post)) + .route("/feature", post().to(feature_post)) + .route("/list", get().to(list_posts)) + .route("/like", post().to(like_post)) + .route("/like/list", get().to(list_post_likes)) + .route("/save", put().to(save_post)) + .route("/report", post().to(create_post_report)) + .route("/report/resolve", put().to(resolve_post_report)) + .route("/report/list", get().to(list_post_reports)) + .route("/site_metadata", get().to(get_link_metadata)), ) // Comment .service( // Handle POST to /comment separately to add the comment() rate limitter - web::resource("/comment") + resource("/comment") .guard(guard::Post()) .wrap(rate_limit.comment()) - .route(web::post().to(create_comment)), + .route(post().to(create_comment)), ) .service( - web::scope("/comment") + scope("/comment") .wrap(rate_limit.message()) - .route("", web::get().to(get_comment)) - .route("", web::put().to(update_comment)) - .route("/delete", web::post().to(delete_comment)) - .route("/remove", web::post().to(remove_comment)) - .route("/mark_as_read", web::post().to(mark_reply_as_read)) - .route("/distinguish", web::post().to(distinguish_comment)) - .route("/like", web::post().to(like_comment)) - .route("/like/list", web::get().to(list_comment_likes)) - .route("/save", web::put().to(save_comment)) - .route("/list", web::get().to(list_comments)) - .route("/report", web::post().to(create_comment_report)) - .route("/report/resolve", web::put().to(resolve_comment_report)) - .route("/report/list", web::get().to(list_comment_reports)), + .route("", get().to(get_comment)) + .route("", put().to(update_comment)) + .route("/delete", post().to(delete_comment)) + .route("/remove", post().to(remove_comment)) + .route("/mark_as_read", post().to(mark_reply_as_read)) + .route("/distinguish", post().to(distinguish_comment)) + .route("/like", post().to(like_comment)) + .route("/like/list", get().to(list_comment_likes)) + .route("/save", put().to(save_comment)) + .route("/list", get().to(list_comments)) + .route("/report", post().to(create_comment_report)) + .route("/report/resolve", put().to(resolve_comment_report)) + .route("/report/list", get().to(list_comment_reports)), ) // Private Message .service( - web::scope("/private_message") + scope("/private_message") .wrap(rate_limit.message()) - .route("/list", web::get().to(get_private_message)) - .route("", web::post().to(create_private_message)) - .route("", web::put().to(update_private_message)) - .route("/delete", web::post().to(delete_private_message)) - .route("/mark_as_read", web::post().to(mark_pm_as_read)) - .route("/report", web::post().to(create_pm_report)) - .route("/report/resolve", web::put().to(resolve_pm_report)) - .route("/report/list", web::get().to(list_pm_reports)), + .route("/list", get().to(get_private_message)) + .route("", post().to(create_private_message)) + .route("", put().to(update_private_message)) + .route("/delete", post().to(delete_private_message)) + .route("/mark_as_read", post().to(mark_pm_as_read)) + .route("/report", post().to(create_pm_report)) + .route("/report/resolve", put().to(resolve_pm_report)) + .route("/report/list", get().to(list_pm_reports)), ) // User .service( // Account action, I don't like that it's in /user maybe /accounts // Handle /user/register separately to add the register() rate limiter - web::resource("/user/register") + resource("/user/register") .guard(guard::Post()) .wrap(rate_limit.register()) - .route(web::post().to(register)), + .route(post().to(register)), ) // User .service( @@ -275,117 +275,111 @@ pub fn config(cfg: &mut web::ServiceConfig, rate_limit: &RateLimitCell) { // TODO: pretty annoying way to apply rate limits for register and login, we should // group them under a common path so that rate limit is only applied once (eg under // /account). - web::resource("/user/login") + resource("/user/login") .guard(guard::Post()) .wrap(rate_limit.register()) - .route(web::post().to(login)), + .route(post().to(login)), ) .service( - web::resource("/user/password_reset") + resource("/user/password_reset") .wrap(rate_limit.register()) - .route(web::post().to(reset_password)), + .route(post().to(reset_password)), ) .service( // Handle captcha separately - web::resource("/user/get_captcha") + resource("/user/get_captcha") .wrap(rate_limit.post()) - .route(web::get().to(get_captcha)), + .route(get().to(get_captcha)), ) .service( - web::resource("/user/export_settings") + resource("/user/export_settings") .wrap(rate_limit.import_user_settings()) - .route(web::get().to(export_settings)), + .route(get().to(export_settings)), ) .service( - web::resource("/user/import_settings") + resource("/user/import_settings") .wrap(rate_limit.import_user_settings()) - .route(web::post().to(import_settings)), + .route(post().to(import_settings)), ) // TODO, all the current account related actions under /user need to get moved here eventually .service( - web::scope("/account") + scope("/account") .wrap(rate_limit.message()) - .route("/list_media", web::get().to(list_media)), + .route("/list_media", get().to(list_media)), ) // User actions .service( - web::scope("/user") + scope("/user") .wrap(rate_limit.message()) - .route("", web::get().to(read_person)) - .route("/mention", web::get().to(list_mentions)) + .route("", get().to(read_person)) + .route("/mention", get().to(list_mentions)) .route( "/mention/mark_as_read", - web::post().to(mark_person_mention_as_read), + post().to(mark_person_mention_as_read), ) - .route("/replies", web::get().to(list_replies)) + .route("/replies", get().to(list_replies)) // Admin action. I don't like that it's in /user - .route("/ban", web::post().to(ban_from_site)) - .route("/banned", web::get().to(list_banned_users)) - .route("/block", web::post().to(block_person)) + .route("/ban", post().to(ban_from_site)) + .route("/banned", get().to(list_banned_users)) + .route("/block", post().to(block_person)) // TODO Account actions. I don't like that they're in /user maybe /accounts - .route("/logout", web::post().to(logout)) - .route("/delete_account", web::post().to(delete_account)) - .route( - "/password_change", - web::post().to(change_password_after_reset), - ) + .route("/logout", post().to(logout)) + .route("/delete_account", post().to(delete_account)) + .route("/password_change", post().to(change_password_after_reset)) // TODO mark_all_as_read feels off being in this section as well - .route( - "/mark_all_as_read", - web::post().to(mark_all_notifications_read), - ) - .route("/save_user_settings", web::put().to(save_user_settings)) - .route("/change_password", web::put().to(change_password)) - .route("/report_count", web::get().to(report_count)) - .route("/unread_count", web::get().to(unread_count)) - .route("/verify_email", web::post().to(verify_email)) - .route("/leave_admin", web::post().to(leave_admin)) - .route("/totp/generate", web::post().to(generate_totp_secret)) - .route("/totp/update", web::post().to(update_totp)) - .route("/list_logins", web::get().to(list_logins)) - .route("/validate_auth", web::get().to(validate_auth)), + .route("/mark_all_as_read", post().to(mark_all_notifications_read)) + .route("/save_user_settings", put().to(save_user_settings)) + .route("/change_password", put().to(change_password)) + .route("/report_count", get().to(report_count)) + .route("/unread_count", get().to(unread_count)) + .route("/verify_email", post().to(verify_email)) + .route("/leave_admin", post().to(leave_admin)) + .route("/totp/generate", post().to(generate_totp_secret)) + .route("/totp/update", post().to(update_totp)) + .route("/list_logins", get().to(list_logins)) + .route("/validate_auth", get().to(validate_auth)), ) // Admin Actions .service( - web::scope("/admin") + scope("/admin") .wrap(rate_limit.message()) - .route("/add", web::post().to(add_admin)) + .route("/add", post().to(add_admin)) .route( "/registration_application/count", - web::get().to(get_unread_registration_application_count), + get().to(get_unread_registration_application_count), ) .route( "/registration_application/list", - web::get().to(list_registration_applications), + get().to(list_registration_applications), ) .route( "/registration_application/approve", - web::put().to(approve_registration_application), + put().to(approve_registration_application), ) .route( "/registration_application", - web::get().to(get_registration_application), + get().to(get_registration_application), ) - .route("/list_all_media", web::get().to(list_all_media)) + .route("/list_all_media", get().to(list_all_media)) .service( - web::scope("/purge") - .route("/person", web::post().to(purge_person)) - .route("/community", web::post().to(purge_community)) - .route("/post", web::post().to(purge_post)) - .route("/comment", web::post().to(purge_comment)), + scope("/purge") + .route("/person", post().to(purge_person)) + .route("/community", post().to(purge_community)) + .route("/post", post().to(purge_post)) + .route("/comment", post().to(purge_comment)), ), ) .service( - web::scope("/custom_emoji") + scope("/custom_emoji") .wrap(rate_limit.message()) - .route("", web::post().to(create_custom_emoji)) - .route("", web::put().to(update_custom_emoji)) - .route("/delete", web::post().to(delete_custom_emoji)), + .route("", post().to(create_custom_emoji)) + .route("", put().to(update_custom_emoji)) + .route("/delete", post().to(delete_custom_emoji)), ), ); cfg.service( - web::scope("/sitemap.xml") + scope("/sitemap.xml") .wrap(rate_limit.message()) - .route("", web::get().to(get_sitemap)), + .route("", get().to(get_sitemap)), ); } diff --git a/src/api_routes_v4.rs b/src/api_routes_v4.rs index a25c03bca6..21917134f8 100644 --- a/src/api_routes_v4.rs +++ b/src/api_routes_v4.rs @@ -1,4 +1,4 @@ -use actix_web::{guard, web}; +use actix_web::{guard, web::*}; use lemmy_api::{ comment::{ distinguish::distinguish_comment, @@ -160,230 +160,230 @@ use lemmy_apub::api::{ use lemmy_routes::images::image_proxy; use lemmy_utils::rate_limit::RateLimitCell; -pub fn config(cfg: &mut web::ServiceConfig, rate_limit: &RateLimitCell) { +pub fn config(cfg: &mut ServiceConfig, rate_limit: &RateLimitCell) { cfg.service( - web::scope("/api/v4") + scope("/api/v4") .wrap(rate_limit.message()) - .route("/image_proxy", web::get().to(image_proxy)) + .route("/image_proxy", get().to(image_proxy)) // Site .service( - web::scope("/site") - .route("", web::get().to(get_site_v4)) + scope("/site") + .route("", get().to(get_site_v4)) // Admin Actions - .route("", web::post().to(create_site)) - .route("", web::put().to(update_site)) - .route("/block", web::post().to(block_instance)), + .route("", post().to(create_site)) + .route("", put().to(update_site)) + .route("/block", post().to(block_instance)), ) - .route("/modlog", web::get().to(get_mod_log)) + .route("/modlog", get().to(get_mod_log)) .service( - web::resource("/search") + resource("/search") .wrap(rate_limit.search()) - .route(web::get().to(search)), + .route(get().to(search)), ) - .route("/resolve_object", web::get().to(resolve_object)) + .route("/resolve_object", get().to(resolve_object)) // Community .service( - web::resource("/community") + resource("/community") .guard(guard::Post()) .wrap(rate_limit.register()) - .route(web::post().to(create_community)), + .route(post().to(create_community)), ) .service( - web::scope("/community") - .route("", web::get().to(get_community)) - .route("", web::put().to(update_community)) - .route("/random", web::get().to(get_random_community)) - .route("/hide", web::put().to(hide_community)) - .route("/list", web::get().to(list_communities)) - .route("/follow", web::post().to(follow_community)) - .route("/block", web::post().to(block_community)) - .route("/delete", web::post().to(delete_community)) + scope("/community") + .route("", get().to(get_community)) + .route("", put().to(update_community)) + .route("/random", get().to(get_random_community)) + .route("/hide", put().to(hide_community)) + .route("/list", get().to(list_communities)) + .route("/follow", post().to(follow_community)) + .route("/block", post().to(block_community)) + .route("/delete", post().to(delete_community)) // Mod Actions - .route("/remove", web::post().to(remove_community)) - .route("/transfer", web::post().to(transfer_community)) - .route("/ban_user", web::post().to(ban_from_community)) - .route("/mod", web::post().to(add_mod_to_community)) + .route("/remove", post().to(remove_community)) + .route("/transfer", post().to(transfer_community)) + .route("/ban_user", post().to(ban_from_community)) + .route("/mod", post().to(add_mod_to_community)) .service( - web::scope("/pending_follows") - .route("/count", web::get().to(get_pending_follows_count)) - .route("/list", web::get().to(get_pending_follows_list)) - .route("/approve", web::post().to(post_pending_follows_approve)), + scope("/pending_follows") + .route("/count", get().to(get_pending_follows_count)) + .route("/list", get().to(get_pending_follows_list)) + .route("/approve", post().to(post_pending_follows_approve)), ), ) .route( "/federated_instances", - web::get().to(get_federated_instances), + get().to(get_federated_instances), ) // Post .service( // Handle POST to /post separately to add the post() rate limitter - web::resource("/post") + resource("/post") .guard(guard::Post()) .wrap(rate_limit.post()) - .route(web::post().to(create_post)), + .route(post().to(create_post)), ) .service( - web::scope("/post") - .route("", web::get().to(get_post)) - .route("", web::put().to(update_post)) - .route("/delete", web::post().to(delete_post)) - .route("/remove", web::post().to(remove_post)) - .route("/mark_as_read", web::post().to(mark_post_as_read)) - .route("/mark_many_as_read", web::post().to(mark_posts_as_read)) - .route("/hide", web::post().to(hide_post)) - .route("/lock", web::post().to(lock_post)) - .route("/feature", web::post().to(feature_post)) - .route("/list", web::get().to(list_posts)) - .route("/like", web::post().to(like_post)) - .route("/like/list", web::get().to(list_post_likes)) - .route("/save", web::put().to(save_post)) - .route("/report", web::post().to(create_post_report)) - .route("/report/resolve", web::put().to(resolve_post_report)) - .route("/report/list", web::get().to(list_post_reports)) - .route("/site_metadata", web::get().to(get_link_metadata)), + scope("/post") + .route("", get().to(get_post)) + .route("", put().to(update_post)) + .route("/delete", post().to(delete_post)) + .route("/remove", post().to(remove_post)) + .route("/mark_as_read", post().to(mark_post_as_read)) + .route("/mark_many_as_read", post().to(mark_posts_as_read)) + .route("/hide", post().to(hide_post)) + .route("/lock", post().to(lock_post)) + .route("/feature", post().to(feature_post)) + .route("/list", get().to(list_posts)) + .route("/like", post().to(like_post)) + .route("/like/list", get().to(list_post_likes)) + .route("/save", put().to(save_post)) + .route("/report", post().to(create_post_report)) + .route("/report/resolve", put().to(resolve_post_report)) + .route("/report/list", get().to(list_post_reports)) + .route("/site_metadata", get().to(get_link_metadata)), ) // Comment .service( // Handle POST to /comment separately to add the comment() rate limitter - web::resource("/comment") + resource("/comment") .guard(guard::Post()) .wrap(rate_limit.comment()) - .route(web::post().to(create_comment)), + .route(post().to(create_comment)), ) .service( - web::scope("/comment") - .route("", web::get().to(get_comment)) - .route("", web::put().to(update_comment)) - .route("/delete", web::post().to(delete_comment)) - .route("/remove", web::post().to(remove_comment)) - .route("/mark_as_read", web::post().to(mark_reply_as_read)) - .route("/distinguish", web::post().to(distinguish_comment)) - .route("/like", web::post().to(like_comment)) - .route("/like/list", web::get().to(list_comment_likes)) - .route("/save", web::put().to(save_comment)) - .route("/list", web::get().to(list_comments)) - .route("/report", web::post().to(create_comment_report)) - .route("/report/resolve", web::put().to(resolve_comment_report)) - .route("/report/list", web::get().to(list_comment_reports)), + scope("/comment") + .route("", get().to(get_comment)) + .route("", put().to(update_comment)) + .route("/delete", post().to(delete_comment)) + .route("/remove", post().to(remove_comment)) + .route("/mark_as_read", post().to(mark_reply_as_read)) + .route("/distinguish", post().to(distinguish_comment)) + .route("/like", post().to(like_comment)) + .route("/like/list", get().to(list_comment_likes)) + .route("/save", put().to(save_comment)) + .route("/list", get().to(list_comments)) + .route("/report", post().to(create_comment_report)) + .route("/report/resolve", put().to(resolve_comment_report)) + .route("/report/list", get().to(list_comment_reports)), ) // Private Message .service( - web::scope("/private_message") - .route("/list", web::get().to(get_private_message)) - .route("", web::post().to(create_private_message)) - .route("", web::put().to(update_private_message)) - .route("/delete", web::post().to(delete_private_message)) - .route("/mark_as_read", web::post().to(mark_pm_as_read)) - .route("/report", web::post().to(create_pm_report)) - .route("/report/resolve", web::put().to(resolve_pm_report)) - .route("/report/list", web::get().to(list_pm_reports)), + scope("/private_message") + .route("/list", get().to(get_private_message)) + .route("", post().to(create_private_message)) + .route("", put().to(update_private_message)) + .route("/delete", post().to(delete_private_message)) + .route("/mark_as_read", post().to(mark_pm_as_read)) + .route("/report", post().to(create_pm_report)) + .route("/report/resolve", put().to(resolve_pm_report)) + .route("/report/list", get().to(list_pm_reports)), ) // User .service( - web::scope("/account/auth") + scope("/account/auth") .guard(guard::Post()) .wrap(rate_limit.register()) - .route("/register", web::post().to(register)) - .route("/login", web::post().to(login)) - .route("/logout", web::post().to(logout)) - .route("/password_reset", web::post().to(reset_password)) - .route("/get_captcha", web::get().to(get_captcha)) + .route("/register", post().to(register)) + .route("/login", post().to(login)) + .route("/logout", post().to(logout)) + .route("/password_reset", post().to(reset_password)) + .route("/get_captcha", get().to(get_captcha)) .route( "/password_change", - web::post().to(change_password_after_reset), + post().to(change_password_after_reset), ) - .route("/change_password", web::put().to(change_password)) - .route("/totp/generate", web::post().to(generate_totp_secret)) - .route("/totp/update", web::post().to(update_totp)) - .route("/verify_email", web::post().to(verify_email)), + .route("/change_password", put().to(change_password)) + .route("/totp/generate", post().to(generate_totp_secret)) + .route("/totp/update", post().to(update_totp)) + .route("/verify_email", post().to(verify_email)), ) .service( - web::scope("/account/settings") + scope("/account/settings") .wrap(rate_limit.import_user_settings()) - .route("/export", web::get().to(export_settings)) - .route("/import", web::post().to(import_settings)), + .route("/export", get().to(export_settings)) + .route("/import", post().to(import_settings)), ) .service( - web::scope("/account") - .route("/my_user", web::get().to(get_my_user)) - .route("/list_media", web::get().to(list_media)) - .route("/mention", web::get().to(list_mentions)) - .route("/replies", web::get().to(list_replies)) - .route("/block", web::post().to(block_person)) - .route("/delete", web::post().to(delete_account)) + scope("/account") + .route("/my_user", get().to(get_my_user)) + .route("/list_media", get().to(list_media)) + .route("/mention", get().to(list_mentions)) + .route("/replies", get().to(list_replies)) + .route("/block", post().to(block_person)) + .route("/delete", post().to(delete_account)) .route( "/mention/mark_as_read", - web::post().to(mark_person_mention_as_read), + post().to(mark_person_mention_as_read), ) .route( "/mention/mark_all_as_read", - web::post().to(mark_all_notifications_read), + post().to(mark_all_notifications_read), ) - .route("/settings/save", web::put().to(save_user_settings)) - .route("/report_count", web::get().to(report_count)) - .route("/unread_count", web::get().to(unread_count)) - .route("/list_logins", web::get().to(list_logins)) - .route("/validate_auth", web::get().to(validate_auth)), + .route("/settings/save", put().to(save_user_settings)) + .route("/report_count", get().to(report_count)) + .route("/unread_count", get().to(unread_count)) + .route("/list_logins", get().to(list_logins)) + .route("/validate_auth", get().to(validate_auth)), ) // User actions - .route("/person", web::get().to(read_person)) + .route("/person", get().to(read_person)) // Admin Actions .service( - web::scope("/admin") - .route("/add", web::post().to(add_admin)) + scope("/admin") + .route("/add", post().to(add_admin)) .route( "/registration_application/count", - web::get().to(get_unread_registration_application_count), + get().to(get_unread_registration_application_count), ) .route( "/registration_application/list", - web::get().to(list_registration_applications), + get().to(list_registration_applications), ) .route( "/registration_application/approve", - web::put().to(approve_registration_application), + put().to(approve_registration_application), ) .route( "/registration_application", - web::get().to(get_registration_application), + get().to(get_registration_application), ) - .route("/list_all_media", web::get().to(list_all_media)) + .route("/list_all_media", get().to(list_all_media)) .service( - web::scope("/purge") - .route("/person", web::post().to(purge_person)) - .route("/community", web::post().to(purge_community)) - .route("/post", web::post().to(purge_post)) - .route("/comment", web::post().to(purge_comment)), + scope("/purge") + .route("/person", post().to(purge_person)) + .route("/community", post().to(purge_community)) + .route("/post", post().to(purge_post)) + .route("/comment", post().to(purge_comment)), ) .service( - web::scope("/tagline") - .route("", web::post().to(create_tagline)) - .route("", web::put().to(update_tagline)) - .route("/delete", web::post().to(delete_tagline)) - .route("/list", web::get().to(list_taglines)), + scope("/tagline") + .route("", post().to(create_tagline)) + .route("", put().to(update_tagline)) + .route("/delete", post().to(delete_tagline)) + .route("/list", get().to(list_taglines)), ) - .route("/ban", web::post().to(ban_from_site)) - .route("/banned", web::get().to(list_banned_users)) - .route("/leave", web::post().to(leave_admin)), + .route("/ban", post().to(ban_from_site)) + .route("/banned", get().to(list_banned_users)) + .route("/leave", post().to(leave_admin)), ) .service( - web::scope("/custom_emoji") - .route("", web::post().to(create_custom_emoji)) - .route("", web::put().to(update_custom_emoji)) - .route("/delete", web::post().to(delete_custom_emoji)) - .route("/list", web::get().to(list_custom_emojis)), + scope("/custom_emoji") + .route("", post().to(create_custom_emoji)) + .route("", put().to(update_custom_emoji)) + .route("/delete", post().to(delete_custom_emoji)) + .route("/list", get().to(list_custom_emojis)), ) .service( - web::scope("/oauth_provider") - .route("", web::post().to(create_oauth_provider)) - .route("", web::put().to(update_oauth_provider)) - .route("/delete", web::post().to(delete_oauth_provider)), + scope("/oauth_provider") + .route("", post().to(create_oauth_provider)) + .route("", put().to(update_oauth_provider)) + .route("/delete", post().to(delete_oauth_provider)), ) .service( - web::scope("/oauth") + scope("/oauth") .wrap(rate_limit.register()) - .route("/authenticate", web::post().to(authenticate_with_oauth)), + .route("/authenticate", post().to(authenticate_with_oauth)), ) - .route("/sitemap.xml", web::get().to(get_sitemap)), + .route("/sitemap.xml", get().to(get_sitemap)), ); } From 026d58387c979fd03999745e563b1c02b3341d7f Mon Sep 17 00:00:00 2001 From: Felix Ableitner Date: Thu, 28 Nov 2024 16:07:27 +0100 Subject: [PATCH 16/26] update --- api_tests/package.json | 2 +- api_tests/src/user.spec.ts | 3 +-- src/api_routes_v4.rs | 10 ++-------- 3 files changed, 4 insertions(+), 11 deletions(-) diff --git a/api_tests/package.json b/api_tests/package.json index 0c8e8990b6..c824b2cd3d 100644 --- a/api_tests/package.json +++ b/api_tests/package.json @@ -28,7 +28,7 @@ "eslint": "^9.14.0", "eslint-plugin-prettier": "^5.1.3", "jest": "^29.5.0", - "lemmy-js-client": "0.20.0-api-v4.6", + "lemmy-js-client": "0.20.0-api-v4.7", "prettier": "^3.2.5", "ts-jest": "^29.1.0", "typescript": "^5.5.4", diff --git a/api_tests/src/user.spec.ts b/api_tests/src/user.spec.ts index cee3947ff6..89f26c4ff0 100644 --- a/api_tests/src/user.spec.ts +++ b/api_tests/src/user.spec.ts @@ -119,8 +119,7 @@ test("Requests with invalid auth should be treated as unauthenticated", async () headers: { Authorization: "Bearer foobar" }, fetchFunction, }); - let my_user = await getMyUser(invalid_auth); - expect(my_user).toBeUndefined(); + await expect(getMyUser(invalid_auth)).rejects.toStrictEqual(Error("incorrect_login")); let site = await getSite(invalid_auth); expect(site.site_view).toBeDefined(); diff --git a/src/api_routes_v4.rs b/src/api_routes_v4.rs index 21917134f8..fe28789d4e 100644 --- a/src/api_routes_v4.rs +++ b/src/api_routes_v4.rs @@ -210,10 +210,7 @@ pub fn config(cfg: &mut ServiceConfig, rate_limit: &RateLimitCell) { .route("/approve", post().to(post_pending_follows_approve)), ), ) - .route( - "/federated_instances", - get().to(get_federated_instances), - ) + .route("/federated_instances", get().to(get_federated_instances)) // Post .service( // Handle POST to /post separately to add the post() rate limitter @@ -288,10 +285,7 @@ pub fn config(cfg: &mut ServiceConfig, rate_limit: &RateLimitCell) { .route("/logout", post().to(logout)) .route("/password_reset", post().to(reset_password)) .route("/get_captcha", get().to(get_captcha)) - .route( - "/password_change", - post().to(change_password_after_reset), - ) + .route("/password_change", post().to(change_password_after_reset)) .route("/change_password", put().to(change_password)) .route("/totp/generate", post().to(generate_totp_secret)) .route("/totp/update", post().to(update_totp)) From e907f1184d22d84eb3ab32ea2681b8cef643a6f1 Mon Sep 17 00:00:00 2001 From: Felix Ableitner Date: Thu, 28 Nov 2024 16:09:20 +0100 Subject: [PATCH 17/26] prettier --- api_tests/src/user.spec.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/api_tests/src/user.spec.ts b/api_tests/src/user.spec.ts index 89f26c4ff0..2521472ecc 100644 --- a/api_tests/src/user.spec.ts +++ b/api_tests/src/user.spec.ts @@ -119,7 +119,9 @@ test("Requests with invalid auth should be treated as unauthenticated", async () headers: { Authorization: "Bearer foobar" }, fetchFunction, }); - await expect(getMyUser(invalid_auth)).rejects.toStrictEqual(Error("incorrect_login")); + await expect(getMyUser(invalid_auth)).rejects.toStrictEqual( + Error("incorrect_login"), + ); let site = await getSite(invalid_auth); expect(site.site_view).toBeDefined(); From 3cec5e9f3d8737099898234059d590f846ef919b Mon Sep 17 00:00:00 2001 From: Felix Ableitner Date: Thu, 28 Nov 2024 16:31:53 +0100 Subject: [PATCH 18/26] lockfile --- api_tests/pnpm-lock.yaml | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/api_tests/pnpm-lock.yaml b/api_tests/pnpm-lock.yaml index 192c89e400..7a3ae51dbc 100644 --- a/api_tests/pnpm-lock.yaml +++ b/api_tests/pnpm-lock.yaml @@ -30,8 +30,8 @@ importers: specifier: ^29.5.0 version: 29.7.0(@types/node@22.9.0) lemmy-js-client: - specifier: 0.20.0-api-v4.6 - version: 0.20.0-api-v4.6 + specifier: 0.20.0-api-v4.7 + version: 0.20.0-api-v4.7 prettier: specifier: ^3.2.5 version: 3.3.3 @@ -1167,8 +1167,8 @@ packages: resolution: {integrity: sha512-eTIzlVOSUR+JxdDFepEYcBMtZ9Qqdef+rnzWdRZuMbOywu5tO2w2N7rqjoANZ5k9vywhL6Br1VRjUIgTQx4E8w==} engines: {node: '>=6'} - lemmy-js-client@0.20.0-api-v4.6: - resolution: {integrity: sha512-+M2kbk0a4beJ5Jpn2I0DBEqF7IHz90Mvl5q85EeaexhsdQvfRzhMi+OmViy6SY9qUEjEYAN5eJJKu479T/My0w==} + lemmy-js-client@0.20.0-api-v4.7: + resolution: {integrity: sha512-wfvzJl1kJw1tmpYpFU+yYDfwFr3lO21QFLtXjH0EeUdeJkkzvnJlu2xt27De42+04N5jKmMTNTI/RcIR9KfCqA==} leven@3.1.0: resolution: {integrity: sha512-qsda+H8jTaUaN/x5vzW2rzc+8Rw4TAQ/4KjB46IwK5VH+IlVeeeje/EoZRpiXvIqjFgK84QffqPztGI3VBLG1A==} @@ -3077,7 +3077,7 @@ snapshots: kleur@3.0.3: {} - lemmy-js-client@0.20.0-api-v4.6: {} + lemmy-js-client@0.20.0-api-v4.7: {} leven@3.1.0: {} From d14f8dc1e140fad16846b45ef893ce0f581d558e Mon Sep 17 00:00:00 2001 From: Felix Ableitner Date: Fri, 29 Nov 2024 11:12:04 +0100 Subject: [PATCH 19/26] v --- crates/api_common/src/site.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/api_common/src/site.rs b/crates/api_common/src/site.rs index 84d5c4e349..27c2e2e21b 100644 --- a/crates/api_common/src/site.rs +++ b/crates/api_common/src/site.rs @@ -435,7 +435,7 @@ pub struct EditSite { /// The response for a site. pub struct SiteResponse { pub site_view: SiteView, - /// deprecated, use field `tagline` or /api/4/tagline/list + /// deprecated, use field `tagline` or /api/v4/tagline/list pub taglines: Vec<()>, } From f6037afa00287acbdf8a8f0e168e2092a2d76f01 Mon Sep 17 00:00:00 2001 From: Felix Ableitner Date: Fri, 29 Nov 2024 11:49:57 +0100 Subject: [PATCH 20/26] fix settings --- src/api_routes_v4.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/api_routes_v4.rs b/src/api_routes_v4.rs index bbb0a733bd..d34ecbf0a2 100644 --- a/src/api_routes_v4.rs +++ b/src/api_routes_v4.rs @@ -291,6 +291,7 @@ pub fn config(cfg: &mut ServiceConfig, rate_limit: &RateLimitCell) { .route("/totp/update", post().to(update_totp)) .route("/verify_email", post().to(verify_email)), ) + .route("/account/settings/save", put().to(save_user_settings)) .service( scope("/account/settings") .wrap(rate_limit.import_user_settings()) @@ -313,7 +314,6 @@ pub fn config(cfg: &mut ServiceConfig, rate_limit: &RateLimitCell) { "/mention/mark_all_as_read", post().to(mark_all_notifications_read), ) - .route("/settings/save", put().to(save_user_settings)) .route("/report_count", get().to(report_count)) .route("/unread_count", get().to(unread_count)) .route("/list_logins", get().to(list_logins)) From 0fa23d7b401dd4914ff719d2af5dd2899c087fa4 Mon Sep 17 00:00:00 2001 From: Felix Ableitner Date: Fri, 29 Nov 2024 12:19:44 +0100 Subject: [PATCH 21/26] move block endpoints --- api_tests/package.json | 2 +- api_tests/pnpm-lock.yaml | 10 +++++----- crates/api/src/community/block.rs | 2 +- crates/api/src/local_user/block.rs | 2 +- crates/api/src/local_user/mod.rs | 2 +- .../{site => local_user}/user_block_instance.rs | 0 crates/api/src/site/mod.rs | 1 - src/api_routes_v3.rs | 10 +++++----- src/api_routes_v4.rs | 16 ++++++++++------ 9 files changed, 24 insertions(+), 21 deletions(-) rename crates/api/src/{site => local_user}/user_block_instance.rs (100%) diff --git a/api_tests/package.json b/api_tests/package.json index 4828aa1af5..ea58e00a55 100644 --- a/api_tests/package.json +++ b/api_tests/package.json @@ -28,7 +28,7 @@ "eslint": "^9.14.0", "eslint-plugin-prettier": "^5.1.3", "jest": "^29.5.0", - "lemmy-js-client": "0.20.0-api-v4.8", + "lemmy-js-client": "0.20.0-api-v4.10", "prettier": "^3.2.5", "ts-jest": "^29.1.0", "typescript": "^5.5.4", diff --git a/api_tests/pnpm-lock.yaml b/api_tests/pnpm-lock.yaml index 3e15e3663c..a2af126758 100644 --- a/api_tests/pnpm-lock.yaml +++ b/api_tests/pnpm-lock.yaml @@ -30,8 +30,8 @@ importers: specifier: ^29.5.0 version: 29.7.0(@types/node@22.9.0) lemmy-js-client: - specifier: 0.20.0-api-v4.8 - version: 0.20.0-api-v4.8 + specifier: 0.20.0-api-v4.10 + version: 0.20.0-api-v4.10 prettier: specifier: ^3.2.5 version: 3.3.3 @@ -1167,8 +1167,8 @@ packages: resolution: {integrity: sha512-eTIzlVOSUR+JxdDFepEYcBMtZ9Qqdef+rnzWdRZuMbOywu5tO2w2N7rqjoANZ5k9vywhL6Br1VRjUIgTQx4E8w==} engines: {node: '>=6'} - lemmy-js-client@0.20.0-api-v4.8: - resolution: {integrity: sha512-h+qgWXP4kUrr2va//WTGT6EXDUHAf3hJpitpD9SX9avlBRyVpp31pJ5BPm1G4kR7KPPyKO/nmAS+7HGKtGkRKA==} + lemmy-js-client@0.20.0-api-v4.10: + resolution: {integrity: sha512-Dtl0CuS2LSVTX02TTRW3Zu51VWUZW3cPt3he+dnfPLVAr+nRA5erGObQJH5B353IO4RTPXDV+nYl+GKHgDeLtw==} leven@3.1.0: resolution: {integrity: sha512-qsda+H8jTaUaN/x5vzW2rzc+8Rw4TAQ/4KjB46IwK5VH+IlVeeeje/EoZRpiXvIqjFgK84QffqPztGI3VBLG1A==} @@ -3077,7 +3077,7 @@ snapshots: kleur@3.0.3: {} - lemmy-js-client@0.20.0-api-v4.8: {} + lemmy-js-client@0.20.0-api-v4.10: {} leven@3.1.0: {} diff --git a/crates/api/src/community/block.rs b/crates/api/src/community/block.rs index a6a48e2e75..d498724939 100644 --- a/crates/api/src/community/block.rs +++ b/crates/api/src/community/block.rs @@ -17,7 +17,7 @@ use lemmy_db_views_actor::structs::CommunityView; use lemmy_utils::error::{LemmyErrorExt, LemmyErrorType, LemmyResult}; #[tracing::instrument(skip(context))] -pub async fn block_community( +pub async fn user_block_community( data: Json, context: Data, local_user_view: LocalUserView, diff --git a/crates/api/src/local_user/block.rs b/crates/api/src/local_user/block.rs index 250277be36..80532e897a 100644 --- a/crates/api/src/local_user/block.rs +++ b/crates/api/src/local_user/block.rs @@ -12,7 +12,7 @@ use lemmy_db_views_actor::structs::PersonView; use lemmy_utils::error::{LemmyErrorExt, LemmyErrorType, LemmyResult}; #[tracing::instrument(skip(context))] -pub async fn block_person( +pub async fn user_block_person( data: Json, context: Data, local_user_view: LocalUserView, diff --git a/crates/api/src/local_user/mod.rs b/crates/api/src/local_user/mod.rs index b1ee7c0b6e..f0314df90f 100644 --- a/crates/api/src/local_user/mod.rs +++ b/crates/api/src/local_user/mod.rs @@ -10,7 +10,7 @@ pub mod list_logins; pub mod list_media; pub mod login; pub mod logout; -pub mod notifications; +pub mod notifications;pub mod user_block_instance; pub mod report_count; pub mod reset_password; pub mod save_settings; diff --git a/crates/api/src/site/user_block_instance.rs b/crates/api/src/local_user/user_block_instance.rs similarity index 100% rename from crates/api/src/site/user_block_instance.rs rename to crates/api/src/local_user/user_block_instance.rs diff --git a/crates/api/src/site/mod.rs b/crates/api/src/site/mod.rs index 52e882bb33..bab66f33bb 100644 --- a/crates/api/src/site/mod.rs +++ b/crates/api/src/site/mod.rs @@ -6,4 +6,3 @@ pub mod list_all_media; pub mod mod_log; pub mod purge; pub mod registration_applications; -pub mod user_block_instance; diff --git a/src/api_routes_v3.rs b/src/api_routes_v3.rs index 9fcc5edd2e..35d5ca38b1 100644 --- a/src/api_routes_v3.rs +++ b/src/api_routes_v3.rs @@ -14,7 +14,7 @@ use lemmy_api::{ community::{ add_mod::add_mod_to_community, ban::ban_from_community, - block::block_community, + block::user_block_community, follow::follow_community, hide::hide_community, transfer::transfer_community, @@ -22,7 +22,7 @@ use lemmy_api::{ local_user::{ add_admin::add_admin, ban_person::ban_from_site, - block::block_person, + block::user_block_person, change_password::change_password, change_password_after_reset::change_password_after_reset, generate_totp_secret::generate_totp_secret, @@ -44,6 +44,7 @@ use lemmy_api::{ reset_password::reset_password, save_settings::save_user_settings, update_totp::update_totp, + user_block_instance::user_block_instance, validate_auth::validate_auth, verify_email::verify_email, }, @@ -85,7 +86,6 @@ use lemmy_api::{ list::list_registration_applications, unread_count::get_unread_registration_application_count, }, - user_block_instance::user_block_instance, }, sitemap::get_sitemap, }; @@ -181,7 +181,7 @@ pub fn config(cfg: &mut ServiceConfig, rate_limit: &RateLimitCell) { .route("/hide", put().to(hide_community)) .route("/list", get().to(list_communities)) .route("/follow", post().to(follow_community)) - .route("/block", post().to(block_community)) + .route("/block", post().to(user_block_community)) .route("/delete", post().to(delete_community)) // Mod Actions .route("/remove", post().to(remove_community)) @@ -321,7 +321,7 @@ pub fn config(cfg: &mut ServiceConfig, rate_limit: &RateLimitCell) { // Admin action. I don't like that it's in /user .route("/ban", post().to(ban_from_site)) .route("/banned", get().to(list_banned_users)) - .route("/block", post().to(block_person)) + .route("/block", post().to(user_block_person)) // TODO Account actions. I don't like that they're in /user maybe /accounts .route("/logout", post().to(logout)) .route("/delete_account", post().to(delete_account)) diff --git a/src/api_routes_v4.rs b/src/api_routes_v4.rs index d34ecbf0a2..ecae3a6ffe 100644 --- a/src/api_routes_v4.rs +++ b/src/api_routes_v4.rs @@ -14,7 +14,7 @@ use lemmy_api::{ community::{ add_mod::add_mod_to_community, ban::ban_from_community, - block::block_community, + block::user_block_community, follow::follow_community, hide::hide_community, pending_follows::{ @@ -28,7 +28,7 @@ use lemmy_api::{ local_user::{ add_admin::add_admin, ban_person::ban_from_site, - block::block_person, + block::user_block_person, change_password::change_password, change_password_after_reset::change_password_after_reset, generate_totp_secret::generate_totp_secret, @@ -50,6 +50,7 @@ use lemmy_api::{ reset_password::reset_password, save_settings::save_user_settings, update_totp::update_totp, + user_block_instance::user_block_instance, validate_auth::validate_auth, verify_email::verify_email, }, @@ -170,7 +171,6 @@ pub fn config(cfg: &mut ServiceConfig, rate_limit: &RateLimitCell) { .service( scope("/site") .route("", get().to(get_site_v4)) - // Admin Actions .route("", post().to(create_site)) .route("", put().to(update_site)), ) @@ -196,7 +196,6 @@ pub fn config(cfg: &mut ServiceConfig, rate_limit: &RateLimitCell) { .route("/hide", put().to(hide_community)) .route("/list", get().to(list_communities)) .route("/follow", post().to(follow_community)) - .route("/block", post().to(block_community)) .route("/delete", post().to(delete_community)) // Mod Actions .route("/remove", post().to(remove_community)) @@ -304,7 +303,6 @@ pub fn config(cfg: &mut ServiceConfig, rate_limit: &RateLimitCell) { .route("/list_media", get().to(list_media)) .route("/mention", get().to(list_mentions)) .route("/replies", get().to(list_replies)) - .route("/block", post().to(block_person)) .route("/delete", post().to(delete_account)) .route( "/mention/mark_as_read", @@ -317,7 +315,13 @@ pub fn config(cfg: &mut ServiceConfig, rate_limit: &RateLimitCell) { .route("/report_count", get().to(report_count)) .route("/unread_count", get().to(unread_count)) .route("/list_logins", get().to(list_logins)) - .route("/validate_auth", get().to(validate_auth)), + .route("/validate_auth", get().to(validate_auth)) + .service( + scope("/block") + .route("/person", post().to(user_block_person)) + .route("/community", post().to(user_block_community)) + .route("/instance", post().to(user_block_instance)), + ), ) // User actions .route("/person", get().to(read_person)) From 9c6ecbf2aed86e824e3d9125a72fd95753806d88 Mon Sep 17 00:00:00 2001 From: Felix Ableitner Date: Fri, 29 Nov 2024 12:28:01 +0100 Subject: [PATCH 22/26] more changes --- api_tests/package.json | 2 +- api_tests/pnpm-lock.yaml | 10 +++++----- src/api_routes_v4.rs | 7 +++++-- 3 files changed, 11 insertions(+), 8 deletions(-) diff --git a/api_tests/package.json b/api_tests/package.json index ea58e00a55..2b34b7cf23 100644 --- a/api_tests/package.json +++ b/api_tests/package.json @@ -28,7 +28,7 @@ "eslint": "^9.14.0", "eslint-plugin-prettier": "^5.1.3", "jest": "^29.5.0", - "lemmy-js-client": "0.20.0-api-v4.10", + "lemmy-js-client": "0.20.0-api-v4.12", "prettier": "^3.2.5", "ts-jest": "^29.1.0", "typescript": "^5.5.4", diff --git a/api_tests/pnpm-lock.yaml b/api_tests/pnpm-lock.yaml index a2af126758..a2cb889bb1 100644 --- a/api_tests/pnpm-lock.yaml +++ b/api_tests/pnpm-lock.yaml @@ -30,8 +30,8 @@ importers: specifier: ^29.5.0 version: 29.7.0(@types/node@22.9.0) lemmy-js-client: - specifier: 0.20.0-api-v4.10 - version: 0.20.0-api-v4.10 + specifier: 0.20.0-api-v4.12 + version: 0.20.0-api-v4.12 prettier: specifier: ^3.2.5 version: 3.3.3 @@ -1167,8 +1167,8 @@ packages: resolution: {integrity: sha512-eTIzlVOSUR+JxdDFepEYcBMtZ9Qqdef+rnzWdRZuMbOywu5tO2w2N7rqjoANZ5k9vywhL6Br1VRjUIgTQx4E8w==} engines: {node: '>=6'} - lemmy-js-client@0.20.0-api-v4.10: - resolution: {integrity: sha512-Dtl0CuS2LSVTX02TTRW3Zu51VWUZW3cPt3he+dnfPLVAr+nRA5erGObQJH5B353IO4RTPXDV+nYl+GKHgDeLtw==} + lemmy-js-client@0.20.0-api-v4.12: + resolution: {integrity: sha512-U6/1ZLBgWHCQgqKraNUGASORqgUPTdutReqeY8+Bl5LYpenFGe87jM3A6Eniu3PQ+C6hBWNbC5axl8EdLOMLrA==} leven@3.1.0: resolution: {integrity: sha512-qsda+H8jTaUaN/x5vzW2rzc+8Rw4TAQ/4KjB46IwK5VH+IlVeeeje/EoZRpiXvIqjFgK84QffqPztGI3VBLG1A==} @@ -3077,7 +3077,7 @@ snapshots: kleur@3.0.3: {} - lemmy-js-client@0.20.0-api-v4.10: {} + lemmy-js-client@0.20.0-api-v4.12: {} leven@3.1.0: {} diff --git a/src/api_routes_v4.rs b/src/api_routes_v4.rs index ecae3a6ffe..9ac71ea5a5 100644 --- a/src/api_routes_v4.rs +++ b/src/api_routes_v4.rs @@ -363,8 +363,11 @@ pub fn config(cfg: &mut ServiceConfig, rate_limit: &RateLimitCell) { .route("/ban", post().to(ban_from_site)) .route("/banned", get().to(list_banned_users)) .route("/leave", post().to(leave_admin)) - .route("block_instance", post().to(admin_block_instance)) - .route("allow_instance", post().to(admin_allow_instance)), + .service( + scope("/instance") + .route("/block", post().to(admin_block_instance)) + .route("/allow", post().to(admin_allow_instance)), + ), ) .service( scope("/custom_emoji") From e620e94c19ed89d7f5599fc66a439d0757a6b5e0 Mon Sep 17 00:00:00 2001 From: Felix Ableitner Date: Fri, 29 Nov 2024 12:29:21 +0100 Subject: [PATCH 23/26] fmt --- crates/api/src/local_user/mod.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/crates/api/src/local_user/mod.rs b/crates/api/src/local_user/mod.rs index f0314df90f..d3fc37a73c 100644 --- a/crates/api/src/local_user/mod.rs +++ b/crates/api/src/local_user/mod.rs @@ -10,10 +10,11 @@ pub mod list_logins; pub mod list_media; pub mod login; pub mod logout; -pub mod notifications;pub mod user_block_instance; +pub mod notifications; pub mod report_count; pub mod reset_password; pub mod save_settings; pub mod update_totp; +pub mod user_block_instance; pub mod validate_auth; pub mod verify_email; From 7b423a0c81f4799a3d8693a3b567f2c88b4bf3d9 Mon Sep 17 00:00:00 2001 From: Felix Ableitner Date: Fri, 29 Nov 2024 12:50:57 +0100 Subject: [PATCH 24/26] update --- api_tests/package.json | 2 +- api_tests/pnpm-lock.yaml | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/api_tests/package.json b/api_tests/package.json index 2b34b7cf23..ca8ea8a152 100644 --- a/api_tests/package.json +++ b/api_tests/package.json @@ -28,7 +28,7 @@ "eslint": "^9.14.0", "eslint-plugin-prettier": "^5.1.3", "jest": "^29.5.0", - "lemmy-js-client": "0.20.0-api-v4.12", + "lemmy-js-client": "0.20.0-api-v4.14", "prettier": "^3.2.5", "ts-jest": "^29.1.0", "typescript": "^5.5.4", diff --git a/api_tests/pnpm-lock.yaml b/api_tests/pnpm-lock.yaml index a2cb889bb1..9a83e79b55 100644 --- a/api_tests/pnpm-lock.yaml +++ b/api_tests/pnpm-lock.yaml @@ -30,8 +30,8 @@ importers: specifier: ^29.5.0 version: 29.7.0(@types/node@22.9.0) lemmy-js-client: - specifier: 0.20.0-api-v4.12 - version: 0.20.0-api-v4.12 + specifier: 0.20.0-api-v4.14 + version: 0.20.0-api-v4.14 prettier: specifier: ^3.2.5 version: 3.3.3 @@ -1167,8 +1167,8 @@ packages: resolution: {integrity: sha512-eTIzlVOSUR+JxdDFepEYcBMtZ9Qqdef+rnzWdRZuMbOywu5tO2w2N7rqjoANZ5k9vywhL6Br1VRjUIgTQx4E8w==} engines: {node: '>=6'} - lemmy-js-client@0.20.0-api-v4.12: - resolution: {integrity: sha512-U6/1ZLBgWHCQgqKraNUGASORqgUPTdutReqeY8+Bl5LYpenFGe87jM3A6Eniu3PQ+C6hBWNbC5axl8EdLOMLrA==} + lemmy-js-client@0.20.0-api-v4.14: + resolution: {integrity: sha512-kdhnQdbcA/jF7lRH5uwOBIcD6cK/9Xg7M9nq/MoxfOhSW7blPyssjQWRYcuhXpHVtjjffomr1uRJmzzVcMWp0A==} leven@3.1.0: resolution: {integrity: sha512-qsda+H8jTaUaN/x5vzW2rzc+8Rw4TAQ/4KjB46IwK5VH+IlVeeeje/EoZRpiXvIqjFgK84QffqPztGI3VBLG1A==} @@ -3077,7 +3077,7 @@ snapshots: kleur@3.0.3: {} - lemmy-js-client@0.20.0-api-v4.12: {} + lemmy-js-client@0.20.0-api-v4.14: {} leven@3.1.0: {} From 52f17281ca25d3c1d17ca7c950e5536127ac5bb2 Mon Sep 17 00:00:00 2001 From: Felix Ableitner Date: Mon, 2 Dec 2024 11:34:58 +0100 Subject: [PATCH 25/26] change some routes --- api_tests/package.json | 2 +- api_tests/pnpm-lock.yaml | 10 +++++----- src/api_routes_v4.rs | 6 +++--- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/api_tests/package.json b/api_tests/package.json index ca8ea8a152..7ea21d0ba0 100644 --- a/api_tests/package.json +++ b/api_tests/package.json @@ -28,7 +28,7 @@ "eslint": "^9.14.0", "eslint-plugin-prettier": "^5.1.3", "jest": "^29.5.0", - "lemmy-js-client": "0.20.0-api-v4.14", + "lemmy-js-client": "0.20.0-api-v4.16", "prettier": "^3.2.5", "ts-jest": "^29.1.0", "typescript": "^5.5.4", diff --git a/api_tests/pnpm-lock.yaml b/api_tests/pnpm-lock.yaml index 9a83e79b55..90fc140706 100644 --- a/api_tests/pnpm-lock.yaml +++ b/api_tests/pnpm-lock.yaml @@ -30,8 +30,8 @@ importers: specifier: ^29.5.0 version: 29.7.0(@types/node@22.9.0) lemmy-js-client: - specifier: 0.20.0-api-v4.14 - version: 0.20.0-api-v4.14 + specifier: 0.20.0-api-v4.15 + version: 0.20.0-api-v4.15 prettier: specifier: ^3.2.5 version: 3.3.3 @@ -1167,8 +1167,8 @@ packages: resolution: {integrity: sha512-eTIzlVOSUR+JxdDFepEYcBMtZ9Qqdef+rnzWdRZuMbOywu5tO2w2N7rqjoANZ5k9vywhL6Br1VRjUIgTQx4E8w==} engines: {node: '>=6'} - lemmy-js-client@0.20.0-api-v4.14: - resolution: {integrity: sha512-kdhnQdbcA/jF7lRH5uwOBIcD6cK/9Xg7M9nq/MoxfOhSW7blPyssjQWRYcuhXpHVtjjffomr1uRJmzzVcMWp0A==} + lemmy-js-client@0.20.0-api-v4.15: + resolution: {integrity: sha512-OvTOf69oMx7ka44GGTX2PxTVhgnRkOj7GOLrF+q2w7sJo3zguuM1EaZz1+pLJSZx2hhPy6wmvtx4vd4t4jWpnw==} leven@3.1.0: resolution: {integrity: sha512-qsda+H8jTaUaN/x5vzW2rzc+8Rw4TAQ/4KjB46IwK5VH+IlVeeeje/EoZRpiXvIqjFgK84QffqPztGI3VBLG1A==} @@ -3077,7 +3077,7 @@ snapshots: kleur@3.0.3: {} - lemmy-js-client@0.20.0-api-v4.14: {} + lemmy-js-client@0.20.0-api-v4.15: {} leven@3.1.0: {} diff --git a/src/api_routes_v4.rs b/src/api_routes_v4.rs index 9ac71ea5a5..a9f71c9da9 100644 --- a/src/api_routes_v4.rs +++ b/src/api_routes_v4.rs @@ -225,7 +225,7 @@ pub fn config(cfg: &mut ServiceConfig, rate_limit: &RateLimitCell) { .route("/delete", post().to(delete_post)) .route("/remove", post().to(remove_post)) .route("/mark_as_read", post().to(mark_post_as_read)) - .route("/mark_many_as_read", post().to(mark_posts_as_read)) + .route("/mark_as_read/many", post().to(mark_posts_as_read)) .route("/hide", post().to(hide_post)) .route("/lock", post().to(lock_post)) .route("/feature", post().to(feature_post)) @@ -299,7 +299,7 @@ pub fn config(cfg: &mut ServiceConfig, rate_limit: &RateLimitCell) { ) .service( scope("/account") - .route("/my_user", get().to(get_my_user)) + .route("", get().to(get_my_user)) .route("/list_media", get().to(list_media)) .route("/mention", get().to(list_mentions)) .route("/replies", get().to(list_replies)) @@ -309,7 +309,7 @@ pub fn config(cfg: &mut ServiceConfig, rate_limit: &RateLimitCell) { post().to(mark_person_mention_as_read), ) .route( - "/mention/mark_all_as_read", + "/mention/mark_as_read/all", post().to(mark_all_notifications_read), ) .route("/report_count", get().to(report_count)) From 4b264460c70422498caa155f77e766ba0dc45c3c Mon Sep 17 00:00:00 2001 From: Felix Ableitner Date: Mon, 2 Dec 2024 12:08:03 +0100 Subject: [PATCH 26/26] lockfile --- api_tests/pnpm-lock.yaml | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/api_tests/pnpm-lock.yaml b/api_tests/pnpm-lock.yaml index 90fc140706..496606e6c2 100644 --- a/api_tests/pnpm-lock.yaml +++ b/api_tests/pnpm-lock.yaml @@ -30,8 +30,8 @@ importers: specifier: ^29.5.0 version: 29.7.0(@types/node@22.9.0) lemmy-js-client: - specifier: 0.20.0-api-v4.15 - version: 0.20.0-api-v4.15 + specifier: 0.20.0-api-v4.16 + version: 0.20.0-api-v4.16 prettier: specifier: ^3.2.5 version: 3.3.3 @@ -1167,8 +1167,8 @@ packages: resolution: {integrity: sha512-eTIzlVOSUR+JxdDFepEYcBMtZ9Qqdef+rnzWdRZuMbOywu5tO2w2N7rqjoANZ5k9vywhL6Br1VRjUIgTQx4E8w==} engines: {node: '>=6'} - lemmy-js-client@0.20.0-api-v4.15: - resolution: {integrity: sha512-OvTOf69oMx7ka44GGTX2PxTVhgnRkOj7GOLrF+q2w7sJo3zguuM1EaZz1+pLJSZx2hhPy6wmvtx4vd4t4jWpnw==} + lemmy-js-client@0.20.0-api-v4.16: + resolution: {integrity: sha512-9Wn7b8YT2KnEA286+RV1B3mLmecAynvAERoC0ZZiccfSgkEvd3rG9A5X9ejiPqp+JzDZJeisO57+Ut4QHr5oTw==} leven@3.1.0: resolution: {integrity: sha512-qsda+H8jTaUaN/x5vzW2rzc+8Rw4TAQ/4KjB46IwK5VH+IlVeeeje/EoZRpiXvIqjFgK84QffqPztGI3VBLG1A==} @@ -3077,7 +3077,7 @@ snapshots: kleur@3.0.3: {} - lemmy-js-client@0.20.0-api-v4.15: {} + lemmy-js-client@0.20.0-api-v4.16: {} leven@3.1.0: {}