From 5ced43ccdecdb74fbb1e817c72e6795c946dc6ab Mon Sep 17 00:00:00 2001 From: Spenser Bushey Date: Sun, 4 Feb 2024 16:00:25 -0800 Subject: [PATCH] Include a header in requests to AudiobookCovers --- server/providers/AudiobookCovers.js | 40 +++++++++++++++++------------ 1 file changed, 24 insertions(+), 16 deletions(-) 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;