feat: Add public album routes and enhance authorization checks for media and albums
This commit is contained in:
@@ -13,7 +13,13 @@ use tower::ServiceExt;
|
||||
use tower_http::services::ServeFile;
|
||||
use uuid::Uuid;
|
||||
|
||||
use crate::{error::ApiError, extractors::query_options::ApiListMediaOptions, middleware::auth::UserId, schema::{MediaDetailsResponse, MediaMetadataResponse, MediaResponse}, state::AppState};
|
||||
use crate::{
|
||||
error::ApiError,
|
||||
extractors::query_options::ApiListMediaOptions,
|
||||
middleware::auth::{OptionalUserId, UserId},
|
||||
schema::{MediaDetailsResponse, MediaMetadataResponse, MediaResponse},
|
||||
state::AppState,
|
||||
};
|
||||
|
||||
pub fn media_routes(max_upload_size: usize) -> Router<AppState> {
|
||||
Router::new()
|
||||
@@ -62,7 +68,7 @@ async fn upload_media(
|
||||
|
||||
async fn get_media_file(
|
||||
State(state): State<AppState>,
|
||||
UserId(user_id): UserId,
|
||||
OptionalUserId(user_id): OptionalUserId,
|
||||
Path(media_id): Path<Uuid>,
|
||||
request: Request,
|
||||
) -> Result<impl IntoResponse, ApiError> {
|
||||
@@ -86,7 +92,7 @@ async fn get_media_file(
|
||||
|
||||
async fn get_media_details(
|
||||
State(state): State<AppState>,
|
||||
UserId(user_id): UserId,
|
||||
OptionalUserId(user_id): OptionalUserId,
|
||||
Path(id): Path<Uuid>,
|
||||
) -> Result<Json<MediaDetailsResponse>, ApiError> {
|
||||
let bundle = state.media_service.get_media_details(id, user_id).await?;
|
||||
@@ -97,13 +103,13 @@ async fn get_media_details(
|
||||
mime_type: bundle.media.mime_type,
|
||||
hash: bundle.media.hash,
|
||||
thumbnail_path: bundle.media.thumbnail_path,
|
||||
metadata: bundle.metadata
|
||||
metadata: bundle
|
||||
.metadata
|
||||
.into_iter()
|
||||
.map(MediaMetadataResponse::from)
|
||||
.collect(),
|
||||
};
|
||||
|
||||
|
||||
Ok(Json(response))
|
||||
}
|
||||
|
||||
@@ -120,7 +126,7 @@ async fn list_user_media(
|
||||
State(state): State<AppState>,
|
||||
UserId(user_id): UserId,
|
||||
ApiListMediaOptions(options): ApiListMediaOptions,
|
||||
) -> Result<Json<Vec<MediaResponse>>, ApiError> {
|
||||
) -> Result<Json<Vec<MediaResponse>>, ApiError> {
|
||||
let media_list = state
|
||||
.media_service
|
||||
.list_user_media(user_id, options)
|
||||
@@ -128,4 +134,4 @@ async fn list_user_media(
|
||||
|
||||
let response = media_list.into_iter().map(MediaResponse::from).collect();
|
||||
Ok(Json(response))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
pub mod album_handlers;
|
||||
pub mod auth_handlers;
|
||||
pub mod media_handlers;
|
||||
pub mod user_handlers;
|
||||
pub mod person_handlers;
|
||||
pub mod public_handlers;
|
||||
pub mod tag_handlers;
|
||||
pub mod person_handlers;
|
||||
pub mod user_handlers;
|
||||
|
||||
33
libertas_api/src/handlers/public_handlers.rs
Normal file
33
libertas_api/src/handlers/public_handlers.rs
Normal file
@@ -0,0 +1,33 @@
|
||||
use axum::{
|
||||
Json, Router,
|
||||
extract::{Path, State},
|
||||
routing::get,
|
||||
};
|
||||
use uuid::Uuid;
|
||||
|
||||
use crate::{
|
||||
error::ApiError,
|
||||
schema::{AlbumResponse, MediaResponse, PublicAlbumBundleResponse},
|
||||
state::AppState,
|
||||
};
|
||||
|
||||
pub fn public_routes() -> Router<AppState> {
|
||||
Router::new().route("/public/albums/{id}", get(get_public_album))
|
||||
}
|
||||
|
||||
async fn get_public_album(
|
||||
State(state): State<AppState>,
|
||||
Path(album_id): Path<Uuid>,
|
||||
) -> Result<Json<PublicAlbumBundleResponse>, ApiError> {
|
||||
let bundle = state
|
||||
.album_service
|
||||
.get_public_album_bundle(album_id)
|
||||
.await?;
|
||||
|
||||
let response = PublicAlbumBundleResponse {
|
||||
album: AlbumResponse::from(bundle.album),
|
||||
media: bundle.media.into_iter().map(MediaResponse::from).collect(),
|
||||
};
|
||||
|
||||
Ok(Json(response))
|
||||
}
|
||||
Reference in New Issue
Block a user