forked from advplyr/audiobookshelf
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Include a header in requests to AudiobookCovers
- Loading branch information
1 parent
66585c3
commit 5ced43c
Showing
1 changed file
with
24 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; |