Mountain/RPC/CocoonService/GenericRequest/FileSystem/
ReaddirUri.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
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_dir(&Uri).await {
14 Ok(mut Entries) => {
15 let mut Names:Vec<String> = Vec::new();
16
17 while let Ok(Some(Entry)) = Entries.next_entry().await {
18 if let Some(Name) = Entry.file_name().to_str() {
19 Names.push(Name.to_string());
20 }
21 }
22
23 super::OkResponse(RequestId, &Names)
24 },
25
26 Err(Error) => super::ErrResponse(RequestId, -32000, format!("readdir: {}", Error)),
27 }
28}