feat(torrents): Toloka section filter by show type, year scope for movies only

This commit is contained in:
ner committed 2026-09-13 19:14:42 +03:00
1 parent c52d798221
commit f642dad64e
5 files changed
+56 -13

No files matched your search

@@ -1,9 +1,11 @@
import { Sort } from '@/data/parsers';
type Options = { query: string; sort: Sort; imdbID: string };
type Options = { query: string; sort: Sort; imdbID: string; type?: 'movie' | 'tv' };
const queryFn = ({ query, sort, imdbID, key }: Options & { key: keyof typeof providers }) =>
fetch(`/api/torrents?key=${key}&query=${query}&sort=${sort}&imdbID=${imdbID}`).then((response) => response.json());
const queryFn = ({ query, sort, imdbID, type, key }: Options & { key: keyof typeof providers }) =>
fetch(`/api/torrents?key=${key}&query=${query}&sort=${sort}&imdbID=${imdbID}&type=${type ?? ''}`).then((response) =>
response.json()
);
export const providers = {
yts: {
@@ -52,9 +52,10 @@ const showTorrentsModal = create(({ onResolve, ...show }: Props) => {
const isSeries = show.type === 'tv';
// Toloka's search is a plain "contains" word-AND match with no IMDB filter, so
// scope the query by the show's year to keep, e.g., "Dune" (2021) away from "Dune: Part Two" (2024).
const tolokaQuery = query && Number.isFinite(year) ? `${query} ${year}` : query;
// Toloka's search is a plain "contains" word-AND match with no IMDB filter. For movies,
// scope the query by the show's year to keep, e.g., "Dune" (2021) away from "Dune: Part Two" (2024);
// for series the TV sections do the disambiguation and a year suffix would hide other seasons.
const tolokaQuery = isSeries ? query : query && Number.isFinite(year) ? `${query} ${year}` : query;
const tracked = { id: show.id, type: show.type, title: show.title };
@@ -64,6 +65,7 @@ const showTorrentsModal = create(({ onResolve, ...show }: Props) => {
sort,
key: providers.yts.key,
imdbID: show.imdb_id!,
type: show.type,
show: tracked
});
const tpb = useTorrents({
@@ -72,6 +74,7 @@ const showTorrentsModal = create(({ onResolve, ...show }: Props) => {
sort,
key: providers.tpb.key,
imdbID: show.imdb_id!,
type: show.type,
show: tracked
});
const tlk = useTorrents({
@@ -80,6 +83,7 @@ const showTorrentsModal = create(({ onResolve, ...show }: Props) => {
sort,
key: providers.tlk.key,
imdbID: show.imdb_id!,
type: show.type,
show: tracked
});
@@ -8,6 +8,7 @@ const useTorrents = ({
query,
sort,
imdbID,
type,
key,
queryFn,
show
@@ -16,13 +17,14 @@ const useTorrents = ({
query: string;
sort: Sort;
imdbID: string;
type?: Show['type'];
show: { id: Show['id']; type: Show['type']; title: Show['title'] };
queryFn: (params: { query: string; sort: Sort; imdbID: string }) => Promise<Torrent[]>;
queryFn: (params: { query: string; sort: Sort; imdbID: string; type?: Show['type'] }) => Promise<Torrent[]>;
}) => {
const result = useQuery({
enabled: Boolean(query),
queryKey: [key, query, sort, imdbID],
queryFn: () => queryFn({ query, sort, imdbID })
queryKey: [key, query, sort, imdbID, type],
queryFn: () => queryFn({ query, sort, imdbID, type })
});
useTrackOnce(analytics.torrentsSearched, result.data ? `${key}:${query}` : undefined, () => ({