[wip] impl Client for ureq::Agent
- use `sharry_file_create` in `AppState`
This commit is contained in:
parent
09af480379
commit
c9528a9ac1
2 changed files with 7 additions and 40 deletions
|
|
@ -47,12 +47,13 @@ impl FileState {
|
|||
|
||||
fn start_upload(
|
||||
self,
|
||||
http: &ureq::Agent,
|
||||
alias: &Alias,
|
||||
share: &Share,
|
||||
) -> io::Result<FileUploading> {
|
||||
http: &impl Client,
|
||||
uri: &Uri,
|
||||
alias_id: &str,
|
||||
share_id: &str,
|
||||
) -> Result<FileUploading, ClientError> {
|
||||
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<Option<()>, 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);
|
||||
|
|
|
|||
|
|
@ -29,40 +29,6 @@ impl FileChecked {
|
|||
))
|
||||
}
|
||||
}
|
||||
|
||||
pub fn start_upload(
|
||||
self,
|
||||
http: &ureq::Agent,
|
||||
alias: &Alias,
|
||||
share: &Share,
|
||||
) -> io::Result<FileUploading> {
|
||||
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 {
|
||||
|
|
|
|||
Loading…
Reference in a new issue