lemmy/src/api_routes_v4.rs

390 lines
13 KiB
Rust
Raw Normal View History

2024-11-28 14:56:34 +00:00
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,
Feature/custom emoji and tagline views (#4580) * Add custom_emoji list route * Add tagline list route * Apply linting * Remove unecessary TaglineView * Add category filter for custom emoji * Add create tagline endpoint * Add update tagline endpoint * Add delete tagline endpoint * Format through lint.sh * Remove custom_emojis and taglines from site resource * Get random tagline on site requets * Impl Crud for Tagline Remove superfluous properties * Move tagline endpoints under /admin * Impl Crud for CustomEmoji * Remove delete from tagline and custom emoji impls * Check markdown for tagline * Validate markdown on tagline * Make content fields non optional Add error types for tagline validation * Use process_markdown instead of process_markdown_opt * Consolidate Tagline error types * Remove unecessary clone * Updat misleading comments * Remove local_site_id from tagline and custom_emoji * Update TaglineInserForm and TaglineUpdateForm * Add ignore_page_limits for custom emojis EmojiPicker needs to be able to retrieve all emojis in 1 call * Update custom_emoji_view Only keep get_all als helper function calling list with paging ignored Only order on category when filtering on category * Removing pointless get_all fn. * remove tagline length checks * make fields of TaglineInsertForm and TaglineUpdateForm mandatory * move emoji order statement * add comment for GetSiteResponse.tagline --------- Co-authored-by: Freakazoid182 <> Co-authored-by: SleeplessOne1917 <28871516+SleeplessOne1917@users.noreply.github.com> Co-authored-by: Dessalines <tyhou13@gmx.com> Co-authored-by: Felix Ableitner <me@nutomic.com>
2024-09-19 09:15:04 +00:00
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,
},
2024-11-26 13:51:07 +00:00
site::{create::create_site, read::get_site_v4, update::update_site},
Feature/custom emoji and tagline views (#4580) * Add custom_emoji list route * Add tagline list route * Apply linting * Remove unecessary TaglineView * Add category filter for custom emoji * Add create tagline endpoint * Add update tagline endpoint * Add delete tagline endpoint * Format through lint.sh * Remove custom_emojis and taglines from site resource * Get random tagline on site requets * Impl Crud for Tagline Remove superfluous properties * Move tagline endpoints under /admin * Impl Crud for CustomEmoji * Remove delete from tagline and custom emoji impls * Check markdown for tagline * Validate markdown on tagline * Make content fields non optional Add error types for tagline validation * Use process_markdown instead of process_markdown_opt * Consolidate Tagline error types * Remove unecessary clone * Updat misleading comments * Remove local_site_id from tagline and custom_emoji * Update TaglineInserForm and TaglineUpdateForm * Add ignore_page_limits for custom emojis EmojiPicker needs to be able to retrieve all emojis in 1 call * Update custom_emoji_view Only keep get_all als helper function calling list with paging ignored Only order on category when filtering on category * Removing pointless get_all fn. * remove tagline length checks * make fields of TaglineInsertForm and TaglineUpdateForm mandatory * move emoji order statement * add comment for GetSiteResponse.tagline --------- Co-authored-by: Freakazoid182 <> Co-authored-by: SleeplessOne1917 <28871516+SleeplessOne1917@users.noreply.github.com> Co-authored-by: Dessalines <tyhou13@gmx.com> Co-authored-by: Felix Ableitner <me@nutomic.com>
2024-09-19 09:15:04 +00:00
tagline::{
create::create_tagline,
delete::delete_tagline,
list::list_taglines,
update::update_tagline,
},
user::{
create::{authenticate_with_oauth, register},
delete::delete_account,
2024-11-22 08:55:18 +00:00
my_user::get_my_user,
},
};
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},
};
Rewrite images to use local proxy (#4035) * Add markdown rule to add rel=nofollow for all links * Add markdown image rule to add local image proxy (fixes #1036) * comments * rewrite markdown image links working * add comment * perform markdown image processing in api/apub receivers * clippy * add db table to validate proxied links * rewrite link fields for avatar, banner etc * sql fmt * proxy links received over federation * add config option * undo post.url rewriting, move http route definition * add tests * proxy images through pictrs * testing * cleanup request.rs file * more cleanup (fixes #2611) * include url content type when sending post over apub (fixes #2611) * store post url content type in db * should be media_type * get rid of cache_remote_thumbnails setting, instead automatically take thumbnail from federation data if available. * fix tests * add setting disable_external_link_previews * federate post url as image depending on mime type * change setting again * machete * invert * support custom emoji * clippy * update defaults * add image proxy test, fix test * fix test * clippy * revert accidental changes * address review * clippy * Markdown link rule-dess (#4356) * Extracting opengraph_data to its own type. * A few additions for markdown-link-rule. --------- Co-authored-by: Nutomic <me@nutomic.com> * fix setting * use enum for image proxy setting * fix test configs * add config backwards compat * clippy * machete --------- Co-authored-by: Dessalines <dessalines@users.noreply.github.com>
2024-01-25 14:22:11 +00:00
use lemmy_routes::images::image_proxy;
use lemmy_utils::rate_limit::RateLimitCell;
2024-11-28 14:56:34 +00:00
pub fn config(cfg: &mut ServiceConfig, rate_limit: &RateLimitCell) {
cfg.service(
2024-11-28 14:56:34 +00:00
scope("/api/v4")
2024-11-21 13:47:31 +00:00
.wrap(rate_limit.message())
2024-11-28 14:56:34 +00:00
.route("/image_proxy", get().to(image_proxy))
// Site
.service(
2024-11-28 14:56:34 +00:00
scope("/site")
.route("", get().to(get_site_v4))
// Admin Actions
2024-11-28 14:56:34 +00:00
.route("", post().to(create_site))
.route("", put().to(update_site))
.route("/block", post().to(block_instance)),
)
2024-11-28 14:56:34 +00:00
.route("/modlog", get().to(get_mod_log))
.service(
2024-11-28 14:56:34 +00:00
resource("/search")
.wrap(rate_limit.search())
2024-11-28 14:56:34 +00:00
.route(get().to(search)),
)
2024-11-28 14:56:34 +00:00
.route("/resolve_object", get().to(resolve_object))
// Community
.service(
2024-11-28 14:56:34 +00:00
resource("/community")
.guard(guard::Post())
2020-04-20 18:05:07 +00:00
.wrap(rate_limit.register())
2024-11-28 14:56:34 +00:00
.route(post().to(create_community)),
)
.service(
2024-11-28 14:56:34 +00:00
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
2024-11-28 14:56:34 +00:00
.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(
2024-11-28 14:56:34 +00:00
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)),
),
)
2024-11-21 11:21:20 +00:00
.route(
"/federated_instances",
2024-11-28 14:56:34 +00:00
get().to(get_federated_instances),
)
// Post
.service(
// Handle POST to /post separately to add the post() rate limitter
2024-11-28 14:56:34 +00:00
resource("/post")
.guard(guard::Post())
.wrap(rate_limit.post())
2024-11-28 14:56:34 +00:00
.route(post().to(create_post)),
)
.service(
2024-11-28 14:56:34 +00:00
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
2021-11-11 20:40:25 +00:00
.service(
// Handle POST to /comment separately to add the comment() rate limitter
2024-11-28 14:56:34 +00:00
resource("/comment")
2021-11-11 20:40:25 +00:00
.guard(guard::Post())
.wrap(rate_limit.comment())
2024-11-28 14:56:34 +00:00
.route(post().to(create_comment)),
2021-11-11 20:40:25 +00:00
)
.service(
2024-11-28 14:56:34 +00:00
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)),
)
2020-05-06 02:06:24 +00:00
// Private Message
.service(
2024-11-28 14:56:34 +00:00
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)),
2020-05-06 02:06:24 +00:00
)
// User
.service(
2024-11-28 14:56:34 +00:00
scope("/account/auth")
.guard(guard::Post())
.wrap(rate_limit.register())
2024-11-28 14:56:34 +00:00
.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))
2024-11-21 11:09:37 +00:00
.route(
"/password_change",
2024-11-28 14:56:34 +00:00
post().to(change_password_after_reset),
2024-11-21 11:09:37 +00:00
)
2024-11-28 14:56:34 +00:00
.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(
2024-11-28 14:56:34 +00:00
scope("/account/settings")
.wrap(rate_limit.import_user_settings())
2024-11-28 14:56:34 +00:00
.route("/export", get().to(export_settings))
.route("/import", post().to(import_settings)),
)
.service(
2024-11-28 14:56:34 +00:00
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))
2020-04-20 04:47:20 +00:00
.route(
2024-11-20 13:41:15 +00:00
"/mention/mark_as_read",
2024-11-28 14:56:34 +00:00
post().to(mark_person_mention_as_read),
2024-11-20 13:41:15 +00:00
)
.route(
"/mention/mark_all_as_read",
2024-11-28 14:56:34 +00:00
post().to(mark_all_notifications_read),
)
2024-11-28 14:56:34 +00:00
.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)),
)
2024-11-20 13:41:15 +00:00
// User actions
2024-11-28 14:56:34 +00:00
.route("/person", get().to(read_person))
// Admin Actions
.service(
2024-11-28 14:56:34 +00:00
scope("/admin")
.route("/add", post().to(add_admin))
.route(
"/registration_application/count",
2024-11-28 14:56:34 +00:00
get().to(get_unread_registration_application_count),
)
.route(
"/registration_application/list",
2024-11-28 14:56:34 +00:00
get().to(list_registration_applications),
)
.route(
"/registration_application/approve",
2024-11-28 14:56:34 +00:00
put().to(approve_registration_application),
)
.route(
"/registration_application",
2024-11-28 14:56:34 +00:00
get().to(get_registration_application),
)
2024-11-28 14:56:34 +00:00
.route("/list_all_media", get().to(list_all_media))
.service(
2024-11-28 14:56:34 +00:00
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)),
Feature/custom emoji and tagline views (#4580) * Add custom_emoji list route * Add tagline list route * Apply linting * Remove unecessary TaglineView * Add category filter for custom emoji * Add create tagline endpoint * Add update tagline endpoint * Add delete tagline endpoint * Format through lint.sh * Remove custom_emojis and taglines from site resource * Get random tagline on site requets * Impl Crud for Tagline Remove superfluous properties * Move tagline endpoints under /admin * Impl Crud for CustomEmoji * Remove delete from tagline and custom emoji impls * Check markdown for tagline * Validate markdown on tagline * Make content fields non optional Add error types for tagline validation * Use process_markdown instead of process_markdown_opt * Consolidate Tagline error types * Remove unecessary clone * Updat misleading comments * Remove local_site_id from tagline and custom_emoji * Update TaglineInserForm and TaglineUpdateForm * Add ignore_page_limits for custom emojis EmojiPicker needs to be able to retrieve all emojis in 1 call * Update custom_emoji_view Only keep get_all als helper function calling list with paging ignored Only order on category when filtering on category * Removing pointless get_all fn. * remove tagline length checks * make fields of TaglineInsertForm and TaglineUpdateForm mandatory * move emoji order statement * add comment for GetSiteResponse.tagline --------- Co-authored-by: Freakazoid182 <> Co-authored-by: SleeplessOne1917 <28871516+SleeplessOne1917@users.noreply.github.com> Co-authored-by: Dessalines <tyhou13@gmx.com> Co-authored-by: Felix Ableitner <me@nutomic.com>
2024-09-19 09:15:04 +00:00
)
.service(
2024-11-28 14:56:34 +00:00
scope("/tagline")
.route("", post().to(create_tagline))
.route("", put().to(update_tagline))
.route("/delete", post().to(delete_tagline))
.route("/list", get().to(list_taglines)),
2024-11-20 13:41:15 +00:00
)
2024-11-28 14:56:34 +00:00
.route("/ban", post().to(ban_from_site))
.route("/banned", get().to(list_banned_users))
.route("/leave", post().to(leave_admin)),
)
.service(
2024-11-28 14:56:34 +00:00
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(
2024-11-28 14:56:34 +00:00
scope("/oauth_provider")
.route("", post().to(create_oauth_provider))
.route("", put().to(update_oauth_provider))
.route("/delete", post().to(delete_oauth_provider)),
)
.service(
2024-11-28 14:56:34 +00:00
scope("/oauth")
.wrap(rate_limit.register())
2024-11-28 14:56:34 +00:00
.route("/authenticate", post().to(authenticate_with_oauth)),
2024-11-21 11:21:20 +00:00
)
2024-11-28 14:56:34 +00:00
.route("/sitemap.xml", get().to(get_sitemap)),
);
}