mirror of https://github.com/LemmyNet/lemmy
Adding listMedia endpoint, to view all your local image uploads. (#4509)
* 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>pull/4429/merge
parent
945064726f
commit
6bfbb9332d
@ -0,0 +1,26 @@
|
||||
use actix_web::web::{Data, Json, Query};
|
||||
use lemmy_api_common::{
|
||||
context::LemmyContext,
|
||||
person::{ListMedia, ListMediaResponse},
|
||||
};
|
||||
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_media(
|
||||
data: Query<ListMedia>,
|
||||
context: Data<LemmyContext>,
|
||||
local_user_view: LocalUserView,
|
||||
) -> Result<Json<ListMediaResponse>, LemmyError> {
|
||||
let page = data.page;
|
||||
let limit = data.limit;
|
||||
let images = LocalImage::get_all_paged_by_local_user_id(
|
||||
&mut context.pool(),
|
||||
local_user_view.local_user.id,
|
||||
page,
|
||||
limit,
|
||||
)
|
||||
.await?;
|
||||
Ok(Json(ListMediaResponse { images }))
|
||||
}
|
@ -0,0 +1,24 @@
|
||||
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 }))
|
||||
}
|
@ -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;
|
||||
|
Loading…
Reference in New Issue