This commit is contained in:
Daniel Shleifman
2021-06-09 12:48:43 +03:00
parent d6b10d79d8
commit c144ef960d
6 changed files with 306 additions and 272 deletions

View File

@@ -0,0 +1,23 @@
import axios from 'axios'
export const getMoviePosters = (movieName, language = 'en') => {
const request = `${`http://api.themoviedb.org/3/search/multi?api_key=${process.env.REACT_APP_TMDB_API_KEY}`}&language=${language}&include_image_language=${language},null&query=${movieName}`
return axios
.get(request)
.then(({ data: { results } }) =>
results.filter(el => el.poster_path).map(el => `https://image.tmdb.org/t/p/w300${el.poster_path}`),
)
.catch(() => null)
}
export const checkImageURL = async url => {
if (!url || !url.match(/.(jpg|jpeg|png|gif)$/i)) return false
try {
await fetch(url)
return true
} catch (e) {
return false
}
}