use serde::{Deserialize, Serialize}; use utoipa::ToSchema; use crate::domain::entities::share::Share; #[derive(Debug, Clone, Serialize, Deserialize, ToSchema)] pub struct ShareDto { pub id: String, pub item_id: String, pub item_name: Option, pub item_type: String, pub token: String, pub url: String, pub has_password: bool, pub expires_at: Option, pub created_at: u64, pub created_by: String, pub access_count: u64, /// File shares only: the shared file's MIME type, resolved at read time /// so anonymous viewers can render an inline media preview (video player /// / image) instead of a bare download button. Absent for folder shares /// and whenever the file lookup fails (display-only enrichment). #[serde(skip_serializing_if = "Option::is_none")] pub mime_type: Option, /// File shares only: the shared file's size in bytes (see `mime_type`). #[serde(skip_serializing_if = "Option::is_none")] pub size: Option, } #[derive(Debug, Clone, Serialize, Deserialize, ToSchema)] pub struct CreateShareDto { pub item_id: String, pub item_name: Option, pub item_type: String, pub password: Option, pub expires_at: Option, } #[derive(Debug, Clone, Serialize, Deserialize, ToSchema)] pub struct UpdateShareDto { pub password: Option, pub expires_at: Option, } impl ShareDto { pub fn from_entity(share: &Share, base_url: &str) -> Self { let url = format!("{}/s/{}", base_url, share.token()); Self { id: share.id().to_string(), item_id: share.item_id().to_string(), item_name: share.item_name().map(|s| s.to_string()), item_type: share.item_type().to_string(), token: share.token().to_string(), url, has_password: share.has_password(), expires_at: share.expires_at(), created_at: share.created_at(), created_by: share.created_by().to_string(), access_count: share.access_count(), mime_type: None, size: None, } } }