mirror of
https://codeberg.org/slatian/service.echoip-slatecave.git
synced 2025-07-21 00:06:03 +02:00
Added query settings to the generaliued templating mechanism
This commit is contained in:
27
src/view.rs
27
src/view.rs
@ -1,9 +1,14 @@
|
||||
|
||||
use axum::http::status::StatusCode;
|
||||
use axum::Json;
|
||||
use axum::response::IntoResponse;
|
||||
use axum::response::Response;
|
||||
|
||||
use crate::DigResult;
|
||||
use crate::IpResult;
|
||||
use crate::config::DnsResolverConfig;
|
||||
use crate::settings::QuerySettings;
|
||||
use crate::settings::ResponseFormat;
|
||||
|
||||
use crate::mycelium::MycView;
|
||||
|
||||
@ -21,7 +26,7 @@ pub enum View {
|
||||
NotFound,
|
||||
}
|
||||
|
||||
impl MycView for View {
|
||||
impl MycView<QuerySettings, ResponseFormat> for View {
|
||||
fn get_template_name(&self) -> String {
|
||||
match self {
|
||||
View::Asn{..} => "asn",
|
||||
@ -35,11 +40,29 @@ impl MycView for View {
|
||||
}.to_string()
|
||||
}
|
||||
|
||||
fn get_status_code(&self) -> StatusCode {
|
||||
fn get_status_code(&self, _: &QuerySettings) -> StatusCode {
|
||||
match self {
|
||||
Self::NotFound => StatusCode::NOT_FOUND,
|
||||
_ => StatusCode::OK,
|
||||
}
|
||||
}
|
||||
|
||||
fn get_api_response(self, settings: &QuerySettings) -> Response {
|
||||
match self {
|
||||
Self::Dig{result, ..} => {
|
||||
Json(result).into_response()
|
||||
},
|
||||
Self::Index{result, ..} | Self::Ip{result, ..} => {
|
||||
Json(result).into_response()
|
||||
},
|
||||
Self::DnsResolverList => {
|
||||
Json(settings.available_dns_resolvers.clone()).into_response()
|
||||
},
|
||||
Self::DnsResolver{ config } => {
|
||||
Json(config).into_response()
|
||||
}
|
||||
_ => Json(self).into_response(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user