mirror of
https://github.com/Start9Labs/start-os.git
synced 2026-03-26 10:21:52 +00:00
Update some of the types
This commit is contained in:
@@ -530,12 +530,12 @@ pub struct ExposedDependent {
|
||||
#[derive(Clone, Debug, Deserialize, Serialize, HasModel)]
|
||||
#[model = "Model<Self>"]
|
||||
pub struct ExposedUI {
|
||||
path: Vec<JsonPointer>,
|
||||
title: String,
|
||||
description: Option<String>,
|
||||
masked: Option<bool>,
|
||||
copyable: Option<bool>,
|
||||
qr: Option<bool>,
|
||||
pub path: JsonPointer,
|
||||
pub title: String,
|
||||
pub description: Option<String>,
|
||||
pub masked: Option<bool>,
|
||||
pub copyable: Option<bool>,
|
||||
pub qr: Option<bool>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Default, Deserialize, Serialize)]
|
||||
|
||||
@@ -1,16 +1,41 @@
|
||||
use clap::Parser;
|
||||
use imbl_value::{json, Value};
|
||||
use models::PackageId;
|
||||
use rpc_toolkit::command;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use serde_json::Value;
|
||||
|
||||
use crate::context::RpcContext;
|
||||
use crate::prelude::*;
|
||||
use crate::Error;
|
||||
use crate::{context::RpcContext, db::model::ExposedUI};
|
||||
|
||||
pub fn display_properties(response: Value) {
|
||||
println!("{}", response);
|
||||
}
|
||||
|
||||
trait IntoProperties {
|
||||
fn into_properties(self, store: &Value) -> Value;
|
||||
}
|
||||
impl IntoProperties for Vec<ExposedUI> {
|
||||
fn into_properties(self, store: &Value) -> Value {
|
||||
let mut data = json!({});
|
||||
for ui in self {
|
||||
let value = ui.path.get(store);
|
||||
data[ui.title] = json!({
|
||||
"type": "string",
|
||||
"description": ui.description,
|
||||
"value": value.map(|x| x.to_string()).unwrap_or_default(),
|
||||
"copyable": ui.copyable,
|
||||
"qr": ui.qr,
|
||||
"masked": ui.masked,
|
||||
});
|
||||
}
|
||||
json!({
|
||||
"version": 2,
|
||||
"data": data
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Deserialize, Serialize, Parser)]
|
||||
#[serde(rename_all = "kebab-case")]
|
||||
#[command(rename_all = "kebab-case")]
|
||||
@@ -22,5 +47,24 @@ pub async fn properties(
|
||||
ctx: RpcContext,
|
||||
PropertiesParam { id }: PropertiesParam,
|
||||
) -> Result<Value, Error> {
|
||||
Ok(todo!())
|
||||
let peeked = ctx.db.peek().await;
|
||||
let data = peeked
|
||||
.as_public()
|
||||
.as_package_data()
|
||||
.as_idx(&id)
|
||||
.or_not_found(&id)?
|
||||
.as_installed()
|
||||
.or_not_found(&id)?
|
||||
.as_store()
|
||||
.de()?;
|
||||
Ok(peeked
|
||||
.as_public()
|
||||
.as_package_data()
|
||||
.as_idx(&id)
|
||||
.or_not_found(&id)?
|
||||
.as_installed()
|
||||
.or_not_found(&id)?
|
||||
.as_store_exposed_ui()
|
||||
.de()?
|
||||
.into_properties(&data))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user