feat: streaming video download via ImageStorage::get_stream
Some checks failed
CI / Check / Test (push) Failing after 41s

This commit is contained in:
2026-06-02 23:45:31 +02:00
parent f160adcd1c
commit 1e063b6580
10 changed files with 93 additions and 9 deletions

View File

@@ -8,6 +8,8 @@ domain = { workspace = true }
anyhow = { workspace = true }
async-trait = { workspace = true }
tracing = { workspace = true }
bytes = { workspace = true }
futures = { workspace = true }
object_store = { workspace = true }
infer = "0.19.0"

View File

@@ -7,6 +7,7 @@ use domain::{
events::DomainEvent,
ports::{EventHandler, ImageStorage},
};
use futures::StreamExt;
use object_store::{ObjectStore, path::Path};
use std::sync::Arc;
@@ -48,6 +49,24 @@ impl ImageStorage for ImageStorageAdapter {
.map_err(|e| DomainError::InfrastructureError(e.to_string()))
}
async fn get_stream(
&self,
key: &str,
) -> Result<futures::stream::BoxStream<'static, Result<bytes::Bytes, DomainError>>, DomainError>
{
let path = Path::from(key);
let result = self.store.get(&path).await.map_err(|e| match e {
object_store::Error::NotFound { .. } => DomainError::NotFound("not found".into()),
_ => DomainError::InfrastructureError(e.to_string()),
})?;
let stream = result.into_stream().map(|chunk| {
chunk
.map(|b| bytes::Bytes::from(b.to_vec()))
.map_err(|e| DomainError::InfrastructureError(e.to_string()))
});
Ok(Box::pin(stream))
}
async fn delete(&self, key: &str) -> Result<(), DomainError> {
let path = Path::from(key);
match self.store.delete(&path).await {