Skip to main content

Mountain/RPC/CocoonService/GenericRequest/FileSystem/
WriteFile.rs

1#![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 Path = Params.get("path").and_then(|V| V.as_str()).unwrap_or("");
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(Path, &Content).await {
18		Ok(()) => super::OkResponse(RequestId, &Value::Null),
19
20		Err(Error) => super::ErrResponse(RequestId, -32000, format!("fs.writeFile: {}", Error)),
21	}
22}