feat: add global douban proxy config

This commit is contained in:
shinya
2025-07-26 15:39:29 +08:00
parent 090d10e4bb
commit 3de3bd2f39
8 changed files with 155 additions and 17 deletions

View File

@@ -5,6 +5,7 @@ export interface AdminConfig {
SearchDownstreamMaxPage: number;
SiteInterfaceCacheTime: number;
ImageProxy: string;
DoubanProxy: string;
};
UserConfig: {
AllowRegister: boolean;

View File

@@ -159,6 +159,7 @@ async function initConfig() {
Number(process.env.NEXT_PUBLIC_SEARCH_MAX_PAGE) || 5,
SiteInterfaceCacheTime: fileConfig.cache_time || 7200,
ImageProxy: process.env.NEXT_PUBLIC_IMAGE_PROXY || '',
DoubanProxy: process.env.NEXT_PUBLIC_DOUBAN_PROXY || '',
},
UserConfig: {
AllowRegister: process.env.NEXT_PUBLIC_ENABLE_REGISTER === 'true',
@@ -197,6 +198,7 @@ async function initConfig() {
Number(process.env.NEXT_PUBLIC_SEARCH_MAX_PAGE) || 5,
SiteInterfaceCacheTime: fileConfig.cache_time || 7200,
ImageProxy: process.env.NEXT_PUBLIC_IMAGE_PROXY || '',
DoubanProxy: process.env.NEXT_PUBLIC_DOUBAN_PROXY || '',
},
UserConfig: {
AllowRegister: process.env.NEXT_PUBLIC_ENABLE_REGISTER === 'true',
@@ -341,6 +343,7 @@ export async function resetConfig() {
Number(process.env.NEXT_PUBLIC_SEARCH_MAX_PAGE) || 5,
SiteInterfaceCacheTime: fileConfig.cache_time || 7200,
ImageProxy: process.env.NEXT_PUBLIC_IMAGE_PROXY || '',
DoubanProxy: process.env.NEXT_PUBLIC_DOUBAN_PROXY || '',
},
UserConfig: {
AllowRegister: process.env.NEXT_PUBLIC_ENABLE_REGISTER === 'true',

View File

@@ -1,4 +1,5 @@
import { DoubanItem, DoubanResult } from './types';
import { getDoubanProxyUrl } from './utils';
interface DoubanCategoriesParams {
kind: 'tv' | 'movie';
@@ -60,16 +61,6 @@ async function fetchWithTimeout(
}
}
/**
* 获取豆瓣代理 URL 设置
*/
export function getDoubanProxyUrl(): string | null {
if (typeof window === 'undefined') return null;
const doubanProxyUrl = localStorage.getItem('doubanProxyUrl');
return doubanProxyUrl && doubanProxyUrl.trim() ? doubanProxyUrl.trim() : null;
}
/**
* 检查是否应该使用客户端获取豆瓣数据
*/

View File

@@ -40,6 +40,44 @@ export function processImageUrl(originalUrl: string): string {
return `${proxyUrl}${encodeURIComponent(originalUrl)}`;
}
/**
* 获取豆瓣代理 URL 设置
*/
export function getDoubanProxyUrl(): string | null {
if (typeof window === 'undefined') return null;
// 本地未开启豆瓣代理,则不使用代理
const enableDoubanProxy = localStorage.getItem('enableDoubanProxy');
if (enableDoubanProxy !== null) {
if (!JSON.parse(enableDoubanProxy) as boolean) {
return null;
}
}
const localDoubanProxy = localStorage.getItem('doubanProxyUrl');
if (localDoubanProxy != null) {
return localDoubanProxy.trim() ? localDoubanProxy.trim() : null;
}
// 如果未设置,则使用全局对象
const serverDoubanProxy = (window as any).RUNTIME_CONFIG?.DOUBAN_PROXY;
return serverDoubanProxy && serverDoubanProxy.trim()
? serverDoubanProxy.trim()
: null;
}
/**
* 处理豆瓣 URL如果设置了豆瓣代理则使用代理
*/
export function processDoubanUrl(originalUrl: string): string {
if (!originalUrl) return originalUrl;
const proxyUrl = getDoubanProxyUrl();
if (!proxyUrl) return originalUrl;
return `${proxyUrl}${encodeURIComponent(originalUrl)}`;
}
export function cleanHtmlTags(text: string): string {
if (!text) return '';
return text