Skip to main content

Mountain/RPC/CocoonService/GenericRequest/FileSystem/
ReaddirUri.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 Uri = Params
10		.get("uri")
11		.and_then(|V| V.as_str())
12		.or_else(|| Params.as_str())
13		.unwrap_or("")
14		.replace("file://", "");
15
16	match tokio::fs::read_dir(&Uri).await {
17		Ok(mut Entries) => {
18			let mut Names:Vec<String> = Vec::new();
19
20			while let Ok(Some(Entry)) = Entries.next_entry().await {
21				if let Some(Name) = Entry.file_name().to_str() {
22					Names.push(Name.to_string());
23				}
24			}
25
26			super::OkResponse(RequestId, &Names)
27		},
28
29		Err(Error) => super::ErrResponse(RequestId, -32000, format!("readdir: {}", Error)),
30	}
31}