Merge pull request #308 from lbryio/thumbnail-error
This commit is contained in:
commit
14c8764925
2 changed files with 46 additions and 58 deletions
41
dist/bundle.es.js
vendored
41
dist/bundle.es.js
vendored
|
@ -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));
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -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));
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue