import { AiOutlineArrowLeft, AiOutlineCloudDownload } from 'react-icons/ai'; import { getAudioInfo, getUserInfo } from '@/lib/podcastApi'; import AudioPlayerControls from './AudioPlayerControls'; import PodcastTabs from './PodcastTabs'; import ShareButton from './ShareButton'; // 导入 ShareButton 组件 import { getTranslation } from '../i18n'; // 从正确路径导入 useTranslation import { headers } from 'next/headers'; // 导入 usePathname import { getTruePathFromHeaders } from '../lib/utils'; // 导入新函数 // 脚本解析函数 (与 page.tsx 中保持一致) const parseTranscript = ( transcript: { speaker_id: number; dialog: string }[] | undefined, podUsers: { role: string; code: string; name: string; usedname: string }[] | undefined, t: (key: string, options?: any) => string // 传递 t 函数 ) => { if (!transcript) return []; return transcript.map((item, index) => { let speakerName: string | null = null; if (podUsers && podUsers[item.speaker_id]) { speakerName = podUsers[item.speaker_id].usedname; // 使用 podUsers 中的 usedname 字段作为 speakerName } else { speakerName = `${t('podcastContent.speaker')} ${item.speaker_id}`; // 回退到 Speaker ID } return { id: index, speaker: speakerName, dialogue: item.dialog }; }); }; interface PodcastContentProps { fileName: string; lang: string; // 新增 lang 属性 } export default async function PodcastContent({ fileName, lang }: PodcastContentProps) { const { t } = await getTranslation(lang, 'components'); // 初始化 getTranslation const result = await getAudioInfo(fileName, lang); const truePath = await getTruePathFromHeaders(await headers(), lang); if (!result.success || !result.data || result.data.status!='completed') { return (

{t('podcastContent.cannotLoadPodcastDetails')}{result.error || t('podcastContent.unknownError')}

{t('podcastContent.returnToHomepage')}
); } const authId = result.data?.auth_id; // 确保 auth_id 存在且安全访问 let userInfoData = null; if (authId) { const userInfo = await getUserInfo(authId, lang); if (userInfo.success && userInfo.data) { userInfoData = { name: userInfo.data.name, email: userInfo.data.email, image: userInfo.data.image, }; } } const responseData = { ...result.data, user: userInfoData // 将用户信息作为嵌套对象添加 }; const audioInfo = responseData; const parsedScript = parseTranscript(audioInfo.podcast_script?.podcast_transcripts || [], audioInfo.podUsers, t); // 传递 t 函数 return (
{/* 返回首页按钮和分享按钮 */}
{/* 修改为 justify-between 和 items-center */} {t('podcastContent.returnToHomepage')}
{/* 使用 flex 容器包裹分享和下载按钮 */} {/* 添加分享按钮 */} {audioInfo.audioUrl && ( )}
{/* 1. 顶部信息区 */}
{/* 缩略图 */}
{audioInfo.avatar_base64 && ( Podcast Thumbnail )}
{/* 标题 */}

{audioInfo.title}

{/* 标签 */} {audioInfo.tags && audioInfo.tags.split('#').map((tag: string) => tag.trim()).filter((tag: string) => !!tag).length > 0 && (
{audioInfo.tags.split('#').filter((tag: string) => !!tag).map((tag: string) => ( {tag.trim()} ))}
)} {/* 元数据栏 */}
{audioInfo.user?.name
{audioInfo.user?.name}
{/* 2. 播放控制区 - 使用客户端组件 */} {/* 3. 内容导航区和内容展示区 - 使用客户端组件 */}
); }