Improve search api

This commit is contained in:
2025-10-31 16:03:18 +03:30
parent 9375c6a9a7
commit 4b1cd06ac7
46 changed files with 29 additions and 14 deletions

0
.editorconfig Normal file → Executable file
View File

0
.gitattributes vendored Normal file → Executable file
View File

0
.github/workflows/deploy.yml vendored Normal file → Executable file
View File

0
.gitignore vendored Normal file → Executable file
View File

0
.prettierrc.json Normal file → Executable file
View File

0
.vscode/extensions.json vendored Normal file → Executable file
View File

0
README.md Normal file → Executable file
View File

0
env.d.ts vendored Normal file → Executable file
View File

0
eslint.config.ts Normal file → Executable file
View File

0
index.html Normal file → Executable file
View File

0
package.json Normal file → Executable file
View File

0
pnpm-lock.yaml generated Normal file → Executable file
View File

0
public/favicon.ico Normal file → Executable file
View File

Before

Width:  |  Height:  |  Size: 4.2 KiB

After

Width:  |  Height:  |  Size: 4.2 KiB

0
public/robots.txt Normal file → Executable file
View File

0
src/App.vue Normal file → Executable file
View File

0
src/components/AddMoreCard.vue Normal file → Executable file
View File

0
src/components/ImageWithFallback.vue Normal file → Executable file
View File

0
src/components/LoadingSpinner.vue Normal file → Executable file
View File

0
src/components/MediaCard.vue Normal file → Executable file
View File

0
src/components/MediaDetails.vue Normal file → Executable file
View File

0
src/components/MediaList.vue Normal file → Executable file
View File

0
src/components/MediaTypeBadge.vue Normal file → Executable file
View File

0
src/components/NavBar.vue Normal file → Executable file
View File

0
src/components/SearchBar.vue Normal file → Executable file
View File

0
src/components/alerts/ErrorAlert.vue Normal file → Executable file
View File

43
src/lib/api.ts Normal file → Executable file
View File

@@ -19,32 +19,47 @@ const instance = axios.create({
})
export const searchMovies = async (query: string): Promise<MediaResponseType> => {
const response = await instance.get(`/search/multi`, {
params: {
query: query,
include_adult: true,
},
})
const [movieSearch, tvSearch] = await Promise.all([
instance.get(`/search/movie`, {
params: {
query: query,
include_adult: true,
},
}),
instance.get(`/search/tv`, {
params: {
query: query,
include_adult: true,
},
}),
])
if (response.status !== 200) {
const movieData = movieSearch.data
const tvData = tvSearch.data
if (movieSearch.status !== 200 || tvSearch.status !== 200) {
return {
Results: [],
Page: 0,
totalResults: 0,
totalPages: 0,
ErrorMessage: response.data.Error,
ErrorMessage: movieSearch.data.Error || tvSearch.data.Error,
}
}
const filtered = response.data.results.filter((result: { media_type: string }) => {
return result.media_type === 'movie' || result.media_type === 'tv'
const filteredMovies = movieData.results.map((result: { media_type: string }) => {
return { ...result, media_type: 'movie' }
})
const filteredTV = tvData.results.map((result: { media_type: string }) => {
return { ...result, media_type: 'tv' }
})
const data: MediaResponseType = {
Results: filtered.map(mapMedia),
Page: response.data.page,
totalResults: response.data.total_results,
totalPages: response.data.total_pages,
Results: [...filteredMovies.map(mapMedia), ...filteredTV.map(mapMedia)],
Page: Math.max(movieData.page, tvData.page),
totalResults: movieData.total_results + tvData.total_results,
totalPages: Math.max(movieData.total_pages, tvData.total_pages),
ErrorMessage: '',
}

0
src/main.ts Normal file → Executable file
View File

0
src/router/index.ts Normal file → Executable file
View File

0
src/stores/media.ts Normal file → Executable file
View File

0
src/style.css Normal file → Executable file
View File

0
src/types/Media.ts Normal file → Executable file
View File

0
src/types/MediaMap.ts Normal file → Executable file
View File

0
src/types/Movie.ts Normal file → Executable file
View File

0
src/types/MovieMap.ts Normal file → Executable file
View File

0
src/types/TvSeries.ts Normal file → Executable file
View File

0
src/types/TvSeriesMap.ts Normal file → Executable file
View File

0
src/views/AddView.vue Normal file → Executable file
View File

0
src/views/DetailsView.vue Normal file → Executable file
View File

0
src/views/HomeView.vue Normal file → Executable file
View File

0
src/views/ListView.vue Normal file → Executable file
View File

0
src/views/NotFoundView.vue Normal file → Executable file
View File

0
src/views/WatchView.vue Normal file → Executable file
View File

0
tsconfig.app.json Normal file → Executable file
View File

0
tsconfig.json Normal file → Executable file
View File

0
tsconfig.node.json Normal file → Executable file
View File

0
vite.config.ts Normal file → Executable file
View File