Update:Custom metadata provider adapter sends mediaType as a query param

This commit is contained in:
advplyr 2024-02-12 17:12:49 -06:00
parent ce7f81d676
commit 4e3e7b10ce
2 changed files with 16 additions and 3 deletions

View File

@ -157,7 +157,7 @@ class BookFinder {
* @returns {Promise<Object[]>} * @returns {Promise<Object[]>}
*/ */
async getCustomProviderResults(title, author, providerSlug) { async getCustomProviderResults(title, author, providerSlug) {
const books = await this.customProviderAdapter.search(title, author, providerSlug) const books = await this.customProviderAdapter.search(title, author, providerSlug, 'book')
if (this.verbose) Logger.debug(`Custom provider '${providerSlug}' Search Results: ${books.length || 0}`) if (this.verbose) Logger.debug(`Custom provider '${providerSlug}' Search Results: ${books.length || 0}`)
return books return books

View File

@ -10,9 +10,10 @@ class CustomProviderAdapter {
* @param {string} title * @param {string} title
* @param {string} author * @param {string} author
* @param {string} providerSlug * @param {string} providerSlug
* @param {string} mediaType
* @returns {Promise<Object[]>} * @returns {Promise<Object[]>}
*/ */
async search(title, author, providerSlug) { async search(title, author, providerSlug, mediaType) {
const providerId = providerSlug.split('custom-')[1] const providerId = providerSlug.split('custom-')[1]
const provider = await Database.customMetadataProviderModel.findByPk(providerId) const provider = await Database.customMetadataProviderModel.findByPk(providerId)
@ -20,13 +21,25 @@ class CustomProviderAdapter {
throw new Error("Custom provider not found for the given id") throw new Error("Custom provider not found for the given id")
} }
// Setup query params
const queryObj = {
mediaType,
query: title
}
if (author) {
queryObj.author = author
}
const queryString = (new URLSearchParams(queryObj)).toString()
// Setup headers
const axiosOptions = {} const axiosOptions = {}
if (provider.authHeaderValue) { if (provider.authHeaderValue) {
axiosOptions.headers = { axiosOptions.headers = {
'Authorization': provider.authHeaderValue 'Authorization': provider.authHeaderValue
} }
} }
const matches = await axios.get(`${provider.url}/search?query=${encodeURIComponent(title)}${!!author ? `&author=${encodeURIComponent(author)}` : ""}`, axiosOptions).then((res) => {
const matches = await axios.get(`${provider.url}/search?${queryString}}`, axiosOptions).then((res) => {
if (!res?.data || !Array.isArray(res.data.matches)) return null if (!res?.data || !Array.isArray(res.data.matches)) return null
return res.data.matches return res.data.matches
}).catch(error => { }).catch(error => {