From 9e0b91d39a3770e0422ca1c962a91daf5671506e Mon Sep 17 00:00:00 2001 From: Dessalines Date: Wed, 13 Mar 2024 17:02:23 -0400 Subject: [PATCH] Adding an endpoint to list all images, for admins only. --- crates/api/src/local_user/list_media.rs | 2 -- crates/api/src/site/mod.rs | 1 + crates/db_schema/src/impls/images.rs | 17 +++++++++++++++++ src/api_routes_http.rs | 2 ++ 4 files changed, 20 insertions(+), 2 deletions(-) diff --git a/crates/api/src/local_user/list_media.rs b/crates/api/src/local_user/list_media.rs index 8bb26bd14..3cc21b251 100644 --- a/crates/api/src/local_user/list_media.rs +++ b/crates/api/src/local_user/list_media.rs @@ -7,8 +7,6 @@ use lemmy_db_schema::source::images::LocalImage; use lemmy_db_views::structs::LocalUserView; use lemmy_utils::error::LemmyError; -/// Lists comment reports for a community if an id is supplied -/// or returns all comment reports for communities a user moderates #[tracing::instrument(skip(context))] pub async fn list_media( data: Query, diff --git a/crates/api/src/site/mod.rs b/crates/api/src/site/mod.rs index d63c77ad9..f18dea3d0 100644 --- a/crates/api/src/site/mod.rs +++ b/crates/api/src/site/mod.rs @@ -1,6 +1,7 @@ pub mod block; pub mod federated_instances; pub mod leave_admin; +pub mod list_all_media; pub mod mod_log; pub mod purge; pub mod registration_applications; diff --git a/crates/db_schema/src/impls/images.rs b/crates/db_schema/src/impls/images.rs index 01cd76247..cc67d9b9d 100644 --- a/crates/db_schema/src/impls/images.rs +++ b/crates/db_schema/src/impls/images.rs @@ -49,6 +49,23 @@ impl LocalImage { .await } + pub async fn get_all( + pool: &mut DbPool<'_>, + page: Option, + limit: Option, + ) -> Result, Error> { + let conn = &mut get_conn(pool).await?; + let (limit, offset) = limit_and_offset(page, limit)?; + + local_image::table + .select(local_image::all_columns) + .order_by(local_image::published.desc()) + .limit(limit) + .offset(offset) + .load::(conn) + .await + } + pub async fn delete_by_alias(pool: &mut DbPool<'_>, alias: &str) -> Result { let conn = &mut get_conn(pool).await?; diesel::delete(local_image::table.filter(local_image::pictrs_alias.eq(alias))) diff --git a/src/api_routes_http.rs b/src/api_routes_http.rs index c67f21c44..bba3578a3 100644 --- a/src/api_routes_http.rs +++ b/src/api_routes_http.rs @@ -72,6 +72,7 @@ use lemmy_api::{ 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, @@ -341,6 +342,7 @@ pub fn config(cfg: &mut web::ServiceConfig, rate_limit: &RateLimitCell) { "/registration_application/approve", web::put().to(approve_registration_application), ) + .route("/list_media", web::get().to(list_all_media)) .service( web::scope("/purge") .route("/person", web::post().to(purge_person))