Skip to main content

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

1use 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
7		.get("uri")
8		.and_then(|V| V.as_str())
9		.or_else(|| Params.as_str())
10		.unwrap_or("")
11		.replace("file://", "");
12
13	match tokio::fs::read(&Uri).await {
14		Ok(Content) => super::OkResponse(RequestId, &Content),
15
16		Err(Error) => super::ErrResponse(RequestId, -32000, format!("readFile: {}", Error)),
17	}
18}