Skip to content

Commit

Permalink
feat(dlg): make actual store_upload_url() call
Browse files Browse the repository at this point in the history
We also assure to call only as often as we have to, keeping some state
between the loops accordingly.
  • Loading branch information
Byron committed Mar 21, 2015
1 parent 9ea8527 commit ffef7dd
Showing 1 changed file with 20 additions and 9 deletions.
29 changes: 20 additions & 9 deletions src/mako/lib/mbuild.mako
Original file line number Diff line number Diff line change
Expand Up @@ -653,6 +653,7 @@ else {
% if resumable_media_param:
let mut should_ask_dlg_for_url = false;
let mut upload_url_from_server = true;
let mut upload_url: Option<String> = None;
% endif
Expand All @@ -675,6 +676,7 @@ else {
% if resumable_media_param:
if should_ask_dlg_for_url && (upload_url = dlg.upload_url()) == () && upload_url.is_some() {
should_ask_dlg_for_url = false;
upload_url_from_server = false;
let mut response = hyper::client::Response::new(Box::new(cmn::DummyNetworkStream));
match response {
Ok(ref mut res) => {
Expand Down Expand Up @@ -730,6 +732,7 @@ else {
}
% endif ## media upload handling
% if resumable_media_param:
upload_url_from_server = true;
if protocol == "${resumable_media_param.protocol}" {
req = req.header(cmn::XUploadContentType(reader_mime_type.clone()));
}
Expand Down Expand Up @@ -768,15 +771,23 @@ else {
if protocol == "${resumable_media_param.protocol}" {
${READER_SEEK | indent_all_but_first_by(6)}
let mut client = &mut *self.hub.client.borrow_mut();
match (cmn::ResumableUploadHelper {
client: &mut client.borrow_mut(),
delegate: dlg,
auth: &mut *self.hub.auth.borrow_mut(),
url: &res.headers.get::<Location>().expect("Location header is part of protocol").0,
reader: &mut reader,
media_type: reader_mime_type.clone(),
content_size: size
}.upload()) {
let upload_result = {
let url = &res.headers.get::<Location>().expect("Location header is part of protocol").0;
if upload_url_from_server {
dlg.store_upload_url(url);
}
cmn::ResumableUploadHelper {
client: &mut client.borrow_mut(),
delegate: dlg,
auth: &mut *self.hub.auth.borrow_mut(),
url: url,
reader: &mut reader,
media_type: reader_mime_type.clone(),
content_size: size
}.upload()
};
match upload_result {
Err(err) => {
## Do not ask the delgate again, as it was asked by the helper !
${delegate_finish}(false);
Expand Down

0 comments on commit ffef7dd

Please sign in to comment.