mirror of
https://github.com/movie-web/movie-web.git
synced 2024-11-11 02:25:08 +01:00
clean up requests
This commit is contained in:
parent
09f6a3125b
commit
1c17ef679d
@ -101,10 +101,13 @@ const headers = {
|
||||
Authorization: `Bearer ${conf().TMDB_API_KEY}`,
|
||||
};
|
||||
|
||||
async function get<T>(url: string): Promise<T> {
|
||||
const res = await mwFetch<any>(url, {
|
||||
async function get<T>(url: string, params?: object): Promise<T> {
|
||||
const res = await mwFetch<any>(encodeURI(url), {
|
||||
headers,
|
||||
baseURL,
|
||||
params: {
|
||||
...params,
|
||||
},
|
||||
});
|
||||
return res;
|
||||
}
|
||||
@ -117,14 +120,20 @@ export async function searchMedia(
|
||||
|
||||
switch (type) {
|
||||
case "movie":
|
||||
data = await get<TMDBMovieResponse>(
|
||||
`search/movie?query=${query}&include_adult=false&language=en-US&page=1`
|
||||
);
|
||||
data = await get<TMDBMovieResponse>("search/movie", {
|
||||
query,
|
||||
include_adult: false,
|
||||
language: "en-US",
|
||||
page: 1,
|
||||
});
|
||||
break;
|
||||
case "show":
|
||||
data = await get<TMDBShowResponse>(
|
||||
`search/tv?query=${query}&include_adult=false&language=en-US&page=1`
|
||||
);
|
||||
data = await get<TMDBShowResponse>("search/tv", {
|
||||
query,
|
||||
include_adult: false,
|
||||
language: "en-US",
|
||||
page: 1,
|
||||
});
|
||||
break;
|
||||
default:
|
||||
throw new Error("Invalid media type");
|
||||
|
Loading…
Reference in New Issue
Block a user