mirror of
https://github.com/jakejarvis/sofa.git
synced 2026-08-29 05:05:38 -04:00
Introduce a local disk cache for TMDB images served through a proxy API route (/api/images/[...path]), eliminating direct client-side CDN dependencies. Images are cached by category (posters, backdrops, stills, logos) and served with immutable cache headers. Move all tmdbImageUrl() calls from client components to API routes and server components so clients receive ready-to-use URLs. This removes the need to expose TMDB_IMAGE_BASE_URL and IMAGE_CACHE_ENABLED via next.config.ts env block. The landing page is split into a server wrapper (app/page.tsx) and client component (components/landing-page.tsx). Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
50 lines
1.4 KiB
TypeScript
50 lines
1.4 KiB
TypeScript
import { type NextRequest, NextResponse } from "next/server";
|
|
import { isTmdbConfigured } from "@/lib/config";
|
|
import { discover } from "@/lib/tmdb/client";
|
|
import { tmdbImageUrl } from "@/lib/tmdb/image";
|
|
|
|
export async function GET(req: NextRequest) {
|
|
if (!isTmdbConfigured()) {
|
|
return NextResponse.json(
|
|
{
|
|
error: "TMDB API key is not configured. Visit /setup for instructions.",
|
|
code: "TMDB_NOT_CONFIGURED",
|
|
},
|
|
{ status: 503 },
|
|
);
|
|
}
|
|
|
|
const { searchParams } = req.nextUrl;
|
|
const type = searchParams.get("type") === "tv" ? "tv" : "movie";
|
|
const genre = searchParams.get("genre");
|
|
const sortBy = searchParams.get("sort_by") || "popularity.desc";
|
|
const page = searchParams.get("page") || "1";
|
|
|
|
const params: Record<string, string> = {
|
|
sort_by: sortBy,
|
|
"vote_count.gte": "50",
|
|
};
|
|
if (genre) {
|
|
params.with_genres = genre;
|
|
}
|
|
|
|
const results = await discover(type, params, Number(page));
|
|
|
|
const filtered = results.results.filter((r) => r.poster_path);
|
|
|
|
return NextResponse.json({
|
|
results: filtered.map((r) => ({
|
|
tmdbId: r.id,
|
|
type,
|
|
title: r.title ?? r.name,
|
|
overview: r.overview,
|
|
releaseDate: r.release_date ?? r.first_air_date,
|
|
posterPath: tmdbImageUrl(r.poster_path, "w500"),
|
|
popularity: r.popularity,
|
|
voteAverage: r.vote_average,
|
|
})),
|
|
page: results.page,
|
|
totalPages: results.total_pages,
|
|
});
|
|
}
|