mirror of
https://github.com/advplyr/audiobookshelf.git
synced 2024-12-20 19:06:06 +01:00
34 lines
865 B
JavaScript
34 lines
865 B
JavaScript
const axios = require('axios')
|
|
const Logger = require('../Logger')
|
|
|
|
class AudiobookCovers {
|
|
#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
|
|
|
|
const url = `https://api.audiobookcovers.com/cover/bytext/`
|
|
const params = new URLSearchParams([['q', search]])
|
|
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
|