//! Push a local PDF to a Supernote via Browse & Access. //! //! cargo run --example push -- [remote_dir] [remote_name] //! //! Examples: //! //! cargo run --example push -- 192.168.1.42 ~/Downloads/workout.pdf //! cargo run --example push -- 192.168.1.42 ./test.pdf Document/ripgrow today.pdf //! //! Passcode: set `SUPERNOTE_PASSCODE` in the environment if Browse & Access //! is protected. use std::path::PathBuf; use supernote_push::{Reachability, Supernote}; fn main() -> Result<(), Box> { let mut args = std::env::args().skip(1); let host = args .next() .ok_or("usage: push [remote_dir] [remote_name]")?; let local: PathBuf = args.next().ok_or("missing ")?.into(); let remote_dir = args .next() .unwrap_or_else(|| "Document/ripgrow".to_string()); let remote_name = args.next().unwrap_or_else(|| { local .file_name() .and_then(|s| s.to_str()) .unwrap_or("push.pdf") .to_string() }); let bytes = std::fs::read(&local)?; println!("read {} bytes from {}", bytes.len(), local.display()); let mut sn = Supernote::at(&host); if let Ok(pc) = std::env::var("SUPERNOTE_PASSCODE") { sn = sn.with_passcode(pc); } print!("probing {host}... "); match sn.reachable() { Reachability::Up => println!("up"), Reachability::WifiTransferOff => { println!("responded but not as expected — check Wi-Fi Transfer"); } Reachability::Unreachable => { println!("unreachable"); return Err("device did not respond".into()); } } println!( "POST {host}/{remote_dir} (filename={remote_name}, {} bytes)", bytes.len() ); sn.push_pdf(&remote_dir, &remote_name, &bytes)?; println!("done."); Ok(()) }