Mountain/IPC/WindServiceHandlers/Model/TextfileRead.rs
1
2//! Read a text file from disk verbatim. Distinct from
3//! `ModelOpen` - this returns the bytes without registering a
4//! `DocumentStateDTO`. Used by tooling paths that want raw
5//! content (e.g. import resolvers, settings inspectors).
6
7use std::sync::Arc;
8
9use serde_json::Value;
10
11use crate::RunTime::ApplicationRunTime::ApplicationRunTime;
12
13pub async fn Fn(_runtime:Arc<ApplicationRunTime>, Arguments:Vec<Value>) -> Result<Value, String> {
14 let Path = Arguments
15 .first()
16 .and_then(|V| V.as_str())
17 .ok_or_else(|| "textFile:read requires path as first argument".to_string())?;
18
19 tokio::fs::read_to_string(Path)
20 .await
21 .map(Value::String)
22 .map_err(|Error| format!("textFile:read failed: {}", Error))
23}