2024-03-26 16:06:11 +00:00
|
|
|
use actix_web::web::{Data, Json, Query};
|
|
|
|
use lemmy_api_common::{
|
|
|
|
context::LemmyContext,
|
|
|
|
person::{ListMedia, ListMediaResponse},
|
|
|
|
utils::is_admin,
|
|
|
|
};
|
2024-04-16 23:20:44 +00:00
|
|
|
use lemmy_db_views::structs::{LocalImageView, LocalUserView};
|
2024-04-10 14:14:11 +00:00
|
|
|
use lemmy_utils::error::LemmyResult;
|
2024-03-26 16:06:11 +00:00
|
|
|
|
|
|
|
#[tracing::instrument(skip(context))]
|
|
|
|
pub async fn list_all_media(
|
|
|
|
data: Query<ListMedia>,
|
|
|
|
context: Data<LemmyContext>,
|
|
|
|
local_user_view: LocalUserView,
|
2024-04-10 14:14:11 +00:00
|
|
|
) -> LemmyResult<Json<ListMediaResponse>> {
|
2024-03-26 16:06:11 +00:00
|
|
|
// Only let admins view all media
|
|
|
|
is_admin(&local_user_view)?;
|
|
|
|
|
|
|
|
let page = data.page;
|
|
|
|
let limit = data.limit;
|
2024-04-16 23:20:44 +00:00
|
|
|
let images = LocalImageView::get_all(&mut context.pool(), page, limit).await?;
|
2024-03-26 16:06:11 +00:00
|
|
|
Ok(Json(ListMediaResponse { images }))
|
|
|
|
}
|