Files
sofa/lib/actions/explore.ts
T
jake ad8ec62317 Refactor tmdbImageUrl to accept semantic category instead of size string
- Change primary argument from TMDB size string (`w500`, `w1280`, etc.)
  to category name (`posters`, `backdrops`, `stills`, `logos`,
  `profiles`); optional size override remains as third argument
- Update all call sites across services, actions, pages, and route
  handlers to use the new category-based API
- Update image.test.ts to match the new signature and replace
  size-mapping test descriptions with category-name descriptions
2026-03-08 12:33:07 -04:00

30 lines
796 B
TypeScript

"use server";
import { requireSession } from "@/lib/auth/session";
import { discover } from "@/lib/tmdb/client";
import { tmdbImageUrl } from "@/lib/tmdb/image";
export async function discoverByGenre(
mediaType: "movie" | "tv",
genreId: number,
) {
await requireSession();
const results = await discover(mediaType, {
sort_by: "popularity.desc",
"vote_count.gte": "50",
with_genres: String(genreId),
});
return results.results
.filter((r) => r.poster_path)
.map((r) => ({
tmdbId: r.id,
type: mediaType,
title: (r.title ?? r.name) as string,
posterPath: tmdbImageUrl(r.poster_path, "posters"),
releaseDate: (r.release_date ?? r.first_air_date ?? null) as
| string
| null,
voteAverage: r.vote_average,
}));
}