Mountain/RPC/CocoonService/GenericRequest/FileSystem/
WriteFile.rs1use serde_json::Value;
2use tonic::Response;
3use ::Vine::Generated::GenericResponse;
4
5pub async fn Fn(RequestId:u64, Params:Value) -> Response<GenericResponse> {
6 let Path = Params.get("path").and_then(|V| V.as_str()).unwrap_or("");
7
8 let Content:Vec<u8> = Params
9 .get("content")
10 .and_then(|V| V.as_array())
11 .map(|A| A.iter().filter_map(|B| B.as_u64().map(|N| N as u8)).collect())
12 .unwrap_or_default();
13
14 match tokio::fs::write(Path, &Content).await {
15 Ok(()) => super::OkResponse(RequestId, &Value::Null),
16
17 Err(Error) => super::ErrResponse(RequestId, -32000, format!("fs.writeFile: {}", Error)),
18 }
19}