10
0
Fork 0
mirror of https://github.com/ZeusWPI/ZNS.git synced 2024-10-30 05:24:26 +01:00
This commit is contained in:
Xander Bil 2024-03-13 16:16:26 +01:00
parent 335670c3c2
commit 5cd801a6d0
No known key found for this signature in database
GPG key ID: EC9706B54A278598
4 changed files with 10 additions and 7 deletions

View file

@ -36,7 +36,7 @@ async fn create_record(req: Request<hyper::body::Incoming>) -> Result<Response<B
Ok(record) => {
let rdata = record
._type
.to_bytes(&record.data)
.to_data(&record.data)
.map_err(|e| e.to_string())?;
match insert_into_database(RR {
name: record.name,
@ -67,9 +67,13 @@ async fn create_record(req: Request<hyper::body::Incoming>) -> Result<Response<B
async fn get_record(req: Request<hyper::body::Incoming>) -> Result<Response<BoxBody>> {
if let Some(q) = req.uri().query() {
let params = form_urlencoded::parse(q.as_bytes()).into_owned().collect::<HashMap<String,String>>();
let params = form_urlencoded::parse(q.as_bytes())
.into_owned()
.collect::<HashMap<String, String>>();
if let Some(domain) = params.get("domain_name") {
return Ok(Response::builder().status(StatusCode::OK).body(full(domain.to_owned()))?)
return Ok(Response::builder()
.status(StatusCode::OK)
.body(full(domain.to_owned()))?);
}
}

View file

@ -3,7 +3,6 @@ use diesel::sqlite::SqliteConnection;
use dotenvy::dotenv;
use std::env;
pub fn establish_connection() -> SqliteConnection {
dotenv().ok();

View file

@ -1,2 +1,2 @@
pub mod models;
pub mod lib;
pub mod models;

View file

@ -39,7 +39,7 @@ pub trait FromBytes {
}
impl Type {
pub fn to_bytes(&self, text: &String) -> Result<Vec<u8>> {
pub fn to_data(&self, text: &String) -> Result<Vec<u8>> {
match self {
Type::A => {
let arr: Vec<u8> = text
@ -57,7 +57,7 @@ impl Type {
}
}
}
pub fn from_bytes(&self, bytes: &[u8]) -> Result<String> {
pub fn from_data(&self, bytes: &[u8]) -> Result<String> {
match self {
Type::A => {
if bytes.len() == 4 {