server: more robust view original serving

This commit is contained in:
Bill Thiede 2025-04-20 10:01:22 -07:00
parent 5cec8add5e
commit c703be2ca5

View File

@ -149,17 +149,13 @@ async fn view_original(
) -> Result<impl IntoResponse, AppError> { ) -> Result<impl IntoResponse, AppError> {
info!("view_original {id}"); info!("view_original {id}");
let mid = if id.starts_with("id:") { let mid = if id.starts_with("id:") {
id.to_string() id
} else { } else {
format!("id:{}", id) format!("id:{id}")
}; };
let files = nm.files(&mid)?; let bytes = nm.show_original(&mid)?;
let Some(path) = files.first() else { let s = String::from_utf8_lossy(&bytes).to_string();
warn!("failed to find files for message {mid}"); Ok(s.into_response())
return Ok((StatusCode::NOT_FOUND, mid).into_response());
};
let str = std::fs::read_to_string(&path)?;
Ok(str.into_response())
} }
async fn graphiql() -> impl IntoResponse { async fn graphiql() -> impl IntoResponse {