most of a dash views api impl

This commit is contained in:
alyssa 2025-12-21 17:24:04 -05:00
parent 1a9ccdb88d
commit 90100a83dc
5 changed files with 176 additions and 5 deletions

View file

@ -3,7 +3,7 @@ use pk_macros::api_endpoint;
use serde_json::{Value, json};
use sqlx::Postgres;
use pluralkit_models::{PKSystem, PKSystemConfig, PrivacyLevel};
use pluralkit_models::{PKDashView, PKSystem, PKSystemConfig, PrivacyLevel};
use crate::{ApiContext, auth::AuthState, error::fail};
@ -36,7 +36,32 @@ pub async fn get_system_settings(
}
Ok(Json(match access_level {
PrivacyLevel::Private => config.to_json(),
PrivacyLevel::Private => {
let mut config_json = config.clone().to_json();
match sqlx::query_as::<Postgres, PKDashView>(
"select * from dash_views where system = $1",
)
.bind(system.id)
.fetch_all(&ctx.db)
.await
{
Ok(val) => {
config_json.as_object_mut().unwrap().insert(
"dash_views".to_string(),
serde_json::to_value(
&val.iter()
.map(|v| v.clone().to_json())
.collect::<Vec<serde_json::Value>>(),
)
.unwrap(),
);
}
Err(err) => fail!(?err, "failed to query dash views"),
};
config_json
}
PrivacyLevel::Public => json!({
"pings_enabled": config.pings_enabled,
"latch_timeout": config.latch_timeout,