autoconnect_web/
routes.rs1use actix_web::{HttpRequest, HttpResponse, web};
2use uuid::Uuid;
3
4use autoconnect_settings::AppState;
5use autopush_common::notification::Notification;
6
7use crate::error::ApiError;
8
9pub async fn ws_route(
11 req: HttpRequest,
12 body: web::Payload,
13 app_state: web::Data<AppState>,
14) -> Result<HttpResponse, ApiError> {
15 Ok(autoconnect_ws::ws_handler(req, body, app_state).await?)
16}
17
18#[allow(unused_mut)]
20pub async fn push_route(
21 uaid: web::Path<Uuid>,
22 mut notif: web::Json<Notification>,
23 app_state: web::Data<AppState>,
24) -> HttpResponse {
25 trace!(
26 "⏩ in push_route, uaid: {} channel_id: {}",
27 uaid, notif.channel_id,
28 );
29 #[cfg(feature = "reliable_report")]
30 {
31 notif
32 .record_reliability(
33 &app_state.reliability,
34 autopush_common::reliability::ReliabilityState::IntAccepted,
35 )
36 .await;
37 notif
38 .record_reliability(
39 &app_state.reliability,
40 autopush_common::reliability::ReliabilityState::Transmitted,
41 )
42 .await;
43 }
44 #[cfg(feature = "reliable_report")]
48 let lnotif = notif.clone_without_reliability_state();
49 #[cfg(not(feature = "reliable_report"))]
50 let lnotif = notif.clone();
51 let result = app_state.clients.notify(uaid.into_inner(), lnotif);
52 if result.is_ok() {
53 #[cfg(feature = "reliable_report")]
54 notif
55 .record_reliability(
56 &app_state.reliability,
57 autopush_common::reliability::ReliabilityState::Accepted,
58 )
59 .await;
60 HttpResponse::Ok().finish()
61 } else {
62 #[cfg(feature = "reliable_report")]
63 notif
64 .record_reliability(
65 &app_state.reliability,
66 autopush_common::reliability::ReliabilityState::Errored,
67 )
68 .await;
69 HttpResponse::NotFound().body("Client not available")
70 }
71}
72
73pub async fn check_storage_route(
75 uaid: web::Path<Uuid>,
76 app_state: web::Data<AppState>,
77) -> HttpResponse {
78 trace!("⏩ check_storage_route, uaid: {}", uaid);
79 let result = app_state.clients.check_storage(uaid.into_inner());
80 if result.is_ok() {
81 HttpResponse::Ok().finish()
82 } else {
83 HttpResponse::NotFound().body("Client not available")
84 }
85}