1use crate::chunk::ChunkHash;
4use serde::{Deserialize, Serialize};
5use uuid::Uuid;
6
7#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
9pub struct FileId(pub Uuid);
10
11impl FileId {
12 pub fn new() -> Self {
14 Self(Uuid::new_v4())
15 }
16
17 pub fn from_uuid(uuid: Uuid) -> Self {
19 Self(uuid)
20 }
21}
22
23impl Default for FileId {
24 fn default() -> Self {
25 Self::new()
26 }
27}
28
29impl std::fmt::Display for FileId {
30 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
31 write!(f, "{}", self.0)
32 }
33}
34
35#[derive(Debug, Clone, Serialize, Deserialize)]
37pub struct FileMetadata {
38 pub id: FileId,
40 pub name: String,
42 pub mime_type: Option<String>,
44 pub size: u64,
46 pub created_at: i64,
48 pub modified_at: i64,
50 pub content_hash: ChunkHash,
52}
53
54#[derive(Debug, Clone, Serialize, Deserialize)]
56pub struct FileManifest {
57 pub metadata: FileMetadata,
59 pub chunks: Vec<ChunkHash>,
61 pub encrypted_dek: Option<Vec<u8>>,
63 pub salt: Option<Vec<u8>>,
65 pub version: u64,
67}
68
69impl FileManifest {
70 pub fn new(metadata: FileMetadata, chunks: Vec<ChunkHash>) -> Self {
72 Self {
73 metadata,
74 chunks,
75 encrypted_dek: None,
76 salt: None,
77 version: 1,
78 }
79 }
80
81 pub fn chunk_count(&self) -> usize {
83 self.chunks.len()
84 }
85}