Reorganize module structure
This commit is contained in:
parent
51047ad11c
commit
14dc84cc43
14 changed files with 19 additions and 23 deletions
|
|
@ -1,57 +0,0 @@
|
|||
use axum::{
|
||||
body::Body,
|
||||
http::{Response, StatusCode, header, HeaderValue},
|
||||
};
|
||||
|
||||
use crate::prelude::*;
|
||||
use crate::{
|
||||
formats::{Format, populate_graph, serialize_graph},
|
||||
};
|
||||
use crate::handlers;
|
||||
|
||||
/// # Panics
|
||||
/// Will panic if file read fails.
|
||||
#[expect(clippy::unused_async)]
|
||||
pub async fn file(file_path: &str, content_type: &str) -> Response<Body> {
|
||||
let content = match std::fs::read(file_path) {
|
||||
Ok(s) => s,
|
||||
Err(e) => {
|
||||
panic!("Failed to read {file_path} contents: {e}")
|
||||
},
|
||||
};
|
||||
|
||||
let mut response = Response::new(Body::from(content));
|
||||
*response.status_mut() = StatusCode::OK;
|
||||
let header = header::CONTENT_TYPE;
|
||||
|
||||
if let Ok(header_value) = HeaderValue::from_str(content_type) {
|
||||
if let Some(h) = response.headers_mut().insert(header, header_value) {
|
||||
log!(
|
||||
"Overwrote existing header {h:?} because a header for the same key existed"
|
||||
);
|
||||
}
|
||||
} else {
|
||||
log!("Failed to create content type header value from {content_type}");
|
||||
}
|
||||
|
||||
response
|
||||
}
|
||||
|
||||
#[expect(clippy::unused_async)]
|
||||
pub async fn serial(format: &Format) -> Response<Body> {
|
||||
let graph = populate_graph();
|
||||
let body = serialize_graph(format, &graph);
|
||||
|
||||
match *format {
|
||||
Format::Toml => handlers::raw::make_response(
|
||||
&body,
|
||||
200,
|
||||
&[(header::CONTENT_TYPE, "text/plain")],
|
||||
),
|
||||
Format::Json => handlers::raw::make_response(
|
||||
&body,
|
||||
200,
|
||||
&[(header::CONTENT_TYPE, "application/json")],
|
||||
),
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue