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:
infinite-persistence 2021-11-11 09:55:48 +08:00
parent b5f1ae1291
commit 7ef5975ee8
No known key found for this signature in database
GPG key ID: B9C3252EDC3D0AA0

View file

@ -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();
}, },
}); });