refactor: 移除本地配置缓存并清理环境变量

移除config-local.ts中的缓存逻辑,简化配置读取流程
删除web/.env中不再需要的ALLOWED_USER_IDS变量
更新.gitignore以忽略上传脚本文件
This commit is contained in:
hex2077
2025-08-27 20:17:53 +08:00
parent 82f9a51ef2
commit 4c46677c19
4 changed files with 2215 additions and 2251 deletions

3
.gitignore vendored
View File

@@ -6,4 +6,5 @@ config/tts_providers-local.json
config/tts_providers-prod.json config/tts_providers-prod.json
.claude .claude
.serena .serena
/node_modules /node_modules
server/ext/upload_edge_tts_to_cloudflare.py

File diff suppressed because it is too large Load Diff

View File

@@ -11,7 +11,6 @@ NEXT_PUBLIC_ENABLE_TTS_CONFIG_PAGE=true
POINTS_PER_PODCAST=20 POINTS_PER_PODCAST=20
POINTS_PER_PODCAST_INIT=100 POINTS_PER_PODCAST_INIT=100
POINTS_PER_SIGN_IN=40 POINTS_PER_SIGN_IN=40
ALLOWED_USER_IDS="123456890"
TTS_PROVIDERS_NAME="tts_providers.json" TTS_PROVIDERS_NAME="tts_providers.json"
DB_FILE_NAME="file:sqlite.db" DB_FILE_NAME="file:sqlite.db"

View File

@@ -2,21 +2,9 @@
import path from 'path'; import path from 'path';
import fs from 'fs/promises'; import fs from 'fs/promises';
// 定义缓存变量和缓存过期时间
let ttsProvidersCache: any = null;
let cacheTimestamp: number = 0;
const CACHE_DURATION = 30 * 60 * 1000; // 30分钟单位毫秒
// 获取 tts_providers.json 文件内容 // 获取 tts_providers.json 文件内容
export async function fetchAndCacheProvidersLocal(lang: string) { export async function fetchAndCacheProvidersLocal(lang: string) {
try { 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; const ttsProvidersName = process.env.TTS_PROVIDERS_NAME;
@@ -27,12 +15,12 @@ export async function fetchAndCacheProvidersLocal(lang: string) {
const configContent = await fs.readFile(configPath, 'utf-8'); const configContent = await fs.readFile(configPath, 'utf-8');
const config = JSON.parse(configContent); const config = JSON.parse(configContent);
// 更新缓存 if(!config) {
ttsProvidersCache = config; console.log('Error reading tts_providers.json, Empty')
cacheTimestamp = now; return null
console.log('重新加载并缓存 tts_providers.json 数据'); }
return ttsProvidersCache return config
} catch (error) { } catch (error) {
console.error('Error reading tts_providers.json:', error); console.error('Error reading tts_providers.json:', error);
return null return null