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