about summary refs log tree commit diff
path: root/src/media
diff options
context:
space:
mode:
Diffstat (limited to 'src/media')
-rw-r--r--src/media/storage/file.rs11
-rw-r--r--src/media/storage/mod.rs2
2 files changed, 7 insertions, 6 deletions
diff --git a/src/media/storage/file.rs b/src/media/storage/file.rs
index a910eca..7250a6b 100644
--- a/src/media/storage/file.rs
+++ b/src/media/storage/file.rs
@@ -31,10 +31,6 @@ impl From<tokio::io::Error> for MediaStoreError {
 }
 
 impl FileStore {
-    pub fn new<T: Into<PathBuf>>(base: T) -> Self {
-        Self { base: base.into() }
-    }
-
     async fn mktemp(&self) -> Result<(PathBuf, BufWriter<tokio::fs::File>)> {
         kittybox_util::fs::mktemp(&self.base, "temp", 16)
             .await
@@ -45,6 +41,9 @@ impl FileStore {
 
 #[async_trait]
 impl MediaStore for FileStore {
+    async fn new(url: &'_ url::Url) -> Result<Self> {
+        Ok(Self { base: url.path().into() })
+    }
 
     #[tracing::instrument(skip(self, content))]
     async fn write_streaming<T>(
@@ -261,7 +260,7 @@ mod tests {
     #[tracing_test::traced_test]
     async fn test_ranges() {
         let tempdir = tempfile::tempdir().expect("Failed to create tempdir");
-        let store = FileStore::new(tempdir.path());
+        let store = FileStore { base: tempdir.path().to_path_buf() };
 
         let file: &[u8] = include_bytes!("./file.rs");
         let stream = tokio_stream::iter(file.chunks(100).map(|i| Ok(bytes::Bytes::copy_from_slice(i))));
@@ -372,7 +371,7 @@ mod tests {
     #[tracing_test::traced_test]
     async fn test_streaming_read_write() {
         let tempdir = tempfile::tempdir().expect("Failed to create tempdir");
-        let store = FileStore::new(tempdir.path());
+        let store = FileStore { base: tempdir.path().to_path_buf() };
 
         let file: &[u8] = include_bytes!("./file.rs");
         let stream = tokio_stream::iter(file.chunks(100).map(|i| Ok(bytes::Bytes::copy_from_slice(i))));
diff --git a/src/media/storage/mod.rs b/src/media/storage/mod.rs
index 020999c..38410e6 100644
--- a/src/media/storage/mod.rs
+++ b/src/media/storage/mod.rs
@@ -86,6 +86,8 @@ pub type Result<T> = std::result::Result<T, MediaStoreError>;
 
 #[async_trait]
 pub trait MediaStore: 'static + Send + Sync + Clone {
+    // Initialize self from a URL, possibly performing asynchronous initialization.
+    async fn new(url: &'_ url::Url) -> Result<Self>;
     async fn write_streaming<T>(
         &self,
         domain: &str,