systemprompt_traits/
storage.rs1use anyhow::Result;
2use async_trait::async_trait;
3use std::path::Path;
4
5#[derive(Debug, Clone, PartialEq, Eq, Hash)]
7pub struct StoredFileId(pub String);
8
9impl StoredFileId {
10 #[must_use]
11 pub fn new(id: impl Into<String>) -> Self {
12 Self(id.into())
13 }
14
15 #[must_use]
16 pub fn as_str(&self) -> &str {
17 &self.0
18 }
19}
20
21impl From<String> for StoredFileId {
22 fn from(s: String) -> Self {
23 Self(s)
24 }
25}
26
27impl From<&str> for StoredFileId {
28 fn from(s: &str) -> Self {
29 Self(s.to_string())
30 }
31}
32
33impl std::fmt::Display for StoredFileId {
34 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
35 write!(f, "{}", self.0)
36 }
37}
38
39#[derive(Debug, Clone)]
41pub struct StoredFileMetadata {
42 pub id: StoredFileId,
43 pub path: String,
44 pub mime_type: String,
45 pub size_bytes: Option<i64>,
46 pub created_at: chrono::DateTime<chrono::Utc>,
47 pub updated_at: chrono::DateTime<chrono::Utc>,
48}
49
50#[async_trait]
55pub trait FileStorage: Send + Sync {
56 async fn store(&self, path: &Path, content: &[u8]) -> Result<StoredFileId>;
58
59 async fn retrieve(&self, id: &StoredFileId) -> Result<Vec<u8>>;
61
62 async fn delete(&self, id: &StoredFileId) -> Result<()>;
64
65 async fn metadata(&self, id: &StoredFileId) -> Result<StoredFileMetadata>;
67
68 async fn exists(&self, id: &StoredFileId) -> Result<bool>;
70
71 fn public_url(&self, _id: &StoredFileId) -> Option<String> {
73 None
74 }
75}