export feature
This commit is contained in:
@@ -22,9 +22,9 @@ impl StorageConfig {
|
||||
&std::env::var("POSTER_STORAGE_PATH")
|
||||
.context("POSTER_STORAGE_PATH required when POSTER_STORAGE_BACKEND=local")?,
|
||||
)?,
|
||||
other => anyhow::bail!(
|
||||
"Unknown POSTER_STORAGE_BACKEND: {other:?}. Valid values: s3, local"
|
||||
),
|
||||
other => {
|
||||
anyhow::bail!("Unknown POSTER_STORAGE_BACKEND: {other:?}. Valid values: s3, local")
|
||||
}
|
||||
};
|
||||
|
||||
Ok(Self(store))
|
||||
@@ -55,8 +55,7 @@ fn build_s3_store(
|
||||
}
|
||||
|
||||
fn build_local_store(path: &str) -> anyhow::Result<Arc<dyn ObjectStore>> {
|
||||
std::fs::create_dir_all(path)
|
||||
.context("Failed to create poster storage directory")?;
|
||||
std::fs::create_dir_all(path).context("Failed to create poster storage directory")?;
|
||||
let store = LocalFileSystem::new_with_prefix(path)
|
||||
.context("Failed to initialise local file system store")?;
|
||||
Ok(Arc::new(store))
|
||||
@@ -68,8 +67,7 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn local_store_creates_dir_and_succeeds() {
|
||||
let dir = std::env::temp_dir()
|
||||
.join(format!("poster_test_{}", uuid::Uuid::new_v4()));
|
||||
let dir = std::env::temp_dir().join(format!("poster_test_{}", uuid::Uuid::new_v4()));
|
||||
let result = build_local_store(dir.to_str().unwrap());
|
||||
assert!(result.is_ok(), "expected Ok, got: {:?}", result.err());
|
||||
assert!(dir.exists(), "directory should have been created");
|
||||
@@ -77,8 +75,7 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn local_store_succeeds_if_dir_already_exists() {
|
||||
let dir = std::env::temp_dir()
|
||||
.join(format!("poster_test_{}", uuid::Uuid::new_v4()));
|
||||
let dir = std::env::temp_dir().join(format!("poster_test_{}", uuid::Uuid::new_v4()));
|
||||
std::fs::create_dir_all(&dir).unwrap();
|
||||
let result = build_local_store(dir.to_str().unwrap());
|
||||
assert!(result.is_ok());
|
||||
|
||||
@@ -7,7 +7,7 @@ use domain::{
|
||||
ports::PosterStorage,
|
||||
value_objects::{MovieId, PosterPath},
|
||||
};
|
||||
use object_store::{Attribute, Attributes, PutOptions, path::Path, ObjectStore};
|
||||
use object_store::{Attribute, Attributes, ObjectStore, PutOptions, path::Path};
|
||||
use std::sync::Arc;
|
||||
|
||||
fn detect_mime(bytes: &[u8]) -> &'static str {
|
||||
@@ -41,7 +41,10 @@ impl PosterStorage for PosterStorageAdapter {
|
||||
let mime = detect_mime(image_bytes);
|
||||
let mut attributes = Attributes::new();
|
||||
attributes.insert(Attribute::ContentType, mime.into());
|
||||
let opts = PutOptions { attributes, ..Default::default() };
|
||||
let opts = PutOptions {
|
||||
attributes,
|
||||
..Default::default()
|
||||
};
|
||||
self.store
|
||||
.put_opts(&path, image_bytes.to_vec().into(), opts)
|
||||
.await
|
||||
@@ -52,7 +55,9 @@ impl PosterStorage for PosterStorageAdapter {
|
||||
async fn get_poster(&self, poster_path: &PosterPath) -> Result<Vec<u8>, DomainError> {
|
||||
let path = Path::from(poster_path.value().to_string());
|
||||
let result = self.store.get(&path).await.map_err(|e| match e {
|
||||
object_store::Error::NotFound { .. } => DomainError::NotFound("Poster not found".into()),
|
||||
object_store::Error::NotFound { .. } => {
|
||||
DomainError::NotFound("Poster not found".into())
|
||||
}
|
||||
_ => DomainError::InfrastructureError(e.to_string()),
|
||||
})?;
|
||||
result
|
||||
|
||||
Reference in New Issue
Block a user