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