From 4c5c8dc41b13e269f5ab4bd09580a070db040506 Mon Sep 17 00:00:00 2001 From: hex2077 Date: Wed, 27 Aug 2025 14:01:27 +0800 Subject: [PATCH] =?UTF-8?q?refactor:=20=E7=A7=BB=E9=99=A4=E8=AE=BE?= =?UTF-8?q?=E7=BD=AE=E9=AA=8C=E8=AF=81=E5=B9=B6=E6=B8=85=E7=90=86TTS?= =?UTF-8?q?=E6=8F=90=E4=BE=9B=E8=80=85=E9=85=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 移除主页中的API密钥和模型验证检查,简化设置表单类型定义 清理TTS提供者接口返回的敏感信息,用占位符替换实际值 --- web/src/app/[lang]/page.tsx | 6 ----- web/src/app/api/audio-example/route.ts | 1 + web/src/app/api/generate-podcast/route.ts | 2 +- web/src/app/api/tts-providers/route.ts | 15 +++++++++++- web/src/components/SettingsForm.tsx | 28 +---------------------- 5 files changed, 17 insertions(+), 35 deletions(-) diff --git a/web/src/app/[lang]/page.tsx b/web/src/app/[lang]/page.tsx index 7314d12..94e8afd 100644 --- a/web/src/app/[lang]/page.tsx +++ b/web/src/app/[lang]/page.tsx @@ -170,12 +170,6 @@ export default function HomePage({ params }: { params: Promise<{ lang: string }> try { // info('开始生成播客', '正在处理您的请求...'); - - if (!settings || !settings.apikey || !settings.model) { - error(t('configErrorTitle'), t('configErrorMessage')); - setIsGenerating(false); - return; - } // 直接发送JSON格式的请求体 const response = await fetch('/api/generate-podcast', { diff --git a/web/src/app/api/audio-example/route.ts b/web/src/app/api/audio-example/route.ts index ca52373..b7e0be0 100644 --- a/web/src/app/api/audio-example/route.ts +++ b/web/src/app/api/audio-example/route.ts @@ -3,6 +3,7 @@ import { getLanguageFromRequest } from '@/lib/utils'; import { getTranslation } from '@/i18n'; import { fetchAndCacheProvidersLocal } from '@/lib/config-local'; +//线上专用 export async function GET(request: NextRequest) { const lang = getLanguageFromRequest(request); const { t } = await getTranslation(lang, 'errors'); diff --git a/web/src/app/api/generate-podcast/route.ts b/web/src/app/api/generate-podcast/route.ts index e2bf0e6..4283aaa 100644 --- a/web/src/app/api/generate-podcast/route.ts +++ b/web/src/app/api/generate-podcast/route.ts @@ -3,7 +3,7 @@ import { startPodcastGenerationTask } from '@/lib/podcastApi'; import type { PodcastGenerationRequest } from '@/types'; // 导入 SettingsFormData import { getSessionData } from '@/lib/server-actions'; import { getUserPoints } from '@/lib/points'; // 导入 getUserPoints -import { fetchAndCacheProvidersLocal } from '@/lib/config-local'; // 导入 getTTSProviders +import { fetchAndCacheProvidersLocal } from '@/lib/config-local'; import { getTranslation } from '@/i18n'; import { getLanguageFromRequest } from '@/lib/utils'; diff --git a/web/src/app/api/tts-providers/route.ts b/web/src/app/api/tts-providers/route.ts index 9e6ebab..c9d2f06 100644 --- a/web/src/app/api/tts-providers/route.ts +++ b/web/src/app/api/tts-providers/route.ts @@ -2,6 +2,7 @@ import { NextRequest, NextResponse } from 'next/server'; import { fetchAndCacheProvidersLocal } from '@/lib/config-local'; import { getTranslation } from '@/i18n'; import { getLanguageFromRequest } from '@/lib/utils'; +import type { SettingsFormData } from '@/types'; // 获取 tts_providers.json 文件内容 @@ -10,7 +11,7 @@ export async function GET(request: NextRequest) { const { t } = await getTranslation(lang, 'errors'); try { - const config = await fetchAndCacheProvidersLocal(lang); + const config = await fetchAndCacheProvidersLocal(lang) as SettingsFormData; console.log('重新加载并缓存 tts_providers.json 数据'); if (!config) { return NextResponse.json( @@ -19,6 +20,18 @@ export async function GET(request: NextRequest) { ); } + config.apikey = ""; + config.baseurl = ""; + config.model = ""; + config.index.api_url = !!config.index.api_url ? "1" : ""; + config.edge.api_url = !!config.edge.api_url ? "1" : ""; + config.doubao['X-Api-App-Id'] = !!config.doubao['X-Api-App-Id'] ? "1" : ""; + config.doubao['X-Api-Access-Key'] = !!config.doubao['X-Api-Access-Key'] ? "1" : ""; + config.fish.api_key = !!config.fish.api_key ? "1" : ""; + config.minimax.group_id = !!config.minimax.group_id ? "1" : ""; + config.minimax.api_key = !!config.minimax.api_key ? "1" : ""; + config.gemini.api_key = !!config.gemini.api_key ? "1" : ""; + return NextResponse.json({ success: true, data: config, diff --git a/web/src/components/SettingsForm.tsx b/web/src/components/SettingsForm.tsx index b7ebbc3..8d28961 100644 --- a/web/src/components/SettingsForm.tsx +++ b/web/src/components/SettingsForm.tsx @@ -13,37 +13,11 @@ import { } from '@heroicons/react/24/outline'; import { getItem, setItem } from '@/lib/storage'; import { useTranslation } from '../i18n/client'; // 导入 useTranslation +import type { SettingsFormData } from '@/types'; // 存储键名 const SETTINGS_STORAGE_KEY = 'podcast-settings'; -// 设置表单数据类型 -interface SettingsFormData { - apikey: string; - model: string; - baseurl: string; - index: { - api_url: string; - }; - edge: { - api_url: string; - }; - doubao: { - 'X-Api-App-Id': string; - 'X-Api-Access-Key': string; - }; - fish: { - api_key: string; - }; - minimax: { - group_id: string; - api_key: string; - }; - gemini: { - api_key: string; - }; -} - // 模型选项 const MODEL_OPTIONS = [ 'gpt-4-turbo',