diff --git a/crates/voidpin/proto/voidpin/v1/voidpin.proto b/crates/voidpin/proto/voidpin/v1/voidpin.proto index 93aa847..4783dee 100644 --- a/crates/voidpin/proto/voidpin/v1/voidpin.proto +++ b/crates/voidpin/proto/voidpin/v1/voidpin.proto @@ -3,7 +3,7 @@ syntax = "proto3"; package voidpin.v1; message CopyRequest { - bytes content = 1; + string content = 1; } message CopyResponse {} @@ -12,7 +12,7 @@ message PasteRequest { } message PasteResponse { - bytes content = 1; + string content = 1; } service VoidPin { diff --git a/crates/voidpin/src/gen/voidpin.v1.rs b/crates/voidpin/src/gen/voidpin.v1.rs index 2497878..d014a09 100644 --- a/crates/voidpin/src/gen/voidpin.v1.rs +++ b/crates/voidpin/src/gen/voidpin.v1.rs @@ -3,8 +3,8 @@ #[allow(clippy::derive_partial_eq_without_eq)] #[derive(Clone, PartialEq, ::prost::Message)] pub struct CopyRequest { - #[prost(bytes="vec", tag="1")] - pub content: ::prost::alloc::vec::Vec, + #[prost(string, tag="1")] + pub content: ::prost::alloc::string::String, } #[allow(clippy::derive_partial_eq_without_eq)] #[derive(Clone, Copy, PartialEq, ::prost::Message)] @@ -17,8 +17,8 @@ pub struct PasteRequest { #[allow(clippy::derive_partial_eq_without_eq)] #[derive(Clone, PartialEq, ::prost::Message)] pub struct PasteResponse { - #[prost(bytes="vec", tag="1")] - pub content: ::prost::alloc::vec::Vec, + #[prost(string, tag="1")] + pub content: ::prost::alloc::string::String, } include!("voidpin.v1.tonic.rs"); // @@protoc_insertion_point(module) \ No newline at end of file diff --git a/crates/voidpin/src/grpc_server.rs b/crates/voidpin/src/grpc_server.rs index fa0d5bc..84b3d33 100644 --- a/crates/voidpin/src/grpc_server.rs +++ b/crates/voidpin/src/grpc_server.rs @@ -25,7 +25,7 @@ impl crate::grpc::void_pin_server::VoidPin for GrpcServer { self.state .local_copier() - .copy(&req.content) + .copy(&req.content.as_bytes()) .await .map_err(|e| tonic::Status::internal(e.to_string()))?; @@ -44,7 +44,7 @@ impl crate::grpc::void_pin_server::VoidPin for GrpcServer { .map_err(|e| tonic::Status::internal(e.to_string()))?; Ok(tonic::Response::new(crate::grpc::PasteResponse { - content: output, + content: String::from_utf8_lossy(&output).to_string(), })) } } diff --git a/crates/voidpin/src/main.rs b/crates/voidpin/src/main.rs index ddc4d84..94c6891 100644 --- a/crates/voidpin/src/main.rs +++ b/crates/voidpin/src/main.rs @@ -100,10 +100,7 @@ async fn main() -> anyhow::Result<()> { } tracing::debug!(content = &input, "found content"); - state - .remote_copier(&remote_host) - .copy(input.as_bytes()) - .await?; + state.remote_copier(&remote_host).copy(input).await?; return Ok(()); } @@ -127,7 +124,7 @@ async fn main() -> anyhow::Result<()> { if let Ok(remote_host) = std::env::var("VOIDPIN_REMOTE") { let output = state.remote_copier(&remote_host).paste().await?; - stdout.write_all(&output).await?; + stdout.write_all(output.as_bytes()).await?; stdout.flush().await?; return Ok(()); @@ -150,16 +147,13 @@ async fn main() -> anyhow::Result<()> { } tracing::debug!(content = &input, "found content"); - state - .remote_copier(&remote_host) - .copy(input.as_bytes()) - .await?; + state.remote_copier(&remote_host).copy(input).await?; } RemoteCommands::Paste { remote_host } => { let output = state.remote_copier(&remote_host).paste().await?; let mut stdout = tokio::io::stdout(); - stdout.write_all(&output).await?; + stdout.write_all(output.as_bytes()).await?; stdout.flush().await?; } }, diff --git a/crates/voidpin/src/remote_copy.rs b/crates/voidpin/src/remote_copy.rs index e47100e..f4858de 100644 --- a/crates/voidpin/src/remote_copy.rs +++ b/crates/voidpin/src/remote_copy.rs @@ -17,7 +17,7 @@ impl RemoteCopier { } } - pub async fn copy(&self, input: &[u8]) -> anyhow::Result<()> { + pub async fn copy(&self, input: String) -> anyhow::Result<()> { let tls = ClientTlsConfig::new(); let channel = Channel::from_shared(self.host.clone())? .tls_config(if self.host.starts_with("https") { @@ -41,7 +41,7 @@ impl RemoteCopier { Ok(()) } - pub async fn paste(&self) -> anyhow::Result> { + pub async fn paste(&self) -> anyhow::Result { let tls = ClientTlsConfig::new(); let channel = Channel::from_shared(self.host.clone())? .tls_config(if self.host.starts_with("https") { @@ -59,10 +59,9 @@ impl RemoteCopier { let resp = client.paste(PasteRequest {}).await?; let output = resp.into_inner().content; - let output = String::from_utf8_lossy(&output); - tracing::info!(content = output.to_string(), "received paste response"); + tracing::info!(content = output, "received paste response"); - Ok(output.as_bytes().to_vec()) + Ok(output) } }