fix(api): default value for hid_pad_format, content-type for /systems/:id/settings endpoint

This commit is contained in:
alyssa 2025-07-05 17:28:57 +00:00
parent 0f840914d7
commit 91d5ae6dd7

View file

@ -2,7 +2,7 @@ use axum::{
extract::State, extract::State,
http::StatusCode, http::StatusCode,
response::{IntoResponse, Response}, response::{IntoResponse, Response},
Extension, Extension, Json,
}; };
use serde_json::json; use serde_json::json;
use sqlx::Postgres; use sqlx::Postgres;
@ -19,7 +19,7 @@ pub async fn get_system_settings(
) -> Response { ) -> Response {
let access_level = auth.access_level_for(&system); let access_level = auth.access_level_for(&system);
let config = match sqlx::query_as::<Postgres, PKSystemConfig>( let mut config = match sqlx::query_as::<Postgres, PKSystemConfig>(
"select * from system_config where system = $1", "select * from system_config where system = $1",
) )
.bind(system.id) .bind(system.id)
@ -46,23 +46,24 @@ pub async fn get_system_settings(
} }
}; };
( // fix this
StatusCode::OK, if config.name_format.is_none() {
serde_json::to_string(&match access_level { config.name_format = Some("{name} {tag}".to_string());
PrivacyLevel::Private => config.to_json(), }
PrivacyLevel::Public => json!({
"pings_enabled": config.pings_enabled, Json(&match access_level {
"latch_timeout": config.latch_timeout, PrivacyLevel::Private => config.to_json(),
"case_sensitive_proxy_tags": config.case_sensitive_proxy_tags, PrivacyLevel::Public => json!({
"proxy_error_message_enabled": config.proxy_error_message_enabled, "pings_enabled": config.pings_enabled,
"hid_display_split": config.hid_display_split, "latch_timeout": config.latch_timeout,
"hid_display_caps": config.hid_display_caps, "case_sensitive_proxy_tags": config.case_sensitive_proxy_tags,
"hid_list_padding": config.hid_list_padding, "proxy_error_message_enabled": config.proxy_error_message_enabled,
"proxy_switch": config.proxy_switch, "hid_display_split": config.hid_display_split,
"name_format": config.name_format, "hid_display_caps": config.hid_display_caps,
}), "hid_list_padding": config.hid_list_padding,
}) "proxy_switch": config.proxy_switch,
.unwrap(), "name_format": config.name_format,
) }),
.into_response() })
.into_response()
} }