diff --git a/src/appstate.rs b/src/appstate.rs index 1c0d1f2..06705c0 100644 --- a/src/appstate.rs +++ b/src/appstate.rs @@ -47,12 +47,13 @@ impl FileState { fn start_upload( self, - http: &ureq::Agent, - alias: &Alias, - share: &Share, - ) -> io::Result { + http: &impl Client, + uri: &Uri, + alias_id: &str, + share_id: &str, + ) -> Result { match self { - FileState::C(checked) => checked.start_upload(http, alias, share), + FileState::C(checked) => http.sharry_file_create(uri, alias_id, share_id, checked), FileState::U(uploading) => Ok(uploading), } } @@ -130,7 +131,7 @@ impl AppState { ) -> Result, UploadError> { let uploading = if let Some(state) = self.files.pop_front() { state - .start_upload(http, &self.alias_id, &self.share_id) + .start_upload(http, &self.uri, &self.alias_id, &self.share_id) .unwrap() // HACK unwrap } else { return Ok(None); diff --git a/src/sharry/file/checked.rs b/src/sharry/file/checked.rs index 4a77c23..b56d62d 100644 --- a/src/sharry/file/checked.rs +++ b/src/sharry/file/checked.rs @@ -29,40 +29,6 @@ impl FileChecked { )) } } - - pub fn start_upload( - self, - http: &ureq::Agent, - alias: &Alias, - share: &Share, - ) -> io::Result { - let size = self.get_size(); - - let res = { - let endpoint = alias.get_endpoint(format!("alias/upload/{}/files/tus", share.id)); - - (http.post(endpoint)) - .sharry_header(alias) - .header("Sharry-File-Name", self.get_name()) - .header("Upload-Length", size) - .send_empty() - .map_err(ureq::Error::into_io)? - }; - - if res.status() != StatusCode::CREATED { - return Err(io::Error::other("unexpected response status")); - } - - let location = (res.headers().get("Location")) - .ok_or_else(|| io::Error::other("Location header not found"))? - .to_str() - .map_err(|_| io::Error::other("Location header invalid"))? - .to_string(); - - debug!("patch uri: {location}"); - - Ok(FileUploading::new(self.path, size, location)) - } } impl<'t> SharryFile<'t> for FileChecked {