mirror of
https://github.com/LemmyNet/lemmy.git
synced 2024-05-09 21:42:39 +00:00
6bfbb9332d
* Adding listMedia endpoint, to view all your local image uploads. - Fixes #4445 * Fix ts import. * Forgot to order by published desc * Adding an endpoint to list all images, for admins only. * Forgot to add file. * Add additional test. * Use better logic for no-limit version. * Better call sites. * Adding another test. * Fix tests. * Moving list_media to /account action. * Addressing PR comments. * Removing pointless comment. --------- Co-authored-by: SleeplessOne1917 <28871516+SleeplessOne1917@users.noreply.github.com>
25 lines
731 B
Rust
25 lines
731 B
Rust
use actix_web::web::{Data, Json, Query};
|
|
use lemmy_api_common::{
|
|
context::LemmyContext,
|
|
person::{ListMedia, ListMediaResponse},
|
|
utils::is_admin,
|
|
};
|
|
use lemmy_db_schema::source::images::LocalImage;
|
|
use lemmy_db_views::structs::LocalUserView;
|
|
use lemmy_utils::error::LemmyError;
|
|
|
|
#[tracing::instrument(skip(context))]
|
|
pub async fn list_all_media(
|
|
data: Query<ListMedia>,
|
|
context: Data<LemmyContext>,
|
|
local_user_view: LocalUserView,
|
|
) -> Result<Json<ListMediaResponse>, LemmyError> {
|
|
// Only let admins view all media
|
|
is_admin(&local_user_view)?;
|
|
|
|
let page = data.page;
|
|
let limit = data.limit;
|
|
let images = LocalImage::get_all(&mut context.pool(), page, limit).await?;
|
|
Ok(Json(ListMediaResponse { images }))
|
|
}
|