Mountain/RPC/CocoonService/GenericRequest/FileSystem/
WriteFileUri.rs1use serde_json::Value;
2use tonic::Response;
3use ::Vine::Generated::GenericResponse;
4
5pub async fn Fn(RequestId:u64, Params:Value) -> Response<GenericResponse> {
6 let Uri = Params.get("uri").and_then(|V| V.as_str()).unwrap_or("").replace("file://", "");
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(&Uri, &Content).await {
15 Ok(()) => super::OkResponse(RequestId, &Value::Null),
16
17 Err(Error) => super::ErrResponse(RequestId, -32000, format!("writeFile: {}", Error)),
18 }
19}