From 6f3dc609942a75b79cf3d0523bf8109667fde045 Mon Sep 17 00:00:00 2001 From: Reinaldo Neto Date: Wed, 7 Jun 2023 12:36:30 -0300 Subject: [PATCH] variable isAutoDownloadEnable name and handleMediaDownload getExtension --- app/containers/message/Audio.tsx | 11 +++++---- app/lib/methods/handleMediaDownload.ts | 31 ++++++++++++-------------- 2 files changed, 19 insertions(+), 23 deletions(-) diff --git a/app/containers/message/Audio.tsx b/app/containers/message/Audio.tsx index 9eac3a908..9e68355f6 100644 --- a/app/containers/message/Audio.tsx +++ b/app/containers/message/Audio.tsx @@ -178,13 +178,12 @@ class MessageAudio extends React.Component { + handleDownload = async () => { const { messageId } = this.props; // @ts-ignore can't use declare to type this const { user } = this.context; @@ -311,7 +310,7 @@ class MessageAudio extends React.Component { const { cached } = this.state; - return cached ? this.togglePlayPause() : this.startDownload(); + return cached ? this.togglePlayPause() : this.handleDownload(); }; playPause = async () => { diff --git a/app/lib/methods/handleMediaDownload.ts b/app/lib/methods/handleMediaDownload.ts index 10e839982..15ca324d8 100644 --- a/app/lib/methods/handleMediaDownload.ts +++ b/app/lib/methods/handleMediaDownload.ts @@ -77,23 +77,20 @@ const getExtension = (type: MediaTypes, mimeType?: string) => { if (!mimeType) { return defaultType[type]; } - const extensionFromMime = () => { - // The library is returning mpag instead of mp3 for audio/mpeg - if (mimeType === 'audio/mpeg') { - return 'mp3'; - } - // For older audios the server is returning the type audio/aac and we can't play it as mp3 - if (mimeType === 'audio/aac') { - return 'm4a'; - } - const extension = mime.extension(mimeType); - // The mime.extension can return false when there aren't any extension - if (!extension) { - return defaultType[type]; - } - return extension; - }; - return extensionFromMime(); + // The library is returning mpag instead of mp3 for audio/mpeg + if (mimeType === 'audio/mpeg') { + return 'mp3'; + } + // For older audios the server is returning the type audio/aac and we can't play it as mp3 + if (mimeType === 'audio/aac') { + return 'm4a'; + } + const extension = mime.extension(mimeType); + // The mime.extension can return false when there aren't any extension + if (!extension) { + return defaultType[type]; + } + return extension; }; const ensureDirAsync = async (dir: string, intermediates = true): Promise => {