完善tmdb反代

This commit is contained in:
mtvpls
2026-01-17 21:18:19 +08:00
parent 531187b5a4
commit 6a976dd91c
18 changed files with 97 additions and 48 deletions

View File

@@ -240,6 +240,7 @@ export async function POST(request: NextRequest) {
// TMDB 配置
tmdbApiKey: adminConfig.SiteConfig.TMDBApiKey,
tmdbProxy: adminConfig.SiteConfig.TMDBProxy,
tmdbReverseProxy: adminConfig.SiteConfig.TMDBReverseProxy,
// 决策模型配置固定使用自定义provider复用主模型的API配置
enableDecisionModel: aiConfig.EnableDecisionModel,
decisionProvider: 'custom',

View File

@@ -179,7 +179,8 @@ export async function GET(request: NextRequest) {
client,
metadataPath,
config.SiteConfig.TMDBApiKey,
config.SiteConfig.TMDBProxy
config.SiteConfig.TMDBProxy,
config.SiteConfig.TMDBReverseProxy
);
// 获取集数列表(使用目录路径或点击的文件路径)

View File

@@ -32,6 +32,7 @@ export async function GET(request: NextRequest) {
const config = await getConfig();
const tmdbApiKey = config.SiteConfig.TMDBApiKey;
const tmdbProxy = config.SiteConfig.TMDBProxy;
const tmdbReverseProxy = config.SiteConfig.TMDBReverseProxy;
const actualKey = getNextApiKey(tmdbApiKey || '');
if (!actualKey) {
@@ -41,9 +42,11 @@ export async function GET(request: NextRequest) {
);
}
// 使用反代代理或默认 Base URL
const baseUrl = tmdbReverseProxy || 'https://api.themoviedb.org';
// 根据类型选择API端点
const endpoint = type === 'movie' ? 'movie' : 'tv';
const url = `https://api.themoviedb.org/3/${endpoint}/${id}?api_key=${actualKey}&language=zh-CN&append_to_response=credits`;
const url = `${baseUrl}/3/${endpoint}/${id}?api_key=${actualKey}&language=zh-CN&append_to_response=credits`;
const fetchOptions: any = tmdbProxy
? {

View File

@@ -32,6 +32,7 @@ export async function GET(request: NextRequest) {
const config = await getConfig();
const tmdbApiKey = config.SiteConfig.TMDBApiKey;
const tmdbProxy = config.SiteConfig.TMDBProxy;
const tmdbReverseProxy = config.SiteConfig.TMDBReverseProxy;
if (!tmdbApiKey) {
return NextResponse.json({ error: 'TMDB API Key 未配置' }, { status: 400 });
@@ -42,7 +43,9 @@ export async function GET(request: NextRequest) {
return NextResponse.json({ error: 'TMDB API Key 无效' }, { status: 400 });
}
const url = `https://api.themoviedb.org/3/tv/${id}/season/${season}?api_key=${actualKey}&language=zh-CN`;
// 使用反代代理或默认 Base URL
const baseUrl = tmdbReverseProxy || 'https://api.themoviedb.org';
const url = `${baseUrl}/3/tv/${id}/season/${season}?api_key=${actualKey}&language=zh-CN`;
const fetchOptions: any = tmdbProxy
? {

View File

@@ -31,6 +31,7 @@ export async function GET(request: NextRequest) {
const config = await getConfig();
const tmdbApiKey = config.SiteConfig.TMDBApiKey;
const tmdbProxy = config.SiteConfig.TMDBProxy;
const tmdbReverseProxy = config.SiteConfig.TMDBReverseProxy;
const actualKey = getNextApiKey(tmdbApiKey || '');
if (!actualKey) {
@@ -40,8 +41,10 @@ export async function GET(request: NextRequest) {
);
}
// 使用反代代理或默认 Base URL
const baseUrl = tmdbReverseProxy || 'https://api.themoviedb.org';
// 使用 multi search 同时搜索电影和电视剧
const url = `https://api.themoviedb.org/3/search/multi?api_key=${actualKey}&language=zh-CN&query=${encodeURIComponent(query)}&page=1`;
const url = `${baseUrl}/3/search/multi?api_key=${actualKey}&language=zh-CN&query=${encodeURIComponent(query)}&page=1`;
const fetchOptions: any = tmdbProxy
? {

View File

@@ -34,6 +34,7 @@ export async function GET(request: NextRequest) {
const config = await getConfig();
const tmdbApiKey = config.SiteConfig.TMDBApiKey;
const tmdbProxy = config.SiteConfig.TMDBProxy;
const tmdbReverseProxy = config.SiteConfig.TMDBReverseProxy;
if (!tmdbApiKey) {
return NextResponse.json(
@@ -42,7 +43,7 @@ export async function GET(request: NextRequest) {
);
}
const result = await getTVSeasons(tmdbApiKey, tvId, tmdbProxy);
const result = await getTVSeasons(tmdbApiKey, tvId, tmdbProxy, tmdbReverseProxy);
if (result.code === 200 && result.seasons) {
return NextResponse.json({

View File

@@ -7,6 +7,7 @@ import { CheckCircle, AlertCircle, Plus } from 'lucide-react';
import PageLayout from '@/components/PageLayout';
import { getTMDBImageUrl } from '@/lib/tmdb.client';
import { processImageUrl } from '@/lib/utils';
interface TMDBResult {
id: number;
@@ -117,7 +118,7 @@ export default function MovieRequestPage() {
const submitRequest = async (item: TMDBResult, season?: number) => {
setSubmitting(true);
try {
let poster = item.poster_path ? getTMDBImageUrl(item.poster_path, 'w500') : undefined;
let poster = item.poster_path ? processImageUrl(getTMDBImageUrl(item.poster_path, 'w500')) : undefined;
let title = item.title || item.name || '';
if (season && seasons.length > 0) {
@@ -125,7 +126,7 @@ export default function MovieRequestPage() {
if (seasonData) {
title = `${title} ${seasonData.name}`;
if (seasonData.poster_path) {
poster = getTMDBImageUrl(seasonData.poster_path, 'w500');
poster = processImageUrl(getTMDBImageUrl(seasonData.poster_path, 'w500'));
}
}
}
@@ -311,7 +312,7 @@ export default function MovieRequestPage() {
>
{item.poster_path ? (
<img
src={getTMDBImageUrl(item.poster_path, 'w500')}
src={processImageUrl(getTMDBImageUrl(item.poster_path, 'w500'))}
alt={item.title || item.name}
className='w-full aspect-[2/3] object-cover'
/>

View File

@@ -13,6 +13,7 @@ import {
import { getDoubanCategories } from '@/lib/douban.client';
import { getTMDBImageUrl, TMDBItem } from '@/lib/tmdb.client';
import { DoubanItem } from '@/lib/types';
import { processImageUrl } from '@/lib/utils';
import ContinueWatching from '@/components/ContinueWatching';
import PageLayout from '@/components/PageLayout';
@@ -516,7 +517,7 @@ function HomeClient() {
>
<VideoCard
title={item.title}
poster={getTMDBImageUrl(item.poster_path)}
poster={processImageUrl(getTMDBImageUrl(item.poster_path))}
year={item.release_date?.split('-')?.[0] || ''}
rate={
item.vote_average && item.vote_average > 0

View File

@@ -1020,7 +1020,7 @@ function PlayPageClient() {
if (detCacheAge < detCacheMaxAge && data && data.backdrop) {
console.log('使用缓存的TMDB详情数据');
setTmdbBackdrop(data.backdrop);
setTmdbBackdrop(processImageUrl(data.backdrop));
// 如果没有豆瓣ID使用TMDb数据补充
if (!videoDoubanId || videoDoubanId === 0) {
@@ -1054,7 +1054,7 @@ function PlayPageClient() {
const result = await response.json();
if (result.backdrop) {
setTmdbBackdrop(result.backdrop);
setTmdbBackdrop(processImageUrl(result.backdrop));
// 如果没有豆瓣ID使用TMDb数据补充
if (!videoDoubanId || videoDoubanId === 0) {
@@ -3279,7 +3279,7 @@ function PlayPageClient() {
finalTitle = correction.title;
}
if (correction.posterPath) {
finalCover = getTMDBImageUrl(correction.posterPath);
finalCover = processImageUrl(getTMDBImageUrl(correction.posterPath));
}
if (correction.overview) {
finalDesc = correction.overview;
@@ -4424,7 +4424,7 @@ function PlayPageClient() {
setVideoTitle(correction.title);
}
if (correction.posterPath) {
const fullPosterUrl = getTMDBImageUrl(correction.posterPath);
const fullPosterUrl = processImageUrl(getTMDBImageUrl(correction.posterPath));
setVideoCover(fullPosterUrl);
}
if (correction.overview) {
@@ -7856,7 +7856,7 @@ const applyCorrection = (detail: SearchResult, correction: any): SearchResult =>
return {
...detail,
title: correction.title || detail.title,
poster: correction.posterPath ? getTMDBImageUrl(correction.posterPath) : detail.poster,
poster: correction.posterPath ? processImageUrl(getTMDBImageUrl(correction.posterPath)) : detail.poster,
year: correction.releaseDate || detail.year,
desc: correction.overview || detail.desc,
rating: correction.voteAverage || detail.rating,