use std::time::Duration; use crate::{Result, browse}; #[derive(Debug, Clone)] pub struct Supernote { host: String, port: u16, passcode: Option, timeout: Duration, } #[derive(Debug, Clone, Copy, PartialEq, Eq)] pub enum Reachability { Up, WifiTransferOff, Unreachable, } #[derive(Debug, Clone)] pub struct Entry { pub name: String, pub is_dir: bool, pub size: u64, } impl Supernote { pub fn at(host: impl Into) -> Self { Self { host: host.into(), port: 8089, passcode: None, timeout: Duration::from_secs(5), } } #[must_use] pub fn with_port(mut self, port: u16) -> Self { self.port = port; self } #[must_use] pub fn with_passcode(mut self, passcode: impl Into) -> Self { self.passcode = Some(passcode.into()); self } #[must_use] pub fn with_timeout(mut self, timeout: Duration) -> Self { self.timeout = timeout; self } pub fn host(&self) -> &str { &self.host } pub fn reachable(&self) -> Reachability { browse::probe(&self.host, self.port, self.timeout) } pub fn push_pdf(&self, remote_dir: &str, filename: &str, bytes: &[u8]) -> Result<()> { browse::upload( &self.host, self.port, self.passcode.as_deref(), remote_dir, filename, bytes, self.timeout, ) } pub fn list(&self, remote_dir: &str) -> Result> { browse::list( &self.host, self.port, self.passcode.as_deref(), remote_dir, self.timeout, ) } }