mirror of
				https://github.com/advplyr/audiobookshelf.git
				synced 2025-10-27 11:18:14 +01:00 
			
		
		
		
	Fix:Catch exception when failing to download podcast episodes
This commit is contained in:
		
							parent
							
								
									f557289274
								
							
						
					
					
						commit
						065675697d
					
				@ -174,20 +174,24 @@ async function recurseFiles(path, relPathToReplace = null) {
 | 
			
		||||
}
 | 
			
		||||
module.exports.recurseFiles = recurseFiles
 | 
			
		||||
 | 
			
		||||
module.exports.downloadFile = async (url, filepath) => {
 | 
			
		||||
module.exports.downloadFile = (url, filepath) => {
 | 
			
		||||
  return new Promise(async (resolve, reject) => {
 | 
			
		||||
    Logger.debug(`[fileUtils] Downloading file to ${filepath}`)
 | 
			
		||||
 | 
			
		||||
  const writer = fs.createWriteStream(filepath)
 | 
			
		||||
  const response = await axios({
 | 
			
		||||
    axios({
 | 
			
		||||
      url,
 | 
			
		||||
      method: 'GET',
 | 
			
		||||
      responseType: 'stream',
 | 
			
		||||
      timeout: 30000
 | 
			
		||||
  })
 | 
			
		||||
    }).then((response) => {
 | 
			
		||||
      const writer = fs.createWriteStream(filepath)
 | 
			
		||||
      response.data.pipe(writer)
 | 
			
		||||
  return new Promise((resolve, reject) => {
 | 
			
		||||
 | 
			
		||||
      writer.on('finish', resolve)
 | 
			
		||||
      writer.on('error', reject)
 | 
			
		||||
    }).catch((err) => {
 | 
			
		||||
      Logger.error(`[fileUtils] Failed to download file "${filepath}"`, err)
 | 
			
		||||
      reject(err)
 | 
			
		||||
    })
 | 
			
		||||
  })
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
		Loading…
	
		Reference in New Issue
	
	Block a user