use axum::{ extract::{Path, State}, response::{self, IntoResponse, Redirect}, }; use axum_extra::TypedHeader; use headers::IfNoneMatch; use crate::{ conversation::{self, app, app::Conversations}, error::Internal, token::extract::Identity, ui::{ assets::{self, Asset, Assets}, error::NotFound, }, }; pub async fn handler( State(conversations): State, identity: Option, Path(conversation): Path, TypedHeader(if_none_match): TypedHeader, ) -> Result { let response = if identity.is_none() { Response::NotLoggedIn } else { match conversations.get(&conversation).await { Ok(_) => { let index = assets::Response::index(&if_none_match)?; Response::Asset(index) } Err(app::GetError::NotFound(_) | app::GetError::Deleted(_)) => { let index = Assets::index()?; Response::NotFound(index) } Err(err @ app::GetError::Failed(_)) => return Err(err.into()), } }; Ok(response) } pub enum Response { NotLoggedIn, NotFound(Asset), Asset(assets::Response), } impl IntoResponse for Response { fn into_response(self) -> response::Response { match self { Self::NotLoggedIn => Redirect::temporary("/login").into_response(), Self::NotFound(asset) => NotFound(asset).into_response(), Self::Asset(asset) => asset.into_response(), } } }