22301009 | 5b28c67 | 2025-04-10 20:12:45 +0800 | [diff] [blame^] | 1 | import React, { useEffect, useState } from 'react'; |
| 2 | import axios from 'axios'; |
| 3 | import { useParams } from 'react-router-dom'; |
| 4 | import Header from '../../../components/Header'; |
| 5 | import './SeedDetail.css'; |
| 6 | |
| 7 | const API_BASE = process.env.REACT_APP_API_BASE; |
| 8 | |
| 9 | const SeedDetail = () => { |
| 10 | const { seed_id } = useParams(); |
| 11 | const [seed, setSeed] = useState(null); |
| 12 | const [error, setError] = useState(null); |
| 13 | |
| 14 | useEffect(() => { |
| 15 | axios |
| 16 | .get(`${API_BASE}/echo/seeds/${seed_id}`) |
| 17 | .then((res) => { |
| 18 | if (res.data.status === 'success') { |
| 19 | setSeed(res.data.seed); |
| 20 | } else { |
| 21 | setError('未能获取种子信息'); |
| 22 | } |
| 23 | }) |
| 24 | .catch(() => { |
| 25 | setError('获取种子详情失败'); |
| 26 | }); |
| 27 | }, [seed_id]); |
| 28 | |
| 29 | if (error) { |
| 30 | return ( |
| 31 | <div> |
| 32 | <Header /> |
| 33 | <div className="seed-detail-container"> |
| 34 | <p className="error">{error}</p> |
| 35 | </div> |
| 36 | </div> |
| 37 | ); |
| 38 | } |
| 39 | |
| 40 | if (!seed) { |
| 41 | return ( |
| 42 | <div> |
| 43 | <Header /> |
| 44 | <div className="seed-detail-container"> |
| 45 | <p>加载中...</p> |
| 46 | </div> |
| 47 | </div> |
| 48 | ); |
| 49 | } |
| 50 | |
| 51 | return ( |
| 52 | <div> |
| 53 | <Header /> |
| 54 | <div className="seed-detail-container"> |
| 55 | <div className="seed-header"> |
| 56 | <img src={seed.cover_url} alt={seed.title} className="cover-image" /> |
| 57 | <div className="seed-basic-info"> |
| 58 | <h1>{seed.title}</h1> |
| 59 | <p><strong>分类:</strong>{seed.category}</p> |
| 60 | <p><strong>标签:</strong>{seed.tags.join(' / ')}</p> |
| 61 | <p><strong>简介:</strong>{seed.description}</p> |
| 62 | <p><strong>大小:</strong>{seed.size} GB</p> |
| 63 | <p><strong>分辨率:</strong>{seed.resolution}</p> |
| 64 | <p><strong>片长:</strong>{seed.duration}</p> |
| 65 | <p><strong>地区:</strong>{seed.region}</p> |
| 66 | <p><strong>发布时间:</strong>{new Date(seed.upload_time).toLocaleString()}</p> |
| 67 | <p><strong>下载次数:</strong>{seed.downloads}</p> |
| 68 | </div> |
| 69 | </div> |
| 70 | |
| 71 | {(seed.category === '电影' || seed.category === '电视剧') && ( |
| 72 | <div className="seed-media-info"> |
| 73 | <p><strong>导演:</strong>{seed.director}</p> |
| 74 | <p><strong>编剧:</strong>{seed.writer}</p> |
| 75 | <p><strong>主演:</strong>{seed.actors.join(' / ')}</p> |
| 76 | </div> |
| 77 | )} |
| 78 | |
| 79 | <div className="uploader-info"> |
| 80 | <h3>发种人</h3> |
| 81 | <img src={seed.user.avatar_url} alt={seed.user.username} className="avatar" /> |
| 82 | <p>{seed.user.username}</p> |
| 83 | </div> |
| 84 | </div> |
| 85 | </div> |
| 86 | ); |
| 87 | }; |
| 88 | |
| 89 | export default SeedDetail; |