Skip to content

Commit 3908579

Browse files
committed
Up: error message
1 parent 0760a78 commit 3908579

1 file changed

Lines changed: 14 additions & 5 deletions

File tree

app/utils/player.native.js

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -114,13 +114,22 @@ const downloadSong = async (urlStream, id) => {
114114
const contentType = getHeader(res?.headers, 'content-type')
115115
const contentLength = parseInt(getHeader(res?.headers, 'content-length'), 10)
116116
const realSize = await FileSystem.getInfoAsync(fileUri).then(info => info.size)
117-
if (res?.status === 200 && contentLength > 0 && contentType?.includes('audio') && realSize === contentLength) {
118-
global.listCacheSong.push(`${id}.${global.streamFormat}`)
119-
return fileUri
120-
} else {
121-
logger.error('downloadSong', 'Error downloading song', res?.status, contentType, contentLength)
117+
118+
if (res?.status !== 200) {
119+
logger.error('downloadSong', `Error downloading song status not 200 (${res?.status})`)
120+
await FileSystem.deleteAsync(fileUri)
121+
return urlStream
122+
} else if (!contentType?.includes('audio')) {
123+
logger.error('downloadSong', `Error downloading song content-type not audio (${contentType})`)
122124
await FileSystem.deleteAsync(fileUri)
123125
return urlStream
126+
} else if ((contentLength > 0 && realSize !== contentLength) || realSize === 0) {
127+
logger.error('downloadSong', `Error downloading song size mismatch (real: ${realSize} / content-length: ${contentLength})`)
128+
await FileSystem.deleteAsync(fileUri)
129+
return urlStream
130+
} else {
131+
global.listCacheSong.push(`${id}.${global.streamFormat}`)
132+
return fileUri
124133
}
125134
} catch (error) {
126135
logger.error('downloadSong', error)

0 commit comments

Comments
 (0)