1use axum::http::header::ACCEPT;
2
3use crate::server::State;
4
5fn check_accept_header(headers: &axum::http::header::HeaderMap) -> anyhow::Result<()> {
6 let Some(value) = headers.get(&ACCEPT) else {
8 anyhow::bail!("header `{ACCEPT}` required");
9 };
10
11 if value.to_str()? != "application/json" {
12 anyhow::bail!("this endpoint only returns `application/json`");
13 }
14
15 Ok(())
16}
17
18pub async fn events(
19 headers: &axum::http::header::HeaderMap,
20 state: &State,
21) -> anyhow::Result<Vec<crate::root::RootEvent>> {
22 check_accept_header(headers)?;
23 crate::root::root_data(state).await
24}
25
26pub async fn try_event_data(
27 headers: &axum::http::header::HeaderMap,
28 event_index: usize,
29 state: &State,
30) -> anyhow::Result<serde_json::Value> {
31 check_accept_header(headers)?;
32 crate::view::try_view_data(event_index, state).await
33}