Compare commits
6 Commits
v0.0.3
...
cuddle-ple
Author | SHA1 | Date | |
---|---|---|---|
|
e4ce6ea7ef | ||
f060e9d2ca | |||
05b34fd7ee | |||
97f5c3a500 | |||
404e393b97 | |||
838cd9d6b1 |
11
CHANGELOG.md
11
CHANGELOG.md
@@ -6,6 +6,17 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|||||||
|
|
||||||
## [Unreleased]
|
## [Unreleased]
|
||||||
|
|
||||||
|
## [0.0.4] - 2025-08-03
|
||||||
|
|
||||||
|
### Added
|
||||||
|
- pipe output
|
||||||
|
- replace bytes with string to avoid endianness
|
||||||
|
- sanitise output
|
||||||
|
- replace output spawn with native tokio method
|
||||||
|
|
||||||
|
### Other
|
||||||
|
- add print to output from paste
|
||||||
|
|
||||||
## [0.0.3] - 2025-08-03
|
## [0.0.3] - 2025-08-03
|
||||||
|
|
||||||
### Added
|
### Added
|
||||||
|
68
Cargo.lock
generated
68
Cargo.lock
generated
@@ -17,6 +17,15 @@ version = "2.0.1"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "320119579fcad9c21884f5c4861d16174d0e06250625266f50fe6898340abefa"
|
checksum = "320119579fcad9c21884f5c4861d16174d0e06250625266f50fe6898340abefa"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "aho-corasick"
|
||||||
|
version = "1.1.3"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "8e60d3430d3a69478ad0993f19238d2df97c507009a52b3c10addcd7f6bcb916"
|
||||||
|
dependencies = [
|
||||||
|
"memchr",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "anstream"
|
name = "anstream"
|
||||||
version = "0.6.19"
|
version = "0.6.19"
|
||||||
@@ -601,6 +610,15 @@ version = "0.4.27"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "13dc2df351e3202783a1fe0d44375f7295ffb4049267b0f3018346dc122a1d94"
|
checksum = "13dc2df351e3202783a1fe0d44375f7295ffb4049267b0f3018346dc122a1d94"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "matchers"
|
||||||
|
version = "0.1.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "8263075bb86c5a1b1427b5ae862e8889656f126e9f77c484496e8b47cf5c5558"
|
||||||
|
dependencies = [
|
||||||
|
"regex-automata 0.1.10",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "matchit"
|
name = "matchit"
|
||||||
version = "0.7.3"
|
version = "0.7.3"
|
||||||
@@ -847,6 +865,50 @@ dependencies = [
|
|||||||
"bitflags",
|
"bitflags",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "regex"
|
||||||
|
version = "1.11.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "b544ef1b4eac5dc2db33ea63606ae9ffcfac26c1416a2806ae0bf5f56b201191"
|
||||||
|
dependencies = [
|
||||||
|
"aho-corasick",
|
||||||
|
"memchr",
|
||||||
|
"regex-automata 0.4.9",
|
||||||
|
"regex-syntax 0.8.5",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "regex-automata"
|
||||||
|
version = "0.1.10"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "6c230d73fb8d8c1b9c0b3135c5142a8acee3a0558fb8db5cf1cb65f8d7862132"
|
||||||
|
dependencies = [
|
||||||
|
"regex-syntax 0.6.29",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "regex-automata"
|
||||||
|
version = "0.4.9"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "809e8dc61f6de73b46c85f4c96486310fe304c434cfa43669d7b40f711150908"
|
||||||
|
dependencies = [
|
||||||
|
"aho-corasick",
|
||||||
|
"memchr",
|
||||||
|
"regex-syntax 0.8.5",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "regex-syntax"
|
||||||
|
version = "0.6.29"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "f162c6dd7b008981e4d40210aca20b4bd0f9b60ca9271061b07f78537722f2e1"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "regex-syntax"
|
||||||
|
version = "0.8.5"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "2b15c43186be67a4fd63bee50d0303afffcef381492ebe2c5d87f324e1b8815c"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "ring"
|
name = "ring"
|
||||||
version = "0.17.14"
|
version = "0.17.14"
|
||||||
@@ -1275,10 +1337,14 @@ version = "0.3.19"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "e8189decb5ac0fa7bc8b96b7cb9b2701d60d48805aca84a238004d665fcc4008"
|
checksum = "e8189decb5ac0fa7bc8b96b7cb9b2701d60d48805aca84a238004d665fcc4008"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
|
"matchers",
|
||||||
"nu-ansi-term",
|
"nu-ansi-term",
|
||||||
|
"once_cell",
|
||||||
|
"regex",
|
||||||
"sharded-slab",
|
"sharded-slab",
|
||||||
"smallvec",
|
"smallvec",
|
||||||
"thread_local",
|
"thread_local",
|
||||||
|
"tracing",
|
||||||
"tracing-core",
|
"tracing-core",
|
||||||
"tracing-log",
|
"tracing-log",
|
||||||
]
|
]
|
||||||
@@ -1326,7 +1392,7 @@ checksum = "ba73ea9cf16a25df0c8caa16c51acb937d5712a8429db78a3ee29d5dcacd3a65"
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "voidpin"
|
name = "voidpin"
|
||||||
version = "0.0.2"
|
version = "0.0.3"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"anyhow",
|
"anyhow",
|
||||||
"async-trait",
|
"async-trait",
|
||||||
|
@@ -3,7 +3,7 @@ members = ["crates/*"]
|
|||||||
resolver = "2"
|
resolver = "2"
|
||||||
|
|
||||||
[workspace.package]
|
[workspace.package]
|
||||||
version = "0.0.3"
|
version = "0.0.4"
|
||||||
|
|
||||||
[workspace.dependencies]
|
[workspace.dependencies]
|
||||||
voidpin = { path = "crates/voidpin" }
|
voidpin = { path = "crates/voidpin" }
|
||||||
|
@@ -13,7 +13,7 @@ version.workspace = true
|
|||||||
anyhow.workspace = true
|
anyhow.workspace = true
|
||||||
tokio.workspace = true
|
tokio.workspace = true
|
||||||
tracing.workspace = true
|
tracing.workspace = true
|
||||||
tracing-subscriber.workspace = true
|
tracing-subscriber = { workspace = true, features = ["env-filter"] }
|
||||||
clap.workspace = true
|
clap.workspace = true
|
||||||
dotenv.workspace = true
|
dotenv.workspace = true
|
||||||
|
|
||||||
|
@@ -3,7 +3,7 @@ syntax = "proto3";
|
|||||||
package voidpin.v1;
|
package voidpin.v1;
|
||||||
|
|
||||||
message CopyRequest {
|
message CopyRequest {
|
||||||
bytes content = 1;
|
string content = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
message CopyResponse {}
|
message CopyResponse {}
|
||||||
@@ -12,7 +12,7 @@ message PasteRequest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
message PasteResponse {
|
message PasteResponse {
|
||||||
bytes content = 1;
|
string content = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
service VoidPin {
|
service VoidPin {
|
||||||
|
@@ -52,35 +52,36 @@ impl LocalCopier {
|
|||||||
pub async fn paste(&self) -> anyhow::Result<Vec<u8>> {
|
pub async fn paste(&self) -> anyhow::Result<Vec<u8>> {
|
||||||
// FIXME: hardcode for macos
|
// FIXME: hardcode for macos
|
||||||
#[cfg(target_os = "macos")]
|
#[cfg(target_os = "macos")]
|
||||||
let mut paste_process = {
|
let paste_process = {
|
||||||
tokio::process::Command::new("pbpaste")
|
tokio::process::Command::new("pbpaste")
|
||||||
.stdin(Stdio::piped())
|
.stdout(Stdio::piped())
|
||||||
|
.stderr(Stdio::piped())
|
||||||
.spawn()?
|
.spawn()?
|
||||||
};
|
};
|
||||||
#[cfg(target_os = "linux")]
|
#[cfg(target_os = "linux")]
|
||||||
let mut paste_process = {
|
let mut paste_process = {
|
||||||
tokio::process::Command::new("wl-paste")
|
tokio::process::Command::new("wl-paste")
|
||||||
.stdin(Stdio::piped())
|
.stdout(Stdio::piped())
|
||||||
|
.stderr(Stdio::piped())
|
||||||
.spawn()?
|
.spawn()?
|
||||||
};
|
};
|
||||||
#[cfg(target_os = "windows")]
|
#[cfg(target_os = "windows")]
|
||||||
let mut paste_process = {
|
let mut paste_process = {
|
||||||
todo!("windows not supported yet");
|
todo!("windows not supported yet");
|
||||||
};
|
};
|
||||||
let mut buf = Vec::new();
|
|
||||||
|
|
||||||
if let Some(mut stdout_handle) = paste_process.stdout.take() {
|
let output = paste_process.wait_with_output().await?;
|
||||||
stdout_handle
|
|
||||||
.read_to_end(&mut buf)
|
if !output.status.success() {
|
||||||
.await
|
anyhow::bail!(
|
||||||
.context("failed to write input to paste process")?;
|
"output failed with: {}, {}, exit_code: {}",
|
||||||
|
std::str::from_utf8(&output.stdout).unwrap_or_default(),
|
||||||
|
std::str::from_utf8(&output.stderr).unwrap_or_default(),
|
||||||
|
output.status.code().unwrap_or_default(),
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
let status = paste_process.wait().await?;
|
Ok(output.stdout)
|
||||||
|
|
||||||
tracing::info!("paste process ended with status: {:?}", status);
|
|
||||||
|
|
||||||
Ok(buf)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -3,8 +3,8 @@
|
|||||||
#[allow(clippy::derive_partial_eq_without_eq)]
|
#[allow(clippy::derive_partial_eq_without_eq)]
|
||||||
#[derive(Clone, PartialEq, ::prost::Message)]
|
#[derive(Clone, PartialEq, ::prost::Message)]
|
||||||
pub struct CopyRequest {
|
pub struct CopyRequest {
|
||||||
#[prost(bytes="vec", tag="1")]
|
#[prost(string, tag="1")]
|
||||||
pub content: ::prost::alloc::vec::Vec<u8>,
|
pub content: ::prost::alloc::string::String,
|
||||||
}
|
}
|
||||||
#[allow(clippy::derive_partial_eq_without_eq)]
|
#[allow(clippy::derive_partial_eq_without_eq)]
|
||||||
#[derive(Clone, Copy, PartialEq, ::prost::Message)]
|
#[derive(Clone, Copy, PartialEq, ::prost::Message)]
|
||||||
@@ -17,8 +17,8 @@ pub struct PasteRequest {
|
|||||||
#[allow(clippy::derive_partial_eq_without_eq)]
|
#[allow(clippy::derive_partial_eq_without_eq)]
|
||||||
#[derive(Clone, PartialEq, ::prost::Message)]
|
#[derive(Clone, PartialEq, ::prost::Message)]
|
||||||
pub struct PasteResponse {
|
pub struct PasteResponse {
|
||||||
#[prost(bytes="vec", tag="1")]
|
#[prost(string, tag="1")]
|
||||||
pub content: ::prost::alloc::vec::Vec<u8>,
|
pub content: ::prost::alloc::string::String,
|
||||||
}
|
}
|
||||||
include!("voidpin.v1.tonic.rs");
|
include!("voidpin.v1.tonic.rs");
|
||||||
// @@protoc_insertion_point(module)
|
// @@protoc_insertion_point(module)
|
@@ -25,7 +25,7 @@ impl crate::grpc::void_pin_server::VoidPin for GrpcServer {
|
|||||||
|
|
||||||
self.state
|
self.state
|
||||||
.local_copier()
|
.local_copier()
|
||||||
.copy(&req.content)
|
.copy(&req.content.as_bytes())
|
||||||
.await
|
.await
|
||||||
.map_err(|e| tonic::Status::internal(e.to_string()))?;
|
.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()))?;
|
.map_err(|e| tonic::Status::internal(e.to_string()))?;
|
||||||
|
|
||||||
Ok(tonic::Response::new(crate::grpc::PasteResponse {
|
Ok(tonic::Response::new(crate::grpc::PasteResponse {
|
||||||
content: output,
|
content: String::from_utf8_lossy(&output).to_string(),
|
||||||
}))
|
}))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -9,6 +9,7 @@ use remote_copy::RemoteCopierState;
|
|||||||
use state::State;
|
use state::State;
|
||||||
use tokio::io::AsyncWriteExt;
|
use tokio::io::AsyncWriteExt;
|
||||||
use tonic::transport;
|
use tonic::transport;
|
||||||
|
use tracing_subscriber::EnvFilter;
|
||||||
|
|
||||||
mod grpc {
|
mod grpc {
|
||||||
include!("gen/voidpin.v1.rs");
|
include!("gen/voidpin.v1.rs");
|
||||||
@@ -64,7 +65,14 @@ enum RemoteCommands {
|
|||||||
#[tokio::main]
|
#[tokio::main]
|
||||||
async fn main() -> anyhow::Result<()> {
|
async fn main() -> anyhow::Result<()> {
|
||||||
dotenv::dotenv().ok();
|
dotenv::dotenv().ok();
|
||||||
tracing_subscriber::fmt::init();
|
tracing_subscriber::fmt()
|
||||||
|
.with_env_filter(
|
||||||
|
EnvFilter::builder()
|
||||||
|
//.with_default_directive("error".parse().unwrap())
|
||||||
|
.from_env_lossy(),
|
||||||
|
)
|
||||||
|
.with_writer(std::io::stderr)
|
||||||
|
.init();
|
||||||
|
|
||||||
let cli = Command::parse();
|
let cli = Command::parse();
|
||||||
tracing::debug!("Starting cli");
|
tracing::debug!("Starting cli");
|
||||||
@@ -92,10 +100,7 @@ async fn main() -> anyhow::Result<()> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
tracing::debug!(content = &input, "found content");
|
tracing::debug!(content = &input, "found content");
|
||||||
state
|
state.remote_copier(&remote_host).copy(input).await?;
|
||||||
.remote_copier(&remote_host)
|
|
||||||
.copy(input.as_bytes())
|
|
||||||
.await?;
|
|
||||||
|
|
||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
@@ -115,10 +120,11 @@ async fn main() -> anyhow::Result<()> {
|
|||||||
}
|
}
|
||||||
Commands::Paste {} => {
|
Commands::Paste {} => {
|
||||||
let mut stdout = tokio::io::stdout();
|
let mut stdout = tokio::io::stdout();
|
||||||
|
|
||||||
if let Ok(remote_host) = std::env::var("VOIDPIN_REMOTE") {
|
if let Ok(remote_host) = std::env::var("VOIDPIN_REMOTE") {
|
||||||
let output = state.remote_copier(&remote_host).paste().await?;
|
let output = state.remote_copier(&remote_host).paste().await?;
|
||||||
|
|
||||||
stdout.write_all(&output).await?;
|
stdout.write_all(output.as_bytes()).await?;
|
||||||
stdout.flush().await?;
|
stdout.flush().await?;
|
||||||
|
|
||||||
return Ok(());
|
return Ok(());
|
||||||
@@ -141,16 +147,13 @@ async fn main() -> anyhow::Result<()> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
tracing::debug!(content = &input, "found content");
|
tracing::debug!(content = &input, "found content");
|
||||||
state
|
state.remote_copier(&remote_host).copy(input).await?;
|
||||||
.remote_copier(&remote_host)
|
|
||||||
.copy(input.as_bytes())
|
|
||||||
.await?;
|
|
||||||
}
|
}
|
||||||
RemoteCommands::Paste { remote_host } => {
|
RemoteCommands::Paste { remote_host } => {
|
||||||
let output = state.remote_copier(&remote_host).paste().await?;
|
let output = state.remote_copier(&remote_host).paste().await?;
|
||||||
|
|
||||||
let mut stdout = tokio::io::stdout();
|
let mut stdout = tokio::io::stdout();
|
||||||
stdout.write_all(&output).await?;
|
stdout.write_all(output.as_bytes()).await?;
|
||||||
stdout.flush().await?;
|
stdout.flush().await?;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
@@ -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 tls = ClientTlsConfig::new();
|
||||||
let channel = Channel::from_shared(self.host.clone())?
|
let channel = Channel::from_shared(self.host.clone())?
|
||||||
.tls_config(if self.host.starts_with("https") {
|
.tls_config(if self.host.starts_with("https") {
|
||||||
@@ -41,7 +41,7 @@ impl RemoteCopier {
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn paste(&self) -> anyhow::Result<Vec<u8>> {
|
pub async fn paste(&self) -> anyhow::Result<String> {
|
||||||
let tls = ClientTlsConfig::new();
|
let tls = ClientTlsConfig::new();
|
||||||
let channel = Channel::from_shared(self.host.clone())?
|
let channel = Channel::from_shared(self.host.clone())?
|
||||||
.tls_config(if self.host.starts_with("https") {
|
.tls_config(if self.host.starts_with("https") {
|
||||||
@@ -58,8 +58,8 @@ impl RemoteCopier {
|
|||||||
tracing::info!("sending paste request");
|
tracing::info!("sending paste request");
|
||||||
let resp = client.paste(PasteRequest {}).await?;
|
let resp = client.paste(PasteRequest {}).await?;
|
||||||
|
|
||||||
tracing::info!("received paste response");
|
|
||||||
let output = resp.into_inner().content;
|
let output = resp.into_inner().content;
|
||||||
|
tracing::info!(content = output, "received paste response");
|
||||||
|
|
||||||
Ok(output)
|
Ok(output)
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user