From 1c17ef679ddb72889771ba488b416590ba1674cb Mon Sep 17 00:00:00 2001 From: adrifcastr Date: Wed, 21 Jun 2023 14:04:37 +0200 Subject: [PATCH] clean up requests --- src/backend/metadata/tmdb.ts | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/src/backend/metadata/tmdb.ts b/src/backend/metadata/tmdb.ts index 4c3259a3..f5d1e370 100644 --- a/src/backend/metadata/tmdb.ts +++ b/src/backend/metadata/tmdb.ts @@ -101,10 +101,13 @@ const headers = { Authorization: `Bearer ${conf().TMDB_API_KEY}`, }; -async function get(url: string): Promise { - const res = await mwFetch(url, { +async function get(url: string, params?: object): Promise { + const res = await mwFetch(encodeURI(url), { headers, baseURL, + params: { + ...params, + }, }); return res; } @@ -117,14 +120,20 @@ export async function searchMedia( switch (type) { case "movie": - data = await get( - `search/movie?query=${query}&include_adult=false&language=en-US&page=1` - ); + data = await get("search/movie", { + query, + include_adult: false, + language: "en-US", + page: 1, + }); break; case "show": - data = await get( - `search/tv?query=${query}&include_adult=false&language=en-US&page=1` - ); + data = await get("search/tv", { + query, + include_adult: false, + language: "en-US", + page: 1, + }); break; default: throw new Error("Invalid media type");