diff --git a/server/providers/AudiobookCovers.js b/server/providers/AudiobookCovers.js index 2d562f15bb..625d3bf90e 100644 --- a/server/providers/AudiobookCovers.js +++ b/server/providers/AudiobookCovers.js @@ -1,23 +1,31 @@ -const axios = require('axios') -const Logger = require('../Logger') +const axios = require("axios"); +const Logger = require("../Logger"); class AudiobookCovers { - constructor() { } + constructor() {} async search(search) { - const url = `https://api.audiobookcovers.com/cover/ai-search` - 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 url = "https://api.audiobookcovers.com/cover/ai-search"; + const request_options = { + params: { + q: search, + }, + headers: { + "User-Agent": `Audiobookshelf/${global.ServerSettings.version}`, + }, + }; + const items = await axios + .get(url, request_options) + .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 })); } } - - -module.exports = AudiobookCovers +module.exports = AudiobookCovers;