Fix all compiler warnings across server and client
- Remove unused ServerConfig struct (config via CLI args) - Remove unused otpks field from Database (not yet needed) - Wire AppError into message routes with proper error propagation - Remove unused imports in send.rs (Seed, MessageContent, etc.) - Suppress dead_code on BundleResponse.fingerprint (needed by serde) Zero warnings, 17/17 tests pass. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -1,4 +1,2 @@
|
||||
pub struct ServerConfig {
|
||||
pub bind_addr: String,
|
||||
pub data_dir: String,
|
||||
}
|
||||
// Server configuration — currently handled via CLI args in main.rs.
|
||||
// This module will be used when file-based configuration is added.
|
||||
|
||||
@@ -3,7 +3,6 @@ use anyhow::Result;
|
||||
pub struct Database {
|
||||
pub keys: sled::Tree,
|
||||
pub messages: sled::Tree,
|
||||
pub otpks: sled::Tree,
|
||||
_db: sled::Db,
|
||||
}
|
||||
|
||||
@@ -12,11 +11,9 @@ impl Database {
|
||||
let db = sled::open(data_dir)?;
|
||||
let keys = db.open_tree("keys")?;
|
||||
let messages = db.open_tree("messages")?;
|
||||
let otpks = db.open_tree("otpks")?;
|
||||
Ok(Database {
|
||||
keys,
|
||||
messages,
|
||||
otpks,
|
||||
_db: db,
|
||||
})
|
||||
}
|
||||
|
||||
@@ -1,10 +1,12 @@
|
||||
use axum::http::StatusCode;
|
||||
use axum::response::{IntoResponse, Response};
|
||||
|
||||
/// Wraps anyhow::Error into an axum-compatible error response.
|
||||
pub struct AppError(pub anyhow::Error);
|
||||
|
||||
impl IntoResponse for AppError {
|
||||
fn into_response(self) -> Response {
|
||||
tracing::error!("{:#}", self.0);
|
||||
(StatusCode::INTERNAL_SERVER_ERROR, self.0.to_string()).into_response()
|
||||
}
|
||||
}
|
||||
@@ -14,3 +16,6 @@ impl<E: Into<anyhow::Error>> From<E> for AppError {
|
||||
AppError(err.into())
|
||||
}
|
||||
}
|
||||
|
||||
/// Convenience type for route handlers.
|
||||
pub type AppResult<T> = Result<T, AppError>;
|
||||
|
||||
@@ -5,6 +5,7 @@ use axum::{
|
||||
};
|
||||
use serde::Deserialize;
|
||||
|
||||
use crate::errors::AppResult;
|
||||
use crate::state::AppState;
|
||||
|
||||
pub fn routes() -> Router<AppState> {
|
||||
@@ -17,45 +18,41 @@ pub fn routes() -> Router<AppState> {
|
||||
#[derive(Deserialize)]
|
||||
struct SendRequest {
|
||||
to: String,
|
||||
message: Vec<u8>, // bincode-serialized WarzoneMessage
|
||||
message: Vec<u8>,
|
||||
}
|
||||
|
||||
async fn send_message(
|
||||
State(state): State<AppState>,
|
||||
Json(req): Json<SendRequest>,
|
||||
) -> Json<serde_json::Value> {
|
||||
// Append to recipient's queue
|
||||
) -> AppResult<Json<serde_json::Value>> {
|
||||
let key = format!("queue:{}", req.to);
|
||||
let _ = state.db.messages.insert(
|
||||
state.db.messages.insert(
|
||||
format!("{}:{}", key, uuid::Uuid::new_v4()).as_bytes(),
|
||||
req.message,
|
||||
);
|
||||
Json(serde_json::json!({ "ok": true }))
|
||||
)?;
|
||||
Ok(Json(serde_json::json!({ "ok": true })))
|
||||
}
|
||||
|
||||
async fn poll_messages(
|
||||
State(state): State<AppState>,
|
||||
Path(fingerprint): Path<String>,
|
||||
) -> Json<Vec<String>> {
|
||||
) -> AppResult<Json<Vec<String>>> {
|
||||
let prefix = format!("queue:{}", fingerprint);
|
||||
let mut messages = Vec::new();
|
||||
for item in state.db.messages.scan_prefix(prefix.as_bytes()) {
|
||||
if let Ok((_, value)) = item {
|
||||
messages.push(base64::Engine::encode(
|
||||
&base64::engine::general_purpose::STANDARD,
|
||||
&value,
|
||||
));
|
||||
}
|
||||
let (_, value) = item?;
|
||||
messages.push(base64::Engine::encode(
|
||||
&base64::engine::general_purpose::STANDARD,
|
||||
&value,
|
||||
));
|
||||
}
|
||||
Json(messages)
|
||||
Ok(Json(messages))
|
||||
}
|
||||
|
||||
async fn ack_message(
|
||||
State(state): State<AppState>,
|
||||
Path(id): Path<String>,
|
||||
) -> Json<serde_json::Value> {
|
||||
// Scan for and remove the message with this ID
|
||||
// In a real implementation, we'd have a proper index
|
||||
let _ = state.db.messages.remove(id.as_bytes());
|
||||
Json(serde_json::json!({ "ok": true }))
|
||||
) -> AppResult<Json<serde_json::Value>> {
|
||||
state.db.messages.remove(id.as_bytes())?;
|
||||
Ok(Json(serde_json::json!({ "ok": true })))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user