use chrono::{DateTime, Utc};
use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct FileMetadata {
pub path: String,
pub size: u64,
pub content_type: Option<String>,
pub created_at: DateTime<Utc>,
pub modified_at: DateTime<Utc>,
pub checksum: Option<String>,
}
impl FileMetadata {
pub fn new(path: String, size: u64) -> Self {
let now = Utc::now();
Self {
path,
size,
content_type: None,
created_at: now,
modified_at: now,
checksum: None,
}
}
pub fn with_content_type(mut self, content_type: String) -> Self {
self.content_type = Some(content_type);
self
}
pub fn with_checksum(mut self, checksum: String) -> Self {
self.checksum = Some(checksum);
self
}
}
#[derive(Debug)]
pub struct StoredFile {
pub metadata: FileMetadata,
pub content: Vec<u8>,
}
impl StoredFile {
pub fn new(metadata: FileMetadata, content: Vec<u8>) -> Self {
Self { metadata, content }
}
pub fn size(&self) -> u64 {
self.content.len() as u64
}
}