修改metainfo为数据库读取,修复tmdb代理连接错误

This commit is contained in:
mtvpls
2025-12-22 20:58:14 +08:00
parent 7ca6379d93
commit 0450edf9bc
13 changed files with 154 additions and 271 deletions
+15 -29
View File
@@ -1,6 +1,7 @@
/* eslint-disable @typescript-eslint/no-explicit-any,no-console */
import { HttpsProxyAgent } from 'https-proxy-agent';
import nodeFetch from 'node-fetch';
export interface TMDBMovie {
id: number;
@@ -45,29 +46,6 @@ interface TMDBTVAiringTodayResponse {
total_results: number;
}
// 代理 agent 缓存,避免每次都创建新实例
const proxyAgentCache = new Map<string, HttpsProxyAgent<string>>();
/**
* 获取或创建代理 agent(复用连接池)
*/
function getProxyAgent(proxy: string): HttpsProxyAgent<string> {
if (!proxyAgentCache.has(proxy)) {
const agent = new HttpsProxyAgent(proxy, {
// 增加超时时间
timeout: 30000, // 30秒
// 保持连接活跃
keepAlive: true,
keepAliveMsecs: 60000, // 60秒
// 最大空闲连接数
maxSockets: 10,
maxFreeSockets: 5,
});
proxyAgentCache.set(proxy, agent);
}
return proxyAgentCache.get(proxy)!;
}
/**
* 获取即将上映的电影
* @param apiKey - TMDB API Key
@@ -90,21 +68,25 @@ export async function getTMDBUpcomingMovies(
const url = `https://api.themoviedb.org/3/movie/upcoming?api_key=${apiKey}&language=zh-CN&page=${page}&region=${region}`;
const fetchOptions: any = proxy
? {
agent: getProxyAgent(proxy),
agent: new HttpsProxyAgent(proxy, {
timeout: 30000,
keepAlive: false,
}),
signal: AbortSignal.timeout(30000),
}
: {
signal: AbortSignal.timeout(15000),
};
const response = await fetch(url, fetchOptions);
// 使用 node-fetch 而不是原生 fetch
const response = await nodeFetch(url, fetchOptions);
if (!response.ok) {
console.error('TMDB API 请求失败:', response.status, response.statusText);
return { code: response.status, list: [] };
}
const data: TMDBUpcomingResponse = await response.json();
const data: TMDBUpcomingResponse = await response.json() as TMDBUpcomingResponse;
return {
code: 200,
@@ -137,21 +119,25 @@ export async function getTMDBUpcomingTVShows(
const url = `https://api.themoviedb.org/3/tv/on_the_air?api_key=${apiKey}&language=zh-CN&page=${page}`;
const fetchOptions: any = proxy
? {
agent: getProxyAgent(proxy),
agent: new HttpsProxyAgent(proxy, {
timeout: 30000,
keepAlive: false,
}),
signal: AbortSignal.timeout(30000),
}
: {
signal: AbortSignal.timeout(15000),
};
const response = await fetch(url, fetchOptions);
// 使用 node-fetch 而不是原生 fetch
const response = await nodeFetch(url, fetchOptions);
if (!response.ok) {
console.error('TMDB TV API 请求失败:', response.status, response.statusText);
return { code: response.status, list: [] };
}
const data: TMDBTVAiringTodayResponse = await response.json();
const data: TMDBTVAiringTodayResponse = await response.json() as TMDBTVAiringTodayResponse;
return {
code: 200,