Mountain/IPC/WindServiceHandlers/Storage/
StorageGetItems.rs1
2use std::sync::Arc;
9
10use CommonLibrary::{Environment::Requires::Requires, Storage::StorageProvider::StorageProvider};
11use serde_json::{Value, json};
12
13use crate::RunTime::ApplicationRunTime::ApplicationRunTime;
14
15pub async fn Fn(RunTime:Arc<ApplicationRunTime>, _Arguments:Vec<Value>) -> Result<Value, String> {
16 let provider:Arc<dyn StorageProvider> = RunTime.Environment.Require();
17
18 match provider.GetAllStorage(true).await {
19 Ok(State) => {
20 if let Some(Obj) = State.as_object() {
21 let Tuples:Vec<Value> = Obj
22 .iter()
23 .map(|(K, V)| {
24 let ValStr = match V {
25 Value::String(S) => S.clone(),
26 _ => V.to_string(),
27 };
28 json!([K, ValStr])
29 })
30 .collect();
31
32 Ok(json!(Tuples))
33 } else {
34 Ok(json!([]))
35 }
36 },
37
38 Err(_) => Ok(json!([])),
39 }
40}