mirror of
https://github.com/EFForg/rayhunter.git
synced 2026-07-22 23:38:10 -07:00
GPS feature webapp side: GPS mode selector, fixed mode lat/lon, API endpoint. Merging with Wifi client and webdav features
This commit is contained in:
committed by
Will Greenberg
parent
ac33ebaf53
commit
c107314194
@@ -0,0 +1,39 @@
|
||||
use axum::Json;
|
||||
use axum::extract::State;
|
||||
use axum::http::StatusCode;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::sync::Arc;
|
||||
|
||||
use crate::server::ServerState;
|
||||
|
||||
#[derive(Clone, Debug, Serialize, Deserialize)]
|
||||
pub struct GpsData {
|
||||
pub latitude: f64,
|
||||
pub longitude: f64,
|
||||
pub timestamp: String,
|
||||
}
|
||||
|
||||
pub async fn post_gps(
|
||||
State(state): State<Arc<ServerState>>,
|
||||
Json(gps_data): Json<GpsData>,
|
||||
) -> Result<StatusCode, (StatusCode, String)> {
|
||||
if state.config.gps_mode != 2 {
|
||||
return Err((
|
||||
StatusCode::FORBIDDEN,
|
||||
"GPS API endpoint is disabled. Set gps_mode to 2 in configuration.".to_string(),
|
||||
));
|
||||
}
|
||||
let mut gps = state.gps_state.write().await;
|
||||
*gps = Some(gps_data);
|
||||
Ok(StatusCode::OK)
|
||||
}
|
||||
|
||||
pub async fn get_gps(
|
||||
State(state): State<Arc<ServerState>>,
|
||||
) -> Result<Json<GpsData>, StatusCode> {
|
||||
let gps = state.gps_state.read().await;
|
||||
match gps.as_ref() {
|
||||
Some(data) => Ok(Json(data.clone())),
|
||||
None => Err(StatusCode::NOT_FOUND),
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user