Merge pull request #308 from lbryio/thumbnail-error

This commit is contained in:
Sean Yesmunt 2020-04-27 14:15:05 -04:00 committed by GitHub
commit 14c8764925
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 46 additions and 58 deletions

41
dist/bundle.es.js vendored
View file

@ -4124,6 +4124,23 @@ const doUploadThumbnail = (filePath, thumbnailBlob, fsAdapter, fs, path) => disp
}, doError(error))); }, doError(error)));
}; };
const doUpload = data => {
return fetch(SPEECH_PUBLISH, {
method: 'POST',
body: data
}).then(res => res.text()).then(text => text.length ? JSON.parse(text) : {}).then(json => {
return json.success ? dispatch({
type: UPDATE_PUBLISH_FORM,
data: {
uploadThumbnailStatus: COMPLETE,
thumbnail: `${json.data.url}.${fileExt}`
}
}) : uploadError(json.message || __('Thumbnail upload service may be down, try again later.'));
}).catch(err => {
uploadError(err.message);
});
};
dispatch({ dispatch({
type: UPDATE_PUBLISH_FORM, type: UPDATE_PUBLISH_FORM,
data: { uploadThumbnailStatus: IN_PROGRESS } data: { uploadThumbnailStatus: IN_PROGRESS }
@ -4140,17 +4157,7 @@ const doUploadThumbnail = (filePath, thumbnailBlob, fsAdapter, fs, path) => disp
data.append('name', name); data.append('name', name);
// $FlowFixMe // $FlowFixMe
data.append('file', { uri: 'file://' + filePath, type: fileType, name: fileName }); data.append('file', { uri: 'file://' + filePath, type: fileType, name: fileName });
return doUpload(data);
return fetch(SPEECH_PUBLISH, {
method: 'POST',
body: data
}).then(response => response.json()).then(json => json.success ? dispatch({
type: UPDATE_PUBLISH_FORM,
data: {
uploadThumbnailStatus: COMPLETE,
thumbnail: `${json.data.url}.${fileExt}`
}
}) : uploadError(json.message)).catch(err => uploadError(err.message));
}); });
} else { } else {
if (filePath && fs && path) { if (filePath && fs && path) {
@ -4172,17 +4179,7 @@ const doUploadThumbnail = (filePath, thumbnailBlob, fsAdapter, fs, path) => disp
data.append('name', name); data.append('name', name);
// $FlowFixMe // $FlowFixMe
data.append('file', file); data.append('file', file);
return doUpload(data);
return fetch(SPEECH_PUBLISH, {
method: 'POST',
body: data
}).then(response => response.json()).then(json => json.success ? dispatch({
type: UPDATE_PUBLISH_FORM,
data: {
uploadThumbnailStatus: COMPLETE,
thumbnail: `${json.data.url}${fileExt}`
}
}) : uploadError(json.message)).catch(err => uploadError(err.message));
} }
}; };

View file

@ -94,6 +94,31 @@ export const doUploadThumbnail = (
); );
}; };
const doUpload = data => {
return fetch(SPEECH_PUBLISH, {
method: 'POST',
body: data,
})
.then(res => res.text())
.then(text => (text.length ? JSON.parse(text) : {}))
.then(json => {
return json.success
? dispatch({
type: ACTIONS.UPDATE_PUBLISH_FORM,
data: {
uploadThumbnailStatus: THUMBNAIL_STATUSES.COMPLETE,
thumbnail: `${json.data.url}.${fileExt}`,
},
})
: uploadError(
json.message || __('Thumbnail upload service may be down, try again later.')
);
})
.catch(err => {
uploadError(err.message);
});
};
dispatch({ dispatch({
type: ACTIONS.UPDATE_PUBLISH_FORM, type: ACTIONS.UPDATE_PUBLISH_FORM,
data: { uploadThumbnailStatus: THUMBNAIL_STATUSES.IN_PROGRESS }, data: { uploadThumbnailStatus: THUMBNAIL_STATUSES.IN_PROGRESS },
@ -110,24 +135,7 @@ export const doUploadThumbnail = (
data.append('name', name); data.append('name', name);
// $FlowFixMe // $FlowFixMe
data.append('file', { uri: 'file://' + filePath, type: fileType, name: fileName }); data.append('file', { uri: 'file://' + filePath, type: fileType, name: fileName });
return doUpload(data);
return fetch(SPEECH_PUBLISH, {
method: 'POST',
body: data,
})
.then(response => response.json())
.then(json =>
json.success
? dispatch({
type: ACTIONS.UPDATE_PUBLISH_FORM,
data: {
uploadThumbnailStatus: THUMBNAIL_STATUSES.COMPLETE,
thumbnail: `${json.data.url}.${fileExt}`,
},
})
: uploadError(json.message)
)
.catch(err => uploadError(err.message));
}); });
} else { } else {
if (filePath && fs && path) { if (filePath && fs && path) {
@ -150,24 +158,7 @@ export const doUploadThumbnail = (
data.append('name', name); data.append('name', name);
// $FlowFixMe // $FlowFixMe
data.append('file', file); data.append('file', file);
return doUpload(data);
return fetch(SPEECH_PUBLISH, {
method: 'POST',
body: data,
})
.then(response => response.json())
.then(json =>
json.success
? dispatch({
type: ACTIONS.UPDATE_PUBLISH_FORM,
data: {
uploadThumbnailStatus: THUMBNAIL_STATUSES.COMPLETE,
thumbnail: `${json.data.url}${fileExt}`,
},
})
: uploadError(json.message)
)
.catch(err => uploadError(err.message));
} }
}; };