This commit is contained in:
ponzischeme89
2026-08-12 08:25:15 +12:00
parent e30962245e
commit 4b31946635
28 changed files with 439 additions and 130 deletions
+22
View File
@@ -23,6 +23,7 @@ type requestCandidate struct {
Overview string `json:"overview"`
PosterURL string `json:"posterUrl,omitempty"`
AlreadyAdded bool `json:"alreadyAdded"`
InLibrary bool `json:"inLibrary"`
}
type requestLookupResponse struct {
@@ -99,6 +100,27 @@ func (s *Server) handleRequestLookup(w http.ResponseWriter, r *http.Request, ses
}
wg.Wait()
candidates := append(movieCandidates, seriesCandidates...)
movieIDs, seriesIDs := []int{}, []int{}
for _, candidate := range candidates {
if candidate.MediaType == "movie" {
movieIDs = append(movieIDs, candidate.ForeignID)
} else {
seriesIDs = append(seriesIDs, candidate.ForeignID)
}
}
moviesInLibrary, movieErr := s.store.LibraryContainsProviderIDs(r.Context(), "Tmdb", movieIDs)
seriesInLibrary, seriesErr := s.store.LibraryContainsProviderIDs(r.Context(), "Tvdb", seriesIDs)
if movieErr != nil || seriesErr != nil {
s.loggerFor(r.Context()).Warn("request library status unavailable",
"movie_error", movieErr, "series_error", seriesErr)
}
for index := range candidates {
if candidates[index].MediaType == "movie" {
candidates[index].InLibrary = moviesInLibrary[candidates[index].ForeignID]
} else {
candidates[index].InLibrary = seriesInLibrary[candidates[index].ForeignID]
}
}
sort.SliceStable(candidates, func(i, j int) bool {
return requestMatchScore(term, candidates[i].Title) < requestMatchScore(term, candidates[j].Title)
})