feat: initial commit — antigravity proxy with MITM, standalone LS, and snapshot tooling
This commit is contained in:
36
src/api/util.rs
Normal file
36
src/api/util.rs
Normal file
@@ -0,0 +1,36 @@
|
||||
//! Shared utilities for API handlers.
|
||||
|
||||
use axum::{
|
||||
http::StatusCode,
|
||||
response::{sse::Event, IntoResponse, Json},
|
||||
};
|
||||
use std::time::{SystemTime, UNIX_EPOCH};
|
||||
|
||||
use super::types::{ErrorDetail, ErrorResponse};
|
||||
|
||||
pub(crate) fn err_response(
|
||||
status: StatusCode,
|
||||
message: String,
|
||||
error_type: &str,
|
||||
) -> axum::response::Response {
|
||||
let body = ErrorResponse {
|
||||
error: ErrorDetail {
|
||||
message,
|
||||
error_type: error_type.to_string(),
|
||||
},
|
||||
};
|
||||
(status, Json(body)).into_response()
|
||||
}
|
||||
|
||||
pub(crate) fn now_unix() -> u64 {
|
||||
SystemTime::now()
|
||||
.duration_since(UNIX_EPOCH)
|
||||
.unwrap_or_default()
|
||||
.as_secs()
|
||||
}
|
||||
|
||||
pub(crate) fn responses_sse_event(event_type: &str, data: serde_json::Value) -> Event {
|
||||
Event::default()
|
||||
.event(event_type)
|
||||
.data(serde_json::to_string(&data).unwrap())
|
||||
}
|
||||
Reference in New Issue
Block a user