Skip to main content

rskit_storage/store/
traits.rs

1use std::time::Duration;
2
3use rskit_errors::AppResult;
4
5use crate::FileSource;
6
7use super::{StoredFile, UploadOptions};
8
9/// Trait for file storage backends.
10#[async_trait::async_trait]
11pub trait FileStore: Send + Sync {
12    /// Upload a file to the store.
13    ///
14    /// `options` carries the content type, user metadata, and an optional
15    /// progress callback; use [`UploadOptions::new`] for store defaults.
16    async fn upload(
17        &self,
18        source: &FileSource,
19        key: &str,
20        options: UploadOptions,
21    ) -> AppResult<StoredFile>;
22
23    /// Download a file from the store.
24    async fn download(&self, key: &str) -> AppResult<FileSource>;
25
26    /// Delete a file from the store.
27    async fn delete(&self, key: &str) -> AppResult<()>;
28
29    /// Check if a file exists in the store.
30    async fn exists(&self, key: &str) -> AppResult<bool>;
31
32    /// Get metadata about a stored file without downloading it.
33    async fn head(&self, key: &str) -> AppResult<StoredFile>;
34
35    /// List files with a given prefix.
36    async fn list(&self, prefix: &str, limit: Option<usize>) -> AppResult<Vec<StoredFile>>;
37
38    /// Generate a presigned URL for temporary access.
39    async fn presigned_url(&self, key: &str, expires_in: Duration) -> AppResult<String>;
40
41    /// Copy a file within the store.
42    async fn copy(&self, from_key: &str, to_key: &str) -> AppResult<StoredFile>;
43
44    /// Rename (move) a file within the store.
45    async fn rename(&self, from_key: &str, to_key: &str) -> AppResult<StoredFile>;
46}