Notify: auto-retry once after 10 seconds
Also: - Show the resume button on notify errors. - Changed the error message to differentiate against v1's.
This commit is contained in:
parent
b5f1ae1291
commit
7ef5975ee8
1 changed files with 29 additions and 18 deletions
|
@ -56,25 +56,36 @@ export function makeResumableUploadRequest(
|
||||||
window.store.dispatch(doUpdateUploadProgress({ params, progress: percentage }));
|
window.store.dispatch(doUpdateUploadProgress({ params, progress: percentage }));
|
||||||
},
|
},
|
||||||
onSuccess: () => {
|
onSuccess: () => {
|
||||||
// Notify lbrynet server
|
let retries = 2;
|
||||||
const xhr = new XMLHttpRequest();
|
|
||||||
xhr.open('POST', `${uploader.url}/notify`);
|
|
||||||
xhr.setRequestHeader('Content-Type', 'application/json');
|
|
||||||
xhr.setRequestHeader('Tus-Resumable', '1.0.0');
|
|
||||||
xhr.setRequestHeader(X_LBRY_AUTH_TOKEN, token);
|
|
||||||
xhr.responseType = 'json';
|
|
||||||
xhr.onload = () => {
|
|
||||||
window.store.dispatch(doUpdateUploadRemove(params));
|
|
||||||
resolve(xhr);
|
|
||||||
};
|
|
||||||
xhr.onerror = () => {
|
|
||||||
reject(new Error(__('There was a problem with your upload. Please try again.')));
|
|
||||||
};
|
|
||||||
xhr.onabort = () => {
|
|
||||||
window.store.dispatch(doUpdateUploadRemove(params));
|
|
||||||
};
|
|
||||||
|
|
||||||
xhr.send(jsonPayload);
|
function makeNotifyRequest() {
|
||||||
|
const xhr = new XMLHttpRequest();
|
||||||
|
xhr.open('POST', `${uploader.url}/notify`);
|
||||||
|
xhr.setRequestHeader('Content-Type', 'application/json');
|
||||||
|
xhr.setRequestHeader('Tus-Resumable', '1.0.0');
|
||||||
|
xhr.setRequestHeader(X_LBRY_AUTH_TOKEN, token);
|
||||||
|
xhr.responseType = 'json';
|
||||||
|
xhr.onload = () => {
|
||||||
|
window.store.dispatch(doUpdateUploadRemove(params));
|
||||||
|
resolve(xhr);
|
||||||
|
};
|
||||||
|
xhr.onerror = () => {
|
||||||
|
if (--retries > 0) {
|
||||||
|
// Auto-retry after 10s delay.
|
||||||
|
setTimeout(() => makeNotifyRequest(), 10000);
|
||||||
|
} else {
|
||||||
|
window.store.dispatch(doUpdateUploadProgress({ params, status: 'error' }));
|
||||||
|
reject(new Error(__('There was a problem in the processing. Please retry.')));
|
||||||
|
}
|
||||||
|
};
|
||||||
|
xhr.onabort = () => {
|
||||||
|
window.store.dispatch(doUpdateUploadRemove(params));
|
||||||
|
};
|
||||||
|
|
||||||
|
xhr.send(jsonPayload);
|
||||||
|
}
|
||||||
|
|
||||||
|
makeNotifyRequest();
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue