feat: Add media thumbnail retrieval functionality and update MediaResponse structure
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
use libertas_core::models::{
|
||||
Album, AlbumPermission, FaceRegion, Media, MediaMetadata, Person, PersonPermission, Tag,
|
||||
Album, AlbumPermission, FaceRegion, Media, MediaBundle, MediaMetadata, Person,
|
||||
PersonPermission, Tag,
|
||||
};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use uuid::Uuid;
|
||||
@@ -7,22 +8,24 @@ use uuid::Uuid;
|
||||
#[derive(Serialize)]
|
||||
pub struct MediaResponse {
|
||||
pub id: uuid::Uuid,
|
||||
pub storage_path: String,
|
||||
pub original_filename: String,
|
||||
pub mime_type: String,
|
||||
pub hash: String,
|
||||
pub thumbnail_path: Option<String>,
|
||||
pub file_url: String,
|
||||
pub thumbnail_url: Option<String>,
|
||||
}
|
||||
|
||||
impl From<Media> for MediaResponse {
|
||||
fn from(media: Media) -> Self {
|
||||
Self {
|
||||
id: media.id,
|
||||
storage_path: media.storage_path,
|
||||
original_filename: media.original_filename,
|
||||
mime_type: media.mime_type,
|
||||
hash: media.hash,
|
||||
thumbnail_path: media.thumbnail_path,
|
||||
file_url: format!("/api/v1/media/{}/file", media.id),
|
||||
thumbnail_url: media
|
||||
.thumbnail_path
|
||||
.map(|_| format!("/api/v1/media/{}/thumbnail", media.id)),
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -130,15 +133,24 @@ impl From<MediaMetadata> for MediaMetadataResponse {
|
||||
|
||||
#[derive(Serialize)]
|
||||
pub struct MediaDetailsResponse {
|
||||
pub id: uuid::Uuid,
|
||||
pub storage_path: String,
|
||||
pub original_filename: String,
|
||||
pub mime_type: String,
|
||||
pub hash: String,
|
||||
pub thumbnail_path: Option<String>,
|
||||
#[serde(flatten)]
|
||||
pub media: MediaResponse,
|
||||
pub metadata: Vec<MediaMetadataResponse>,
|
||||
}
|
||||
|
||||
impl From<MediaBundle> for MediaDetailsResponse {
|
||||
fn from(bundle: MediaBundle) -> Self {
|
||||
Self {
|
||||
media: MediaResponse::from(bundle.media),
|
||||
metadata: bundle
|
||||
.metadata
|
||||
.into_iter()
|
||||
.map(MediaMetadataResponse::from)
|
||||
.collect(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Serialize)]
|
||||
pub struct TagResponse {
|
||||
pub id: Uuid,
|
||||
|
||||
Reference in New Issue
Block a user