Files
movies-diary/crates/presentation/src/handlers/images.rs
Gabriel Kaszewski f262417971
Some checks failed
CI / Check / Test (push) Failing after 46s
refactor: rename ImageStorage → ObjectStorage
2026-06-03 01:33:08 +02:00

26 lines
763 B
Rust

use axum::{
extract::{Path, State},
http::{StatusCode, header},
response::IntoResponse,
};
use crate::state::AppState;
pub async fn get_image(
State(state): State<AppState>,
Path(key): Path<String>,
) -> impl IntoResponse {
if key.starts_with("http://") || key.starts_with("https://") {
return axum::response::Redirect::temporary(&key).into_response();
}
match state.app_ctx.services.object_storage.get(&key).await {
Ok(bytes) => {
let mime = infer::get(&bytes)
.map(|t| t.mime_type())
.unwrap_or("application/octet-stream");
([(header::CONTENT_TYPE, mime)], bytes).into_response()
}
Err(_) => StatusCode::NOT_FOUND.into_response(),
}
}