about summary refs log tree commit diff
path: root/kittybox-rs
diff options
context:
space:
mode:
authorVika <vika@fireburn.ru>2023-07-22 19:56:33 +0300
committerVika <vika@fireburn.ru>2023-07-22 19:56:33 +0300
commit8ab17c76a2e9f20bc27d9c765cd2f3779a0d7e13 (patch)
tree63783576c911ee1c04064ffabda2d31c91a5bb68 /kittybox-rs
parent5b0f56d6557df71c1da7e9ab6feaeda791d0183d (diff)
downloadkittybox-8ab17c76a2e9f20bc27d9c765cd2f3779a0d7e13.tar.zst
media: fix Axum behavior change with slashes in passed paths
Diffstat (limited to 'kittybox-rs')
-rw-r--r--kittybox-rs/src/media/storage/file.rs13
1 files changed, 7 insertions, 6 deletions
diff --git a/kittybox-rs/src/media/storage/file.rs b/kittybox-rs/src/media/storage/file.rs
index 59723d5..0aaaa3b 100644
--- a/kittybox-rs/src/media/storage/file.rs
+++ b/kittybox-rs/src/media/storage/file.rs
@@ -141,7 +141,8 @@ impl MediaStore for FileStore {
         domain: &str,
         filename: &str,
     ) -> Result<(Metadata, Pin<Box<dyn tokio_stream::Stream<Item = std::io::Result<bytes::Bytes>> + Send>>)> {
-        let path = self.base.join(format!("{}/{}", domain, filename));
+        debug!("Domain: {}, filename: {}", domain, filename);
+        let path = self.base.join(domain).join(filename);
         debug!("Path: {}", path.display());
 
         let file = OpenOptions::new()
@@ -165,7 +166,7 @@ impl MediaStore for FileStore {
 
     #[tracing::instrument(skip(self))]
     async fn metadata(&self, domain: &str, filename: &str) -> Result<Metadata> {
-        let metapath = self.base.join(format!("{}{}.json", domain, filename));
+        let metapath = self.base.join(domain).join(format!("{}.json", filename));
         debug!("Metadata path: {}", metapath.display());
 
         let meta = serde_json::from_slice(&tokio::fs::read(metapath).await?)
@@ -291,7 +292,7 @@ mod tests {
         // try to read range
         let range = {
             let stream = store.stream_range(
-                "fireburn.ru", &("/".to_string() + &filename),
+                "fireburn.ru", &filename,
                 (Bound::Included(0), Bound::Included(299))
             ).await.unwrap();
 
@@ -310,7 +311,7 @@ mod tests {
 
         let range = {
             let stream = store.stream_range(
-                "fireburn.ru", &("/".to_string() + &filename),
+                "fireburn.ru", &filename,
                 (Bound::Included(150), Bound::Included(449))
             ).await.unwrap();
 
@@ -328,7 +329,7 @@ mod tests {
         tracing::debug!("Reading range from the end...");
         let range = {
             let stream = store.stream_range(
-                "fireburn.ru", &("/".to_string() + &filename),
+                "fireburn.ru", &filename,
                 // Note: the `headers` crate parses bounds in a
                 // non-standard way, where unbounded start actually
                 // means getting things from the end...
@@ -413,7 +414,7 @@ mod tests {
         let (metadata, read_back) = {
             let (metadata, stream) = store.read_streaming(
                 "fireburn.ru",
-                &("/".to_string() + &filename)
+                &filename
             ).await.unwrap();
             let mut reader = tokio_util::io::StreamReader::new(stream);