292 lines
6.4 KiB
Rust
292 lines
6.4 KiB
Rust
use libertas_core::models::{
|
|
Album, AlbumPermission, FaceRegion, Media, MediaBundle, MediaMetadata, Person,
|
|
PersonPermission, Tag,
|
|
};
|
|
use libertas_core::schema::PaginatedResponse as CorePaginatedResponse;
|
|
use serde::{Deserialize, Serialize};
|
|
use uuid::Uuid;
|
|
|
|
#[derive(Serialize)]
|
|
pub struct MediaResponse {
|
|
pub id: uuid::Uuid,
|
|
pub original_filename: String,
|
|
pub mime_type: String,
|
|
pub hash: String,
|
|
pub file_url: String,
|
|
pub thumbnail_url: Option<String>,
|
|
}
|
|
|
|
impl From<Media> for MediaResponse {
|
|
fn from(media: Media) -> Self {
|
|
Self {
|
|
id: media.id,
|
|
original_filename: media.original_filename,
|
|
mime_type: media.mime_type,
|
|
hash: media.hash,
|
|
file_url: format!("/api/v1/media/{}/file", media.id),
|
|
thumbnail_url: media
|
|
.thumbnail_path
|
|
.map(|_| format!("/api/v1/media/{}/thumbnail", media.id)),
|
|
}
|
|
}
|
|
}
|
|
|
|
#[derive(Deserialize)]
|
|
pub struct ListMediaParams {
|
|
pub sort_by: Option<String>,
|
|
pub order: Option<String>,
|
|
pub mime_type: Option<String>,
|
|
#[serde(default)]
|
|
pub metadata: Vec<String>,
|
|
pub page: Option<u32>,
|
|
pub limit: Option<u32>,
|
|
}
|
|
|
|
#[derive(Deserialize)]
|
|
pub struct CreateAlbumRequest {
|
|
pub name: String,
|
|
pub description: Option<String>,
|
|
pub is_public: Option<bool>,
|
|
}
|
|
|
|
#[derive(Deserialize)]
|
|
pub struct AddMediaToAlbumRequest {
|
|
pub media_ids: Vec<Uuid>,
|
|
}
|
|
|
|
#[derive(Deserialize)]
|
|
pub struct ShareAlbumRequest {
|
|
pub target_user_id: Uuid,
|
|
pub permission: AlbumPermission,
|
|
}
|
|
|
|
#[derive(Serialize)]
|
|
pub struct AlbumResponse {
|
|
pub id: Uuid,
|
|
pub owner_id: Uuid,
|
|
pub name: String,
|
|
pub description: Option<String>,
|
|
pub is_public: bool,
|
|
pub created_at: chrono::DateTime<chrono::Utc>,
|
|
pub updated_at: chrono::DateTime<chrono::Utc>,
|
|
}
|
|
|
|
impl From<Album> for AlbumResponse {
|
|
fn from(album: Album) -> Self {
|
|
Self {
|
|
id: album.id,
|
|
owner_id: album.owner_id,
|
|
name: album.name,
|
|
description: album.description,
|
|
is_public: album.is_public,
|
|
created_at: album.created_at,
|
|
updated_at: album.updated_at,
|
|
}
|
|
}
|
|
}
|
|
|
|
#[derive(Deserialize)]
|
|
pub struct UpdateAlbumRequest {
|
|
pub name: Option<String>,
|
|
pub description: Option<Option<String>>,
|
|
pub is_public: Option<bool>,
|
|
}
|
|
|
|
#[derive(Deserialize)]
|
|
pub struct RegisterRequest {
|
|
pub username: String,
|
|
pub email: String,
|
|
pub password: String,
|
|
}
|
|
|
|
#[derive(Deserialize)]
|
|
pub struct LoginRequest {
|
|
pub username_or_email: String,
|
|
pub password: String,
|
|
}
|
|
|
|
#[derive(Serialize)]
|
|
pub struct LoginResponse {
|
|
pub token: String,
|
|
}
|
|
|
|
#[derive(Serialize)]
|
|
pub struct UserResponse {
|
|
pub id: Uuid,
|
|
pub username: String,
|
|
pub email: String,
|
|
}
|
|
|
|
#[derive(Serialize)]
|
|
pub struct MediaMetadataResponse {
|
|
pub source: String,
|
|
pub tag_name: String,
|
|
pub tag_value: String,
|
|
}
|
|
|
|
impl From<MediaMetadata> for MediaMetadataResponse {
|
|
fn from(metadata: MediaMetadata) -> Self {
|
|
Self {
|
|
source: metadata.source.as_str().to_string(),
|
|
tag_name: metadata.tag_name,
|
|
tag_value: metadata.tag_value,
|
|
}
|
|
}
|
|
}
|
|
|
|
#[derive(Serialize)]
|
|
pub struct MediaDetailsResponse {
|
|
#[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,
|
|
pub name: String,
|
|
}
|
|
|
|
impl From<Tag> for TagResponse {
|
|
fn from(tag: Tag) -> Self {
|
|
Self {
|
|
id: tag.id,
|
|
name: tag.name,
|
|
}
|
|
}
|
|
}
|
|
|
|
#[derive(Deserialize)]
|
|
pub struct MediaTagsRequest {
|
|
pub tags: Vec<String>,
|
|
}
|
|
|
|
#[derive(Serialize)]
|
|
pub struct PersonResponse {
|
|
pub id: Uuid,
|
|
pub owner_id: Uuid,
|
|
pub name: String,
|
|
}
|
|
|
|
impl From<Person> for PersonResponse {
|
|
fn from(person: Person) -> Self {
|
|
Self {
|
|
id: person.id,
|
|
owner_id: person.owner_id,
|
|
name: person.name,
|
|
}
|
|
}
|
|
}
|
|
|
|
#[derive(Deserialize)]
|
|
pub struct CreatePersonRequest {
|
|
pub name: String,
|
|
}
|
|
|
|
#[derive(Deserialize)]
|
|
pub struct UpdatePersonRequest {
|
|
pub name: String,
|
|
}
|
|
|
|
#[derive(Serialize)]
|
|
pub struct FaceRegionResponse {
|
|
pub id: Uuid,
|
|
pub media_id: Uuid,
|
|
pub person_id: Option<Uuid>,
|
|
pub x_min: f32,
|
|
pub y_min: f32,
|
|
pub x_max: f32,
|
|
pub y_max: f32,
|
|
}
|
|
|
|
impl From<FaceRegion> for FaceRegionResponse {
|
|
fn from(face: FaceRegion) -> Self {
|
|
Self {
|
|
id: face.id,
|
|
media_id: face.media_id,
|
|
person_id: face.person_id,
|
|
x_min: face.x_min,
|
|
y_min: face.y_min,
|
|
x_max: face.x_max,
|
|
y_max: face.y_max,
|
|
}
|
|
}
|
|
}
|
|
|
|
#[derive(Deserialize)]
|
|
pub struct AssignFaceRequest {
|
|
pub person_id: Uuid,
|
|
}
|
|
|
|
#[derive(Deserialize)]
|
|
pub struct SharePersonRequest {
|
|
pub target_user_id: Uuid,
|
|
pub permission: PersonPermission,
|
|
}
|
|
|
|
#[derive(Serialize)]
|
|
pub struct PublicAlbumBundleResponse {
|
|
pub album: AlbumResponse,
|
|
pub media: Vec<MediaResponse>,
|
|
}
|
|
|
|
#[derive(Deserialize)]
|
|
pub struct MergePersonRequest {
|
|
pub source_person_id: Uuid,
|
|
}
|
|
|
|
#[derive(Serialize)]
|
|
pub struct PaginatedResponse<T> {
|
|
pub data: Vec<T>,
|
|
pub page: u32,
|
|
pub limit: u32,
|
|
pub total_items: i64,
|
|
pub total_pages: u32,
|
|
pub has_next_page: bool,
|
|
pub has_prev_page: bool,
|
|
}
|
|
|
|
pub fn map_paginated_response<T, U>(core_response: CorePaginatedResponse<T>) -> PaginatedResponse<U>
|
|
where
|
|
U: From<T>,
|
|
{
|
|
PaginatedResponse {
|
|
data: core_response.data.into_iter().map(U::from).collect(),
|
|
page: core_response.page,
|
|
limit: core_response.limit,
|
|
total_items: core_response.total_items,
|
|
total_pages: core_response.total_pages,
|
|
has_next_page: core_response.has_next_page,
|
|
has_prev_page: core_response.has_prev_page,
|
|
}
|
|
}
|
|
|
|
#[derive(Deserialize)]
|
|
pub struct ServeFileQuery {
|
|
#[serde(default)]
|
|
pub strip: bool,
|
|
}
|
|
|
|
#[derive(Deserialize)]
|
|
pub struct SetThumbnailRequest {
|
|
pub media_id: Uuid,
|
|
}
|
|
|
|
#[derive(Deserialize)]
|
|
pub struct SetPersonThumbnailRequest {
|
|
pub face_region_id: Uuid,
|
|
}
|