refactor: 移除设置验证并清理TTS提供者配置

移除主页中的API密钥和模型验证检查,简化设置表单类型定义
清理TTS提供者接口返回的敏感信息,用占位符替换实际值
This commit is contained in:
hex2077
2025-08-27 14:01:27 +08:00
parent ecef7718b9
commit 4c5c8dc41b
5 changed files with 17 additions and 35 deletions

View File

@@ -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', {

View File

@@ -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');

View File

@@ -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';

View File

@@ -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,

View File

@@ -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',