mirror of
https://github.com/sct/overseerr.git
synced 2025-09-17 17:24:35 +02:00

* feat(search): search by id This adds the ability to search by ID (starting with TMDb ID). Since there doesn't seem to be way of searching across movies, tv and persons, I have to search through all 3 and use the first one in the order: movie -> tv -> person Searching by ID is triggered using a 'prefix' just like in the *arrs. * fix: missed some refactoring * feat(search): use locale language * feat(search): search using imdb id * feat(search): search using tvdb id * fix: alias type import * fix: missed some refactoring * fix(search): account for id being a string * feat(search): account for movies/tvs/persons with the same id * feat(search): remove non-null assertion Co-authored-by: Ryan Cohen <ryan@sct.dev>
46 lines
1.3 KiB
TypeScript
46 lines
1.3 KiB
TypeScript
import { Router } from 'express';
|
|
import TheMovieDb from '../api/themoviedb';
|
|
import { TmdbSearchMultiResponse } from '../api/themoviedb/interfaces';
|
|
import Media from '../entity/Media';
|
|
import { findSearchProvider } from '../lib/search';
|
|
import { mapSearchResults } from '../models/Search';
|
|
|
|
const searchRoutes = Router();
|
|
|
|
searchRoutes.get('/', async (req, res) => {
|
|
const queryString = req.query.query as string;
|
|
const searchProvider = findSearchProvider(queryString.toLowerCase());
|
|
let results: TmdbSearchMultiResponse;
|
|
|
|
if (searchProvider) {
|
|
const [id] = queryString
|
|
.toLowerCase()
|
|
.match(searchProvider.pattern) as RegExpMatchArray;
|
|
results = await searchProvider.search(
|
|
id,
|
|
req.locale ?? (req.query.language as string)
|
|
);
|
|
} else {
|
|
const tmdb = new TheMovieDb();
|
|
|
|
results = await tmdb.searchMulti({
|
|
query: queryString,
|
|
page: Number(req.query.page),
|
|
language: req.locale ?? (req.query.language as string),
|
|
});
|
|
}
|
|
|
|
const media = await Media.getRelatedMedia(
|
|
results.results.map((result) => result.id)
|
|
);
|
|
|
|
return res.status(200).json({
|
|
page: results.page,
|
|
totalPages: results.total_pages,
|
|
totalResults: results.total_results,
|
|
results: mapSearchResults(results.results, media),
|
|
});
|
|
});
|
|
|
|
export default searchRoutes;
|