Fix rustfmt formatting in server and kiosk

This commit is contained in:
2026-08-09 19:54:00 -04:00
parent 77bc93e70f
commit f6487f00e3
11 changed files with 57 additions and 40 deletions
+8 -2
View File
@@ -81,7 +81,10 @@ pub struct KioskIdentity {
impl FromRequestParts<AppState> for AdminIdentity {
type Rejection = AppError;
async fn from_request_parts(parts: &mut Parts, state: &AppState) -> Result<Self, Self::Rejection> {
async fn from_request_parts(
parts: &mut Parts,
state: &AppState,
) -> Result<Self, Self::Rejection> {
let token = bearer_token(parts)?;
let data = decode::<AdminClaims>(
&token,
@@ -100,7 +103,10 @@ impl FromRequestParts<AppState> for AdminIdentity {
impl FromRequestParts<AppState> for KioskIdentity {
type Rejection = AppError;
async fn from_request_parts(parts: &mut Parts, state: &AppState) -> Result<Self, Self::Rejection> {
async fn from_request_parts(
parts: &mut Parts,
state: &AppState,
) -> Result<Self, Self::Rejection> {
let token = bearer_token(parts)?;
let token_hash = hash_opaque_token(&token);
+8 -5
View File
@@ -118,7 +118,9 @@ fn apply_defaults(kiosk_id: &str, mut layout: Value) -> Value {
.entry("foregroundColor")
.or_insert_with(|| json!("#f4f6f8"));
object.entry("widgetOpacity").or_insert_with(|| json!(0.5));
object.entry("background").or_insert_with(default_background);
object
.entry("background")
.or_insert_with(default_background);
object.entry("nightMode").or_insert_with(default_night_mode);
object.entry("widgets").or_insert_with(|| json!([]));
object
@@ -160,10 +162,11 @@ fn fill_nested_defaults(target: Option<&mut Value>, defaults: Value) {
}
pub async fn load_layout(db: &SqlitePool, kiosk_id: &str) -> AppResult<Value> {
let row: Option<(String,)> = sqlx::query_as("SELECT data FROM kiosk_layouts WHERE kiosk_id = ?")
.bind(kiosk_id)
.fetch_optional(db)
.await?;
let row: Option<(String,)> =
sqlx::query_as("SELECT data FROM kiosk_layouts WHERE kiosk_id = ?")
.bind(kiosk_id)
.fetch_optional(db)
.await?;
let stored = match row {
Some((data,)) => serde_json::from_str(&data).unwrap_or_else(|_| default_layout(kiosk_id)),
+4 -1
View File
@@ -75,7 +75,10 @@ async fn main() {
.nest("/api/kiosk", routes::kiosk_router().layer(kiosk_cors))
.nest("/api", routes::api_router().layer(cors))
.nest_service("/media", ServeDir::new(state.config.media_dir.clone()))
.nest_service("/downloads", ServeDir::new(state.config.package_dir.clone()))
.nest_service(
"/downloads",
ServeDir::new(state.config.package_dir.clone()),
)
.layer(TraceLayer::new_for_http())
.with_state(state);
+1 -3
View File
@@ -39,9 +39,7 @@ impl From<KioskRow> for KioskView {
status: row.status,
last_seen_at: row.last_seen_at,
created_at: row.created_at,
metrics: row
.metrics
.and_then(|raw| serde_json::from_str(&raw).ok()),
metrics: row.metrics.and_then(|raw| serde_json::from_str(&raw).ok()),
metrics_at: row.metrics_at,
}
}
+9 -7
View File
@@ -24,13 +24,15 @@ pub async fn issue_pin(
let expires_at = issued_at + seconds_to_ms(rotation_seconds + grace_seconds);
let pin = allocate_unique_pin(db, issued_at).await?;
sqlx::query("INSERT INTO kiosk_pins (pin, kiosk_id, issued_at, expires_at) VALUES (?, ?, ?, ?)")
.bind(&pin)
.bind(kiosk_id)
.bind(issued_at)
.bind(expires_at)
.execute(db)
.await?;
sqlx::query(
"INSERT INTO kiosk_pins (pin, kiosk_id, issued_at, expires_at) VALUES (?, ?, ?, ?)",
)
.bind(&pin)
.bind(kiosk_id)
.bind(issued_at)
.bind(expires_at)
.execute(db)
.await?;
Ok(IssuedPin {
pin,
+5 -4
View File
@@ -85,10 +85,11 @@ async fn list_kiosks(
State(state): State<AppState>,
_admin: AdminIdentity,
) -> AppResult<Json<KioskListResponse>> {
let rows: Vec<KioskRow> =
sqlx::query_as(&format!("SELECT {KIOSK_COLUMNS} FROM kiosks ORDER BY created_at"))
.fetch_all(&state.db)
.await?;
let rows: Vec<KioskRow> = sqlx::query_as(&format!(
"SELECT {KIOSK_COLUMNS} FROM kiosks ORDER BY created_at"
))
.fetch_all(&state.db)
.await?;
let now = now_ms();
let kiosks = rows
+5 -1
View File
@@ -30,7 +30,11 @@ fn resolve_server_url(state: &AppState, headers: &HeaderMap) -> String {
}
if !state.config.public_api_url.is_empty() {
return state.config.public_api_url.trim_end_matches('/').to_string();
return state
.config
.public_api_url
.trim_end_matches('/')
.to_string();
}
"http://localhost:8080".to_string()
-1
View File
@@ -5,7 +5,6 @@ use axum::{Json, Router};
use serde::{Deserialize, Serialize};
use serde_json::Value;
use crate::auth::{generate_opaque_token, hash_opaque_token, KioskIdentity};
use crate::clock::now_ms;
use crate::error::{AppError, AppResult};
+12 -5
View File
@@ -34,22 +34,29 @@ pub async fn store_image(
}
if body.len() > MAX_UPLOAD_BYTES {
return Err(AppError::BadRequest("images must be 8 MB or smaller".into()));
return Err(AppError::BadRequest(
"images must be 8 MB or smaller".into(),
));
}
let content_type = headers
.get(axum::http::header::CONTENT_TYPE)
.and_then(|value| value.to_str().ok())
.map(|value| value.split(';').next().unwrap_or(value).trim().to_lowercase())
.map(|value| {
value
.split(';')
.next()
.unwrap_or(value)
.trim()
.to_lowercase()
})
.unwrap_or_default();
let extension = ALLOWED_TYPES
.iter()
.find(|(mime, _)| *mime == content_type)
.map(|(_, extension)| *extension)
.ok_or_else(|| {
AppError::BadRequest("images must be a PNG, JPEG, WEBP or GIF".into())
})?;
.ok_or_else(|| AppError::BadRequest("images must be a PNG, JPEG, WEBP or GIF".into()))?;
let directory = std::path::Path::new(&state.config.media_dir);
tokio::fs::create_dir_all(directory)