diff --git a/src/main.rs b/src/main.rs index 2f51b84..d38e939 100644 --- a/src/main.rs +++ b/src/main.rs @@ -27,7 +27,7 @@ fn main() { info!("share: {share:?}"); for file in args.files { - let file = file.create(&agent, &share).unwrap(); + let file = file.create(&agent, &alias, &share).unwrap(); info!("file: {file:?}"); for chunk in file.chunked(args.chunk_size * 1024 * 1024) { @@ -39,5 +39,5 @@ fn main() { } } - share.notify(&agent).unwrap(); + share.notify(&agent, &alias).unwrap(); } diff --git a/src/sharry/file/mod.rs b/src/sharry/file/mod.rs index 09e08c0..08bf70c 100644 --- a/src/sharry/file/mod.rs +++ b/src/sharry/file/mod.rs @@ -4,7 +4,7 @@ use std::{ ffi::OsStr, fs::metadata, io::{self, ErrorKind}, - path::PathBuf, + path::{Path, PathBuf}, }; use log::{debug, error}; @@ -25,8 +25,8 @@ pub struct File { } impl File { - pub fn new(path: impl Into) -> io::Result { - let path: PathBuf = path.into(); + pub fn new(path: impl AsRef) -> io::Result { + let path = path.as_ref().to_owned(); let m = metadata(&path)?; if !m.is_file() { @@ -45,15 +45,20 @@ impl File { }) } - pub fn create(self, http: &ureq::Agent, share: &Share) -> Result { + pub fn create( + self, + http: &ureq::Agent, + alias: &Alias, + share: &Share, + ) -> Result { if self.patch_uri.is_some() { return Err(Other("patch_uri already set".into())); } - let endpoint = (share.alias).get_endpoint(format!("alias/upload/{}/files/tus", share.id)); + let endpoint = alias.get_endpoint(format!("alias/upload/{}/files/tus", share.id)); let res = (http.post(endpoint)) - .sharry_header(share.alias) + .sharry_header(alias) .header("Sharry-File-Name", &self.name) .header("Upload-Length", self.size) .send_empty()?; diff --git a/src/sharry/share.rs b/src/sharry/share.rs index b374284..b9254bd 100644 --- a/src/sharry/share.rs +++ b/src/sharry/share.rs @@ -6,15 +6,14 @@ use super::{ }; #[derive(Debug)] -pub struct Share<'t> { - pub(super) alias: &'t Alias, +pub struct Share { pub(super) id: String, } -impl<'t> Share<'t> { +impl Share { pub fn create( http: &ureq::Agent, - alias: &'t Alias, + alias: &Alias, data: NewShareRequest, ) -> Result { let res = (http.post(alias.get_endpoint("alias/upload/new"))) @@ -29,14 +28,14 @@ impl<'t> Share<'t> { return Err(ureq::Error::Other("unexpected json response".into())); } - Ok(Self { alias, id: res.id }) + Ok(Self { id: res.id }) } - pub fn notify(&self, http: &ureq::Agent) -> Result<(), ureq::Error> { - let endpoint = (self.alias).get_endpoint(format!("alias/mail/notify/{}", self.id)); + pub fn notify(&self, http: &ureq::Agent, alias: &Alias) -> Result<(), ureq::Error> { + let endpoint = alias.get_endpoint(format!("alias/mail/notify/{}", self.id)); let res = (http.post(endpoint)) - .sharry_header(self.alias) + .sharry_header(alias) .send_empty()? .body_mut() .read_json::()?;