| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
use std::path::PathBuf; |
| 14 |
|
| 15 |
use supernote_push::{Reachability, Supernote}; |
| 16 |
|
| 17 |
fn main() -> Result<(), Box<dyn std::error::Error>> { |
| 18 |
let mut args = std::env::args().skip(1); |
| 19 |
let host = args |
| 20 |
.next() |
| 21 |
.ok_or("usage: push <host> <local.pdf> [remote_dir] [remote_name]")?; |
| 22 |
let local: PathBuf = args.next().ok_or("missing <local.pdf>")?.into(); |
| 23 |
let remote_dir = args |
| 24 |
.next() |
| 25 |
.unwrap_or_else(|| "Document/ripgrow".to_string()); |
| 26 |
let remote_name = args.next().unwrap_or_else(|| { |
| 27 |
local |
| 28 |
.file_name() |
| 29 |
.and_then(|s| s.to_str()) |
| 30 |
.unwrap_or("push.pdf") |
| 31 |
.to_string() |
| 32 |
}); |
| 33 |
|
| 34 |
let bytes = std::fs::read(&local)?; |
| 35 |
println!("read {} bytes from {}", bytes.len(), local.display()); |
| 36 |
|
| 37 |
let mut sn = Supernote::at(&host); |
| 38 |
if let Ok(pc) = std::env::var("SUPERNOTE_PASSCODE") { |
| 39 |
sn = sn.with_passcode(pc); |
| 40 |
} |
| 41 |
|
| 42 |
print!("probing {host}... "); |
| 43 |
match sn.reachable() { |
| 44 |
Reachability::Up => println!("up"), |
| 45 |
Reachability::WifiTransferOff => { |
| 46 |
println!("responded but not as expected — check Wi-Fi Transfer"); |
| 47 |
} |
| 48 |
Reachability::Unreachable => { |
| 49 |
println!("unreachable"); |
| 50 |
return Err("device did not respond".into()); |
| 51 |
} |
| 52 |
} |
| 53 |
|
| 54 |
println!( |
| 55 |
"POST {host}/{remote_dir} (filename={remote_name}, {} bytes)", |
| 56 |
bytes.len() |
| 57 |
); |
| 58 |
sn.push_pdf(&remote_dir, &remote_name, &bytes)?; |
| 59 |
println!("done."); |
| 60 |
Ok(()) |
| 61 |
} |
| 62 |
|