autoconnect_web/
routes.rsuse actix_web::{web, HttpRequest, HttpResponse};
use uuid::Uuid;
use autoconnect_settings::AppState;
use autopush_common::notification::Notification;
use crate::error::ApiError;
pub async fn ws_route(
req: HttpRequest,
body: web::Payload,
app_state: web::Data<AppState>,
) -> Result<HttpResponse, ApiError> {
Ok(autoconnect_ws::ws_handler(req, body, app_state).await?)
}
#[allow(unused_mut)]
pub async fn push_route(
uaid: web::Path<Uuid>,
mut notif: web::Json<Notification>,
app_state: web::Data<AppState>,
) -> HttpResponse {
trace!(
"⏩ in push_route, uaid: {} channel_id: {}",
uaid,
notif.channel_id,
);
#[cfg(feature = "reliable_report")]
{
notif
.record_reliability(
&app_state.reliability,
autopush_common::reliability::ReliabilityState::IntAccepted,
)
.await;
notif
.record_reliability(
&app_state.reliability,
autopush_common::reliability::ReliabilityState::Transmitted,
)
.await;
}
let result = app_state
.clients
.notify(uaid.into_inner(), notif.clone())
.await;
if result.is_ok() {
#[cfg(feature = "reliable_report")]
notif
.record_reliability(
&app_state.reliability,
autopush_common::reliability::ReliabilityState::Accepted,
)
.await;
HttpResponse::Ok().finish()
} else {
HttpResponse::NotFound().body("Client not available")
}
}
pub async fn check_storage_route(
uaid: web::Path<Uuid>,
app_state: web::Data<AppState>,
) -> HttpResponse {
trace!("⏩ check_storage_route, uaid: {}", uaid);
let result = app_state.clients.check_storage(uaid.into_inner()).await;
if result.is_ok() {
HttpResponse::Ok().finish()
} else {
HttpResponse::NotFound().body("Client not available")
}
}