From 4e3e7b10ce70042d2ffa9e391cb18af6de9f8377 Mon Sep 17 00:00:00 2001 From: advplyr Date: Mon, 12 Feb 2024 17:12:49 -0600 Subject: [PATCH] Update:Custom metadata provider adapter sends mediaType as a query param --- server/finders/BookFinder.js | 2 +- server/providers/CustomProviderAdapter.js | 17 +++++++++++++++-- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/server/finders/BookFinder.js b/server/finders/BookFinder.js index 7ba97ed1..f218587c 100644 --- a/server/finders/BookFinder.js +++ b/server/finders/BookFinder.js @@ -157,7 +157,7 @@ class BookFinder { * @returns {Promise} */ 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}`) return books diff --git a/server/providers/CustomProviderAdapter.js b/server/providers/CustomProviderAdapter.js index 36f4c930..3d5209c7 100644 --- a/server/providers/CustomProviderAdapter.js +++ b/server/providers/CustomProviderAdapter.js @@ -10,9 +10,10 @@ class CustomProviderAdapter { * @param {string} title * @param {string} author * @param {string} providerSlug + * @param {string} mediaType * @returns {Promise} */ - async search(title, author, providerSlug) { + async search(title, author, providerSlug, mediaType) { const providerId = providerSlug.split('custom-')[1] const provider = await Database.customMetadataProviderModel.findByPk(providerId) @@ -20,13 +21,25 @@ class CustomProviderAdapter { 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 = {} if (provider.authHeaderValue) { axiosOptions.headers = { '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 return res.data.matches }).catch(error => {