feat: 添加每日签到功能和sitemap生成
refactor: 优化TTS配置获取逻辑并提取为独立模块 fix: 修正新用户积分初始化环境变量名称 style: 更新播客生成页面UI和文案 docs: 修改提示词模板格式和内容 build: 添加next-sitemap依赖和配置文件
This commit is contained in:
40
web/src/lib/config-local.ts
Normal file
40
web/src/lib/config-local.ts
Normal file
@@ -0,0 +1,40 @@
|
||||
'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() {
|
||||
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
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user