feat(grpc): call walk_dir from grpc service

This commit is contained in:
Alexander Navarro 2024-04-24 11:23:36 -04:00
parent f803aa92f7
commit 8cd4b4b10f
4 changed files with 41 additions and 9 deletions

View file

@ -1,8 +1,12 @@
use crate::file_explorer;
use super::grpc_juno;
use grpc_juno::juno_request_server::{JunoRequest, JunoRequestServer};
use grpc_juno::{PingRequestMessage, PingResponseMessage};
use grpc_juno::{GetFilesRequest, GetFilesResponse, PingRequestMessage, PingResponseMessage};
use std::error::Error;
use std::net::SocketAddr;
use std::path::PathBuf;
use std::str::FromStr;
use tonic::transport::Server;
use tonic::{async_trait, Request, Response, Result, Status};
@ -29,6 +33,26 @@ impl JunoRequest for GRPCServer {
Ok(Response::new(reply))
}
async fn get_files(
&self,
request: Request<GetFilesRequest>,
) -> Result<Response<GetFilesResponse>, Status> {
let path = PathBuf::from_str(request.into_inner().path.as_str())
.expect("Failed to create pathbuf");
let files = match file_explorer::walk_dir(&path) {
Ok(files) => files,
Err(_err) => panic!("Error reading path: {:?}", path),
};
eprintln!("DEBUGPRINT[2]: server.rs:44: files={:#?}", files);
let reply = GetFilesResponse {
files: files.iter().map(|x| x.display().to_string()).collect(),
};
Ok(Response::new(reply))
}
}
#[async_trait]