Files
Podcast-Generator/web/src/lib/config-local.ts
hex2077 0b00a3b0ae feat(i18n): 添加多语言支持并重构相关组件
实现国际化(i18n)支持,包括:
1. 新增i18n配置文件和中间件
2. 重构页面和组件以支持多语言
3. 添加中英日三语翻译文件
4. 修改API路由以支持语言参数
5. 更新README文档说明i18n功能
6. 添加语言切换组件
7. 调整布局和路由结构支持多语言路径
2025-08-25 00:46:32 +08:00

40 lines
1.3 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
'use server'
import path from 'path';
import fs from 'fs/promises';
// 定义缓存变量和缓存过期时间
let ttsProvidersCache: any = null;
let cacheTimestamp: number = 0;
const CACHE_DURATION = 30 * 60 * 1000; // 30分钟单位毫秒
// 获取 tts_providers.json 文件内容
export async function fetchAndCacheProvidersLocal(lang: string) {
try {
const now = Date.now();
// 检查缓存是否有效
if (ttsProvidersCache && (now - cacheTimestamp < CACHE_DURATION)) {
console.log('从缓存中返回 tts_providers.json 数据');
return ttsProvidersCache
}
// 缓存无效或不存在,读取文件并更新缓存
const ttsProvidersName = process.env.TTS_PROVIDERS_NAME;
if (!ttsProvidersName) {
throw new Error('TTS_PROVIDERS_NAME 环境变量未设置');
}
const configPath = path.join(process.cwd(), '..', 'config', ttsProvidersName);
const configContent = await fs.readFile(configPath, 'utf-8');
const config = JSON.parse(configContent);
// 更新缓存
ttsProvidersCache = config;
cacheTimestamp = now;
console.log('重新加载并缓存 tts_providers.json 数据');
return ttsProvidersCache
} catch (error) {
console.error('Error reading tts_providers.json:', error);
return null
}
}