实现播客详情页功能,包括: 1. 新增 PodcastContent 组件展示播客详情 2. 添加 AudioPlayerControls 和 PodcastTabs 组件 3. 实现分享功能组件 ShareButton 4. 优化音频文件命名规则和缓存机制 5. 完善类型定义和 API 接口 6. 调整 UI 布局和响应式设计 7. 修复积分不足状态码问题
45 lines
1.4 KiB
TypeScript
45 lines
1.4 KiB
TypeScript
import { NextRequest, NextResponse } from 'next/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 GET() {
|
||
try {
|
||
const now = Date.now();
|
||
|
||
// 检查缓存是否有效
|
||
if (ttsProvidersCache && (now - cacheTimestamp < CACHE_DURATION)) {
|
||
console.log('从缓存中返回 tts_providers.json 数据');
|
||
return NextResponse.json({
|
||
success: true,
|
||
data: ttsProvidersCache,
|
||
});
|
||
}
|
||
|
||
// 缓存无效或不存在,读取文件并更新缓存
|
||
const configPath = path.join(process.cwd(), '..', 'config', 'tts_providers.json');
|
||
const configContent = await fs.readFile(configPath, 'utf-8');
|
||
const config = JSON.parse(configContent);
|
||
|
||
// 更新缓存
|
||
ttsProvidersCache = config;
|
||
cacheTimestamp = now;
|
||
console.log('重新加载并缓存 tts_providers.json 数据');
|
||
|
||
return NextResponse.json({
|
||
success: true,
|
||
data: config,
|
||
});
|
||
} catch (error) {
|
||
console.error('Error reading tts_providers.json:', error);
|
||
return NextResponse.json(
|
||
{ success: false, error: '无法读取TTS提供商配置文件' },
|
||
{ status: 500 }
|
||
);
|
||
}
|
||
} |