fix the try catch download media
This commit is contained in:
parent
02ba6e9961
commit
99973c0d28
|
@ -300,6 +300,7 @@ class MessageAudio extends React.Component<IMessageAudioProps, IMessageAudioStat
|
|||
const { messageId } = this.props;
|
||||
const { user } = this.context;
|
||||
this.setState({ loading: true });
|
||||
try {
|
||||
const url = this.getUrl();
|
||||
if (url && this.filePath) {
|
||||
const audio = await downloadMediaFile({
|
||||
|
@ -308,12 +309,13 @@ class MessageAudio extends React.Component<IMessageAudioProps, IMessageAudioStat
|
|||
messageId,
|
||||
path: this.filePath
|
||||
});
|
||||
if (!audio) {
|
||||
return this.setState({ loading: false, toDownload: true });
|
||||
}
|
||||
await this.sound.loadAsync({ uri: this.filePath });
|
||||
|
||||
await this.sound.loadAsync({ uri: audio });
|
||||
return this.setState({ loading: false, toDownload: false });
|
||||
}
|
||||
} catch {
|
||||
return this.setState({ loading: false, toDownload: true });
|
||||
}
|
||||
};
|
||||
|
||||
onPress = () => {
|
||||
|
|
|
@ -142,6 +142,7 @@ const ImageContainer = React.memo(
|
|||
|
||||
const handleDownload = async () => {
|
||||
setLoading(true);
|
||||
try {
|
||||
// The param file.title_link is the one that point to image with best quality, however we still need to test the imageUrl
|
||||
// And we don't have sure that exists the file.title_link
|
||||
const imgUrl = imageUrl || formatAttachmentUrl(newFile.title_link || newFile.image_url, user.id, user.token, baseUrl);
|
||||
|
@ -151,16 +152,18 @@ const ImageContainer = React.memo(
|
|||
messageId,
|
||||
path: filePath.current
|
||||
});
|
||||
if (!imageUri) {
|
||||
setLoading(false);
|
||||
return setToDownload(true);
|
||||
}
|
||||
|
||||
setNewFile(prev => ({
|
||||
...prev,
|
||||
title_link: filePath.current
|
||||
title_link: imageUri
|
||||
}));
|
||||
setToDownload(false);
|
||||
setLoading(false);
|
||||
} catch (e) {
|
||||
console.log('🚀 ~ file: Image.tsx:164 ~ handleDownload ~ e:', e);
|
||||
setLoading(false);
|
||||
return setToDownload(true);
|
||||
}
|
||||
};
|
||||
|
||||
const onPress = () => {
|
||||
|
|
|
@ -123,19 +123,20 @@ const Video = React.memo(
|
|||
|
||||
const handleDownload = async () => {
|
||||
setLoading(true);
|
||||
try {
|
||||
const videoUri = await downloadMediaFile({
|
||||
downloadUrl: video,
|
||||
mediaType: MediaTypes.video,
|
||||
messageId,
|
||||
path: filePath.current
|
||||
});
|
||||
if (videoUri) {
|
||||
setNewFile(prev => ({
|
||||
...prev,
|
||||
video_url: filePath.current
|
||||
video_url: videoUri
|
||||
}));
|
||||
}
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
};
|
||||
|
||||
const onPress = async () => {
|
||||
|
|
|
@ -56,7 +56,7 @@ export function downloadMediaFile({
|
|||
messageId: string;
|
||||
downloadUrl: string;
|
||||
path: string;
|
||||
}): Promise<string | void> {
|
||||
}): Promise<string> {
|
||||
return new Promise((resolve, reject) => {
|
||||
const downloadKey = mediaDownloadKey(mediaType, messageId);
|
||||
const options = {
|
||||
|
|
Loading…
Reference in New Issue