refactor: 移除本地配置缓存并清理环境变量
移除config-local.ts中的缓存逻辑,简化配置读取流程 删除web/.env中不再需要的ALLOWED_USER_IDS变量 更新.gitignore以忽略上传脚本文件
This commit is contained in:
3
.gitignore
vendored
3
.gitignore
vendored
@@ -6,4 +6,5 @@ config/tts_providers-local.json
|
||||
config/tts_providers-prod.json
|
||||
.claude
|
||||
.serena
|
||||
/node_modules
|
||||
/node_modules
|
||||
server/ext/upload_edge_tts_to_cloudflare.py
|
||||
4440
config/edge-tts.json
4440
config/edge-tts.json
File diff suppressed because it is too large
Load Diff
1
web/.env
1
web/.env
@@ -11,7 +11,6 @@ NEXT_PUBLIC_ENABLE_TTS_CONFIG_PAGE=true
|
||||
POINTS_PER_PODCAST=20
|
||||
POINTS_PER_PODCAST_INIT=100
|
||||
POINTS_PER_SIGN_IN=40
|
||||
ALLOWED_USER_IDS="123456890"
|
||||
|
||||
TTS_PROVIDERS_NAME="tts_providers.json"
|
||||
DB_FILE_NAME="file:sqlite.db"
|
||||
|
||||
@@ -2,21 +2,9 @@
|
||||
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;
|
||||
@@ -27,12 +15,12 @@ export async function fetchAndCacheProvidersLocal(lang: string) {
|
||||
const configContent = await fs.readFile(configPath, 'utf-8');
|
||||
const config = JSON.parse(configContent);
|
||||
|
||||
// 更新缓存
|
||||
ttsProvidersCache = config;
|
||||
cacheTimestamp = now;
|
||||
console.log('重新加载并缓存 tts_providers.json 数据');
|
||||
if(!config) {
|
||||
console.log('Error reading tts_providers.json, Empty')
|
||||
return null
|
||||
}
|
||||
|
||||
return ttsProvidersCache
|
||||
return config
|
||||
} catch (error) {
|
||||
console.error('Error reading tts_providers.json:', error);
|
||||
return null
|
||||
|
||||
Reference in New Issue
Block a user