rskit_storage/store/
model.rs1use std::collections::HashMap;
2
3use chrono::{DateTime, Utc};
4use serde::{Deserialize, Serialize};
5
6pub const DEFAULT_CONTENT_TYPE: &str = "application/octet-stream";
8
9#[derive(Debug, Clone, Serialize, Deserialize)]
11pub struct StoredFile {
12 pub key: String,
14 pub size: u64,
16 pub content_type: String,
18 pub stored_at: DateTime<Utc>,
20 pub metadata: HashMap<String, String>,
22}
23
24impl StoredFile {
25 #[must_use]
27 pub fn new(key: impl Into<String>, size: u64, content_type: Option<&str>) -> Self {
28 Self {
29 key: key.into(),
30 size,
31 content_type: content_type_or_default(content_type).to_string(),
32 stored_at: Utc::now(),
33 metadata: HashMap::new(),
34 }
35 }
36
37 #[must_use]
39 pub fn with_metadata(mut self, metadata: HashMap<String, String>) -> Self {
40 self.metadata = metadata;
41 self
42 }
43
44 #[must_use]
46 pub fn with_stored_at(mut self, stored_at: DateTime<Utc>) -> Self {
47 self.stored_at = stored_at;
48 self
49 }
50}
51
52#[must_use]
54pub fn content_type_or_default(content_type: Option<&str>) -> &str {
55 content_type
56 .map(str::trim)
57 .filter(|value| !value.is_empty())
58 .unwrap_or(DEFAULT_CONTENT_TYPE)
59}