summaryrefslogtreecommitdiff
path: root/src/routes
diff options
context:
space:
mode:
authorfx <[email protected]>2023-10-14 22:01:33 +0200
committerfx <[email protected]>2023-10-14 22:01:33 +0200
commit6648d1da1df9a4e4e2945739fc0fd3c7f77643cb (patch)
treee487bbf77c5280a58ee5bcd69f6b74018be96430 /src/routes
parent25885b8e08252db20f2a50e64184b6a59e546a73 (diff)
downloadwebol-6648d1da1df9a4e4e2945739fc0fd3c7f77643cb.tar
webol-6648d1da1df9a4e4e2945739fc0fd3c7f77643cb.tar.gz
webol-6648d1da1df9a4e4e2945739fc0fd3c7f77643cb.zip
test this fing shit on pi wohoo
Diffstat (limited to 'src/routes')
-rw-r--r--src/routes/device.rs4
-rw-r--r--src/routes/start.rs2
2 files changed, 5 insertions, 1 deletions
diff --git a/src/routes/device.rs b/src/routes/device.rs
index d5d7144..025c7d0 100644
--- a/src/routes/device.rs
+++ b/src/routes/device.rs
@@ -4,11 +4,13 @@ use axum::headers::HeaderMap;
4use axum::Json; 4use axum::Json;
5use serde::{Deserialize, Serialize}; 5use serde::{Deserialize, Serialize};
6use serde_json::{json, Value}; 6use serde_json::{json, Value};
7use tracing::info;
7use crate::auth::auth; 8use crate::auth::auth;
8use crate::db::Device; 9use crate::db::Device;
9use crate::error::WebolError; 10use crate::error::WebolError;
10 11
11pub async fn get_device(State(state): State<Arc<crate::AppState>>, headers: HeaderMap, Json(payload): Json<GetDevicePayload>) -> Result<Json<Value>, WebolError> { 12pub async fn get_device(State(state): State<Arc<crate::AppState>>, headers: HeaderMap, Json(payload): Json<GetDevicePayload>) -> Result<Json<Value>, WebolError> {
13 info!("GET request");
12 let secret = headers.get("authorization"); 14 let secret = headers.get("authorization");
13 if auth(secret).map_err(WebolError::Auth)? { 15 if auth(secret).map_err(WebolError::Auth)? {
14 let device = sqlx::query_as!( 16 let device = sqlx::query_as!(
@@ -33,6 +35,7 @@ pub struct GetDevicePayload {
33} 35}
34 36
35pub async fn put_device(State(state): State<Arc<crate::AppState>>, headers: HeaderMap, Json(payload): Json<PutDevicePayload>) -> Result<Json<Value>, WebolError> { 37pub async fn put_device(State(state): State<Arc<crate::AppState>>, headers: HeaderMap, Json(payload): Json<PutDevicePayload>) -> Result<Json<Value>, WebolError> {
38 info!("PUT request");
36 let secret = headers.get("authorization"); 39 let secret = headers.get("authorization");
37 if auth(secret).map_err(WebolError::Auth)? { 40 if auth(secret).map_err(WebolError::Auth)? {
38 sqlx::query!( 41 sqlx::query!(
@@ -64,6 +67,7 @@ pub struct PutDeviceResponse {
64} 67}
65 68
66pub async fn post_device(State(state): State<Arc<crate::AppState>>, headers: HeaderMap, Json(payload): Json<PostDevicePayload>) -> Result<Json<Value>, WebolError> { 69pub async fn post_device(State(state): State<Arc<crate::AppState>>, headers: HeaderMap, Json(payload): Json<PostDevicePayload>) -> Result<Json<Value>, WebolError> {
70 info!("POST request");
67 let secret = headers.get("authorization"); 71 let secret = headers.get("authorization");
68 if auth(secret).map_err(WebolError::Auth)? { 72 if auth(secret).map_err(WebolError::Auth)? {
69 let device = sqlx::query_as!( 73 let device = sqlx::query_as!(
diff --git a/src/routes/start.rs b/src/routes/start.rs
index d16ea4e..2e6a648 100644
--- a/src/routes/start.rs
+++ b/src/routes/start.rs
@@ -28,7 +28,7 @@ pub async fn start(State(state): State<Arc<crate::AppState>>, headers: HeaderMap
28 28
29 let bind_addr = SETTINGS 29 let bind_addr = SETTINGS
30 .get_string("bindaddr") 30 .get_string("bindaddr")
31 .map_err(|err| WebolError::Server(Box::new(err)))?; 31 .unwrap_or("0.0.0.0:1111".to_string());
32 32
33 let _ = send_packet( 33 let _ = send_packet(
34 &bind_addr.parse().map_err(|err| WebolError::Server(Box::new(err)))?, 34 &bind_addr.parse().map_err(|err| WebolError::Server(Box::new(err)))?,