Broke out settings and fixed a bug with the dns resolver not being persisted

This commit is contained in:
Slatian
2023-08-05 22:53:48 +02:00
parent d88b15ba02
commit 55897585ff
3 changed files with 70 additions and 80 deletions

49
src/settings.rs Normal file
View File

@ -0,0 +1,49 @@
use serde::{Deserialize,Serialize};
/* Response format */
#[derive(Deserialize, Serialize, Clone, Copy)]
pub enum ResponseFormat {
#[serde(rename="text/plain", alias="text")]
TextPlain,
#[serde(rename="text/html", alias="html")]
TextHtml,
#[serde(rename="application/json", alias="json")]
ApplicationJson,
}
impl ToString for ResponseFormat {
fn to_string(&self) -> String {
match self {
ResponseFormat::TextPlain => "text/plain",
ResponseFormat::TextHtml => "text/html",
ResponseFormat::ApplicationJson => "application/json",
}.to_string()
}
}
impl ResponseFormat {
pub fn to_file_extension(&self) -> String {
match self {
ResponseFormat::TextPlain => ".txt",
ResponseFormat::TextHtml => ".html",
ResponseFormat::ApplicationJson => ".json",
}.to_string()
}
}
/* Query and Template Settings */
#[derive(Deserialize, Serialize, Clone)]
pub struct QuerySettings {
pub format: ResponseFormat,
pub lang: String,
pub available_dns_resolvers: Vec<Selectable>,
pub dns_resolver_id: String,
}
#[derive(Deserialize, Serialize, Clone)]
pub struct Selectable {
pub id: String,
pub name: String,
}