mirror of
https://github.com/advplyr/audiobookshelf.git
synced 2026-07-14 00:32:55 +02:00
Fix:Add timeout to provider matching default to 30s #3000
This commit is contained in:
@@ -2,22 +2,32 @@ const axios = require('axios')
|
||||
const Logger = require('../Logger')
|
||||
|
||||
class AudiobookCovers {
|
||||
constructor() { }
|
||||
#responseTimeout = 30000
|
||||
|
||||
constructor() {}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param {string} search
|
||||
* @param {number} [timeout]
|
||||
* @returns {Promise<{cover: string}[]>}
|
||||
*/
|
||||
async search(search, timeout = this.#responseTimeout) {
|
||||
if (!timeout || isNaN(timeout)) timeout = this.#responseTimeout
|
||||
|
||||
async search(search) {
|
||||
const url = `https://api.audiobookcovers.com/cover/bytext/`
|
||||
const params = new URLSearchParams([['q', search]])
|
||||
const items = await axios.get(url, { params }).then((res) => {
|
||||
if (!res || !res.data) return []
|
||||
return res.data
|
||||
}).catch(error => {
|
||||
Logger.error('[AudiobookCovers] Cover search error', error)
|
||||
return []
|
||||
})
|
||||
return items.map(item => ({ cover: item.versions.png.original }))
|
||||
const items = await axios
|
||||
.get(url, {
|
||||
params,
|
||||
timeout
|
||||
})
|
||||
.then((res) => res?.data || [])
|
||||
.catch((error) => {
|
||||
Logger.error('[AudiobookCovers] Cover search error', error)
|
||||
return []
|
||||
})
|
||||
return items.map((item) => ({ cover: item.versions.png.original }))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
module.exports = AudiobookCovers
|
||||
|
||||
Reference in New Issue
Block a user