22301009 | ecc1c1c | 2025-04-09 21:56:23 +0800 | [diff] [blame] | 1 | import React, { useState, useEffect } from 'react'; |
22301009 | ecc1c1c | 2025-04-09 21:56:23 +0800 | [diff] [blame] | 2 | import { Link } from 'wouter'; |
22301009 | afbcf4b | 2025-04-10 16:08:39 +0800 | [diff] [blame] | 3 | import axios from 'axios'; |
22301009 | afbcf4b | 2025-04-10 16:08:39 +0800 | [diff] [blame] | 4 | import Recommend from './Recommend/Recommend'; |
22301009 | 1e2aea7 | 2025-06-08 16:35:54 +0800 | [diff] [blame] | 5 | import Header from '../../components/Header'; |
22301009 | ecc1c1c | 2025-04-09 21:56:23 +0800 | [diff] [blame] | 6 | import './SeedList.css'; |
22301009 | 80aaf0d | 2025-06-05 23:20:05 +0800 | [diff] [blame] | 7 | import { useUser } from '../../context/UserContext'; |
22301009 | 1e2aea7 | 2025-06-08 16:35:54 +0800 | [diff] [blame] | 8 | import toast from 'react-hot-toast'; |
| 9 | import { confirmAlert } from 'react-confirm-alert'; |
| 10 | import 'react-confirm-alert/src/react-confirm-alert.css'; |
| 11 | import AuthButton from '../../components/AuthButton'; |
22301009 | afbcf4b | 2025-04-10 16:08:39 +0800 | [diff] [blame] | 12 | |
22301009 | ecc1c1c | 2025-04-09 21:56:23 +0800 | [diff] [blame] | 13 | const SeedList = () => { |
| 14 | const [seeds, setSeeds] = useState([]); |
22301009 | ecc1c1c | 2025-04-09 21:56:23 +0800 | [diff] [blame] | 15 | const [loading, setLoading] = useState(true); |
| 16 | const [searchTerm, setSearchTerm] = useState(''); |
22301009 | ecc1c1c | 2025-04-09 21:56:23 +0800 | [diff] [blame] | 17 | const [sortOption, setSortOption] = useState('最新'); |
22301009 | afbcf4b | 2025-04-10 16:08:39 +0800 | [diff] [blame] | 18 | const [activeTab, setActiveTab] = useState('种子列表'); |
| 19 | const [filters, setFilters] = useState({}); |
| 20 | const [selectedFilters, setSelectedFilters] = useState({}); |
22301009 | 1e2aea7 | 2025-06-08 16:35:54 +0800 | [diff] [blame] | 21 | const [tagMode, setTagMode] = useState('any'); |
22301009 | afbcf4b | 2025-04-10 16:08:39 +0800 | [diff] [blame] | 22 | const [errorMsg, setErrorMsg] = useState(''); |
22301009 | 80aaf0d | 2025-06-05 23:20:05 +0800 | [diff] [blame] | 23 | const { user } = useUser(); |
| 24 | |
22301009 | afbcf4b | 2025-04-10 16:08:39 +0800 | [diff] [blame] | 25 | const TAGS = ['猜你喜欢', '电影', '电视剧', '动漫', '音乐', '游戏', '综艺', '软件', '体育', '学习', '纪录片', '其他']; |
22301009 | ecc1c1c | 2025-04-09 21:56:23 +0800 | [diff] [blame] | 26 | |
22301009 | 1e2aea7 | 2025-06-08 16:35:54 +0800 | [diff] [blame] | 27 | const CATEGORY_MAP = { |
22301009 | 01d3ff9 | 2025-06-07 16:16:26 +0800 | [diff] [blame] | 28 | '电影': 'movie', |
| 29 | '电视剧': 'tv', |
| 30 | '动漫': 'anime', |
| 31 | '音乐': 'music', |
| 32 | '游戏': 'game', |
| 33 | '综艺': 'variety', |
| 34 | '软件': 'software', |
| 35 | '体育': 'sports', |
| 36 | '学习': 'study', |
| 37 | '纪录片': 'documentary', |
| 38 | '其他': 'other', |
22301009 | 1e2aea7 | 2025-06-08 16:35:54 +0800 | [diff] [blame] | 39 | '猜你喜欢': '', |
| 40 | '种子列表': '', |
| 41 | }; |
22301009 | afbcf4b | 2025-04-10 16:08:39 +0800 | [diff] [blame] | 42 | |
22301009 | cbd5aac | 2025-06-09 23:08:53 +0800 | [diff] [blame] | 43 | const formatBytes = (bytes) => { |
| 44 | if (bytes === 0 || bytes === null || bytes === undefined) return '0 B'; |
| 45 | const k = 1024; |
| 46 | const sizes = ['B', 'KB', 'MB', 'GB', 'TB']; |
| 47 | const i = Math.floor(Math.log(bytes) / Math.log(k)); |
| 48 | return parseFloat((bytes / Math.pow(k, i)).toFixed(2)) + ' ' + sizes[i]; |
| 49 | }; |
| 50 | |
| 51 | |
22301009 | afbcf4b | 2025-04-10 16:08:39 +0800 | [diff] [blame] | 52 | const buildQueryParams = () => { |
22301009 | 80aaf0d | 2025-06-05 23:20:05 +0800 | [diff] [blame] | 53 | const category = CATEGORY_MAP[activeTab] || ''; |
22301009 | cbd5aac | 2025-06-09 23:08:53 +0800 | [diff] [blame] | 54 | const orderKey = sortOption === '最新' ? 'create_time' : (sortOption === '最热' ? 'leechers' : 'create_time'); |
22301009 | afbcf4b | 2025-04-10 16:08:39 +0800 | [diff] [blame] | 55 | const params = { |
22301009 | afbcf4b | 2025-04-10 16:08:39 +0800 | [diff] [blame] | 56 | page: 1, |
22301009 | 80aaf0d | 2025-06-05 23:20:05 +0800 | [diff] [blame] | 57 | size: 20, |
| 58 | orderKey, |
| 59 | orderDesc: true, |
22301009 | ecc1c1c | 2025-04-09 21:56:23 +0800 | [diff] [blame] | 60 | }; |
| 61 | |
22301009 | 80aaf0d | 2025-06-05 23:20:05 +0800 | [diff] [blame] | 62 | if (searchTerm.trim()) { |
22301009 | cbd5aac | 2025-06-09 23:08:53 +0800 | [diff] [blame] | 63 | params.keyword = searchTerm.trim(); |
22301009 | 80aaf0d | 2025-06-05 23:20:05 +0800 | [diff] [blame] | 64 | } |
| 65 | if (category) { |
| 66 | params.category = category; |
| 67 | } |
22301009 | afbcf4b | 2025-04-10 16:08:39 +0800 | [diff] [blame] | 68 | |
| 69 | const tags = Object.entries(selectedFilters) |
22301009 | 80aaf0d | 2025-06-05 23:20:05 +0800 | [diff] [blame] | 70 | .filter(([_, value]) => value !== '不限') |
| 71 | .map(([_, value]) => value); |
22301009 | afbcf4b | 2025-04-10 16:08:39 +0800 | [diff] [blame] | 72 | |
| 73 | if (tags.length > 0) { |
22301009 | 80aaf0d | 2025-06-05 23:20:05 +0800 | [diff] [blame] | 74 | params.tags = tags; |
22301009 | 1e2aea7 | 2025-06-08 16:35:54 +0800 | [diff] [blame] | 75 | params.tagMode = tagMode; |
22301009 | afbcf4b | 2025-04-10 16:08:39 +0800 | [diff] [blame] | 76 | } |
| 77 | |
| 78 | return params; |
| 79 | }; |
| 80 | |
22301009 | cbd5aac | 2025-06-09 23:08:53 +0800 | [diff] [blame] | 81 | |
22301009 | afbcf4b | 2025-04-10 16:08:39 +0800 | [diff] [blame] | 82 | const fetchSeeds = async () => { |
22301009 | 1e2aea7 | 2025-06-08 16:35:54 +0800 | [diff] [blame] | 83 | if (activeTab === '猜你喜欢') return; |
22301009 | afbcf4b | 2025-04-10 16:08:39 +0800 | [diff] [blame] | 84 | setLoading(true); |
| 85 | setErrorMsg(''); |
| 86 | try { |
| 87 | const params = buildQueryParams(); |
22301009 | 01d3ff9 | 2025-06-07 16:16:26 +0800 | [diff] [blame] | 88 | const response = await axios.get('/seeds/list', { params }); |
22301009 | 80aaf0d | 2025-06-05 23:20:05 +0800 | [diff] [blame] | 89 | const data = response.data; |
22301009 | afbcf4b | 2025-04-10 16:08:39 +0800 | [diff] [blame] | 90 | |
22301009 | 1e2aea7 | 2025-06-08 16:35:54 +0800 | [diff] [blame] | 91 | if (data.code !== 0) throw new Error(data.msg || '获取失败'); |
22301009 | 80aaf0d | 2025-06-05 23:20:05 +0800 | [diff] [blame] | 92 | setSeeds(data.data || []); |
22301009 | afbcf4b | 2025-04-10 16:08:39 +0800 | [diff] [blame] | 93 | } catch (error) { |
| 94 | console.error('获取种子列表失败:', error); |
| 95 | setErrorMsg(error.message || '获取失败,请稍后再试。'); |
| 96 | setSeeds([]); |
22301009 | afbcf4b | 2025-04-10 16:08:39 +0800 | [diff] [blame] | 97 | } finally { |
| 98 | setLoading(false); |
| 99 | } |
| 100 | }; |
| 101 | |
| 102 | const fetchFilterOptions = async () => { |
22301009 | 80aaf0d | 2025-06-05 23:20:05 +0800 | [diff] [blame] | 103 | if (activeTab === '猜你喜欢' || !CATEGORY_MAP[activeTab]) return; |
22301009 | afbcf4b | 2025-04-10 16:08:39 +0800 | [diff] [blame] | 104 | const category = CATEGORY_MAP[activeTab]; |
| 105 | try { |
22301009 | 80aaf0d | 2025-06-05 23:20:05 +0800 | [diff] [blame] | 106 | const res = await axios.get(`/seed-filters?category=${category}`); |
22301009 | 5b28c67 | 2025-04-10 20:12:45 +0800 | [diff] [blame] | 107 | const filterData = res.data || {}; |
| 108 | setFilters(filterData); |
| 109 | |
22301009 | afbcf4b | 2025-04-10 16:08:39 +0800 | [diff] [blame] | 110 | const defaultSelections = {}; |
22301009 | 5b28c67 | 2025-04-10 20:12:45 +0800 | [diff] [blame] | 111 | for (const key in filterData) { |
22301009 | afbcf4b | 2025-04-10 16:08:39 +0800 | [diff] [blame] | 112 | defaultSelections[key] = '不限'; |
| 113 | } |
| 114 | setSelectedFilters(defaultSelections); |
| 115 | } catch (err) { |
| 116 | console.error('获取筛选项失败:', err); |
| 117 | setFilters({}); |
| 118 | setSelectedFilters({}); |
| 119 | } |
| 120 | }; |
22301009 | ecc1c1c | 2025-04-09 21:56:23 +0800 | [diff] [blame] | 121 | |
| 122 | useEffect(() => { |
22301009 | 80aaf0d | 2025-06-05 23:20:05 +0800 | [diff] [blame] | 123 | fetchFilterOptions(); |
22301009 | afbcf4b | 2025-04-10 16:08:39 +0800 | [diff] [blame] | 124 | }, [activeTab]); |
22301009 | ecc1c1c | 2025-04-09 21:56:23 +0800 | [diff] [blame] | 125 | |
22301009 | afbcf4b | 2025-04-10 16:08:39 +0800 | [diff] [blame] | 126 | useEffect(() => { |
22301009 | 80aaf0d | 2025-06-05 23:20:05 +0800 | [diff] [blame] | 127 | fetchSeeds(); |
22301009 | afbcf4b | 2025-04-10 16:08:39 +0800 | [diff] [blame] | 128 | }, [activeTab, sortOption, selectedFilters, tagMode, searchTerm]); |
22301009 | ecc1c1c | 2025-04-09 21:56:23 +0800 | [diff] [blame] | 129 | |
22301009 | afbcf4b | 2025-04-10 16:08:39 +0800 | [diff] [blame] | 130 | const handleDownload = async (seedId) => { |
22301009 | afbcf4b | 2025-04-10 16:08:39 +0800 | [diff] [blame] | 131 | try { |
22301009 | 80aaf0d | 2025-06-05 23:20:05 +0800 | [diff] [blame] | 132 | const response = await axios.get(`/seeds/${seedId}/download`, { |
22301009 | 1e2aea7 | 2025-06-08 16:35:54 +0800 | [diff] [blame] | 133 | params: { passkey: user.userId }, |
22301009 | cbd5aac | 2025-06-09 23:08:53 +0800 | [diff] [blame] | 134 | responseType: 'blob', |
| 135 | validateStatus: () => true // 允许处理非 2xx 响应 |
22301009 | afbcf4b | 2025-04-10 16:08:39 +0800 | [diff] [blame] | 136 | }); |
| 137 | |
22301009 | cbd5aac | 2025-06-09 23:08:53 +0800 | [diff] [blame] | 138 | if (response.data && response.data.type === 'application/json') { |
| 139 | // 服务端返回的是 JSON 而不是 torrent 文件,尝试解析内容 |
| 140 | const reader = new FileReader(); |
| 141 | reader.onload = () => { |
| 142 | try { |
| 143 | const json = JSON.parse(reader.result); |
| 144 | if (json.code === 403 && json.msg === '您没有权限') { |
| 145 | toast.error('您已被封禁,如有疑问请联系管理员'); |
| 146 | } else { |
| 147 | toast.error(json.msg || '下载失败,请稍后再试。'); |
| 148 | } |
| 149 | } catch { |
| 150 | toast.error('下载失败,请稍后再试。'); |
| 151 | } |
| 152 | }; |
| 153 | reader.readAsText(response.data); |
| 154 | return; |
| 155 | } |
| 156 | |
| 157 | // 如果是 torrent 文件 |
22301009 | afbcf4b | 2025-04-10 16:08:39 +0800 | [diff] [blame] | 158 | const blob = new Blob([response.data], { type: 'application/x-bittorrent' }); |
| 159 | const downloadUrl = URL.createObjectURL(blob); |
| 160 | const a = document.createElement('a'); |
| 161 | a.href = downloadUrl; |
| 162 | a.download = `${seedId}.torrent`; |
| 163 | a.click(); |
| 164 | URL.revokeObjectURL(downloadUrl); |
| 165 | } catch (error) { |
| 166 | console.error('下载失败:', error); |
22301009 | 1e2aea7 | 2025-06-08 16:35:54 +0800 | [diff] [blame] | 167 | toast.error('下载失败,请稍后再试。'); |
22301009 | ecc1c1c | 2025-04-09 21:56:23 +0800 | [diff] [blame] | 168 | } |
22301009 | afbcf4b | 2025-04-10 16:08:39 +0800 | [diff] [blame] | 169 | }; |
22301009 | ecc1c1c | 2025-04-09 21:56:23 +0800 | [diff] [blame] | 170 | |
22301009 | cbd5aac | 2025-06-09 23:08:53 +0800 | [diff] [blame] | 171 | |
22301009 | 5b28c67 | 2025-04-10 20:12:45 +0800 | [diff] [blame] | 172 | const handleFilterChange = (key, value) => { |
22301009 | 1e2aea7 | 2025-06-08 16:35:54 +0800 | [diff] [blame] | 173 | setSelectedFilters(prev => ({ ...prev, [key]: value })); |
22301009 | 5b28c67 | 2025-04-10 20:12:45 +0800 | [diff] [blame] | 174 | }; |
| 175 | |
| 176 | const clearFilter = (key) => { |
22301009 | 1e2aea7 | 2025-06-08 16:35:54 +0800 | [diff] [blame] | 177 | setSelectedFilters(prev => ({ ...prev, [key]: '不限' })); |
22301009 | 5b28c67 | 2025-04-10 20:12:45 +0800 | [diff] [blame] | 178 | }; |
| 179 | |
22301009 | ecc1c1c | 2025-04-09 21:56:23 +0800 | [diff] [blame] | 180 | return ( |
Krishya | f1d0ea8 | 2025-05-03 17:01:58 +0800 | [diff] [blame] | 181 | <div className="seed-list-container"> |
22301009 | 80aaf0d | 2025-06-05 23:20:05 +0800 | [diff] [blame] | 182 | <Header /> |
22301009 | ecc1c1c | 2025-04-09 21:56:23 +0800 | [diff] [blame] | 183 | |
22301009 | ecc1c1c | 2025-04-09 21:56:23 +0800 | [diff] [blame] | 184 | <div className="controls"> |
| 185 | <input |
| 186 | type="text" |
| 187 | placeholder="搜索种子..." |
| 188 | value={searchTerm} |
| 189 | onChange={(e) => setSearchTerm(e.target.value)} |
| 190 | className="search-input" |
| 191 | /> |
22301009 | 1e2aea7 | 2025-06-08 16:35:54 +0800 | [diff] [blame] | 192 | <select value={sortOption} onChange={(e) => setSortOption(e.target.value)} className="sort-select"> |
22301009 | ecc1c1c | 2025-04-09 21:56:23 +0800 | [diff] [blame] | 193 | <option value="最新">最新</option> |
| 194 | <option value="最热">最热</option> |
22301009 | afbcf4b | 2025-04-10 16:08:39 +0800 | [diff] [blame] | 195 | </select> |
22301009 | cbd5aac | 2025-06-09 23:08:53 +0800 | [diff] [blame] | 196 | {/* <select value={tagMode} onChange={(e) => setTagMode(e.target.value)} className="tag-mode-select"> |
22301009 | afbcf4b | 2025-04-10 16:08:39 +0800 | [diff] [blame] | 197 | <option value="any">包含任意标签</option> |
| 198 | <option value="all">包含所有标签</option> |
22301009 | cbd5aac | 2025-06-09 23:08:53 +0800 | [diff] [blame] | 199 | </select> */} |
22301009 | ecc1c1c | 2025-04-09 21:56:23 +0800 | [diff] [blame] | 200 | </div> |
| 201 | |
| 202 | <div className="tag-filters"> |
22301009 | 80aaf0d | 2025-06-05 23:20:05 +0800 | [diff] [blame] | 203 | {TAGS.map(tag => ( |
22301009 | cbd5aac | 2025-06-09 23:08:53 +0800 | [diff] [blame] | 204 | <button |
22301009 | ecc1c1c | 2025-04-09 21:56:23 +0800 | [diff] [blame] | 205 | key={tag} |
22301009 | 80aaf0d | 2025-06-05 23:20:05 +0800 | [diff] [blame] | 206 | className={`tag-button ${activeTab === tag ? 'active-tag' : ''}`} |
22301009 | ecc1c1c | 2025-04-09 21:56:23 +0800 | [diff] [blame] | 207 | onClick={() => { |
22301009 | afbcf4b | 2025-04-10 16:08:39 +0800 | [diff] [blame] | 208 | setActiveTab(tag); |
| 209 | setFilters({}); |
| 210 | setSelectedFilters({}); |
22301009 | ecc1c1c | 2025-04-09 21:56:23 +0800 | [diff] [blame] | 211 | }} |
| 212 | > |
| 213 | {tag} |
22301009 | 207e2db | 2025-06-09 00:27:28 +0800 | [diff] [blame] | 214 | </button> |
22301009 | ecc1c1c | 2025-04-09 21:56:23 +0800 | [diff] [blame] | 215 | ))} |
| 216 | </div> |
| 217 | |
22301009 | 80aaf0d | 2025-06-05 23:20:05 +0800 | [diff] [blame] | 218 | {activeTab !== '猜你喜欢' && Object.keys(filters).length > 0 && ( |
22301009 | afbcf4b | 2025-04-10 16:08:39 +0800 | [diff] [blame] | 219 | <div className="filter-bar"> |
| 220 | {Object.entries(filters).map(([key, options]) => ( |
| 221 | <div className="filter-group" key={key}> |
| 222 | <label>{key}:</label> |
22301009 | 1e2aea7 | 2025-06-08 16:35:54 +0800 | [diff] [blame] | 223 | <select value={selectedFilters[key]} onChange={(e) => handleFilterChange(key, e.target.value)}> |
22301009 | 80aaf0d | 2025-06-05 23:20:05 +0800 | [diff] [blame] | 224 | {options.map(opt => ( |
22301009 | afbcf4b | 2025-04-10 16:08:39 +0800 | [diff] [blame] | 225 | <option key={opt} value={opt}>{opt}</option> |
| 226 | ))} |
| 227 | </select> |
22301009 | 80aaf0d | 2025-06-05 23:20:05 +0800 | [diff] [blame] | 228 | {selectedFilters[key] !== '不限' && ( |
22301009 | 1e2aea7 | 2025-06-08 16:35:54 +0800 | [diff] [blame] | 229 | <button className="clear-filter-btn" onClick={() => clearFilter(key)}>✕</button> |
22301009 | 5b28c67 | 2025-04-10 20:12:45 +0800 | [diff] [blame] | 230 | )} |
22301009 | afbcf4b | 2025-04-10 16:08:39 +0800 | [diff] [blame] | 231 | </div> |
| 232 | ))} |
| 233 | </div> |
| 234 | )} |
| 235 | |
22301009 | ecc1c1c | 2025-04-09 21:56:23 +0800 | [diff] [blame] | 236 | <div className="seed-list-content"> |
22301009 | 80aaf0d | 2025-06-05 23:20:05 +0800 | [diff] [blame] | 237 | {activeTab === '猜你喜欢' ? ( |
22301009 | afbcf4b | 2025-04-10 16:08:39 +0800 | [diff] [blame] | 238 | <Recommend /> |
22301009 | 80aaf0d | 2025-06-05 23:20:05 +0800 | [diff] [blame] | 239 | ) : loading ? ( |
22301009 | ecc1c1c | 2025-04-09 21:56:23 +0800 | [diff] [blame] | 240 | <p>加载中...</p> |
22301009 | 80aaf0d | 2025-06-05 23:20:05 +0800 | [diff] [blame] | 241 | ) : errorMsg ? ( |
22301009 | afbcf4b | 2025-04-10 16:08:39 +0800 | [diff] [blame] | 242 | <p className="error-text">{errorMsg}</p> |
22301009 | 80aaf0d | 2025-06-05 23:20:05 +0800 | [diff] [blame] | 243 | ) : seeds.length === 0 ? ( |
22301009 | ecc1c1c | 2025-04-09 21:56:23 +0800 | [diff] [blame] | 244 | <p>未找到符合条件的种子。</p> |
| 245 | ) : ( |
Krishya | 25590de | 2025-04-21 19:03:49 +0800 | [diff] [blame] | 246 | <div className="seed-list-card"> |
| 247 | <div className="seed-list-header"> |
| 248 | <div className="seed-header-cover"></div> |
| 249 | <div className="seed-header-title">种子名称</div> |
| 250 | <div className="seed-header-size">大小</div> |
| 251 | <div className="seed-header-upload-time">上传时间</div> |
| 252 | <div className="seed-header-downloads">下载次数</div> |
| 253 | <div className="seed-header-actions">操作</div> |
| 254 | </div> |
| 255 | <div className="seed-list-body"> |
22301009 | 80aaf0d | 2025-06-05 23:20:05 +0800 | [diff] [blame] | 256 | {seeds.map((seed, index) => { |
22301009 | 80aaf0d | 2025-06-05 23:20:05 +0800 | [diff] [blame] | 257 | let tagsArray = []; |
| 258 | if (seed.tags) { |
| 259 | if (Array.isArray(seed.tags)) { |
| 260 | tagsArray = seed.tags; |
| 261 | } else if (typeof seed.tags === 'string') { |
| 262 | try { |
| 263 | tagsArray = JSON.parse(seed.tags); |
| 264 | if (!Array.isArray(tagsArray)) { |
22301111 | a289e26 | 2025-06-07 22:38:46 +0800 | [diff] [blame] | 265 | tagsArray = seed.tags.split(',').map(t => t.trim()).filter(t => t); |
22301009 | 80aaf0d | 2025-06-05 23:20:05 +0800 | [diff] [blame] | 266 | } |
| 267 | } catch { |
22301111 | a289e26 | 2025-06-07 22:38:46 +0800 | [diff] [blame] | 268 | tagsArray = seed.tags.split(',').map(t => t.trim()).filter(t => t); |
22301009 | 80aaf0d | 2025-06-05 23:20:05 +0800 | [diff] [blame] | 269 | } |
| 270 | } |
| 271 | } |
| 272 | |
| 273 | return ( |
22301009 | cbd5aac | 2025-06-09 23:08:53 +0800 | [diff] [blame] | 274 | // <Link to={`/seed/${seed.id}`} key={index} className="seed-item-link"> |
| 275 | <Link to={`/seed/${seed.id}`} key={seed.id} className="seed-item-link"> |
22301009 | 80aaf0d | 2025-06-05 23:20:05 +0800 | [diff] [blame] | 276 | <div className="seed-item"> |
22301009 | 4158f3a | 2025-06-06 19:59:10 +0800 | [diff] [blame] | 277 | {seed.imageUrl && ( |
22301009 | 1e2aea7 | 2025-06-08 16:35:54 +0800 | [diff] [blame] | 278 | <img src={seed.imageUrl} alt={seed.title} className="seed-item-cover" /> |
22301009 | 80aaf0d | 2025-06-05 23:20:05 +0800 | [diff] [blame] | 279 | )} |
| 280 | <div className="seed-item-title"> |
| 281 | <div className="seed-title-row"> |
| 282 | <h3 className="seed-title">{seed.title}</h3> |
| 283 | <div className="seed-tags"> |
| 284 | {tagsArray.map((tag, i) => ( |
| 285 | <span key={i} className="tag-label">{tag}</span> |
| 286 | ))} |
| 287 | </div> |
Krishya | 25590de | 2025-04-21 19:03:49 +0800 | [diff] [blame] | 288 | </div> |
| 289 | </div> |
22301009 | cbd5aac | 2025-06-09 23:08:53 +0800 | [diff] [blame] | 290 | {/* <div className="seed-item-size">{seed.size || '未知'}</div> */} |
| 291 | <div className="seed-item-size">{seed.size ? formatBytes(seed.size) : '未知'}</div> |
| 292 | |
| 293 | <div className="seed-item-upload-time"> |
| 294 | { |
| 295 | (() => { |
| 296 | if (!seed.createdTime || !Array.isArray(seed.createdTime)) return '未知'; |
| 297 | const [year, month, day, hour, minute, second] = seed.createdTime; |
| 298 | if ([year, month, day, hour, minute, second].some(v => typeof v !== 'number')) return '未知'; |
| 299 | |
| 300 | const date = new Date(year, month - 1, day, hour, minute, second); |
| 301 | if (isNaN(date.getTime())) return '未知'; |
| 302 | |
| 303 | // 格式化为 yyyy-mm-dd |
| 304 | const yyyy = date.getFullYear(); |
| 305 | const mm = String(date.getMonth() + 1).padStart(2, '0'); // 月份要加1,补0 |
| 306 | const dd = String(date.getDate()).padStart(2, '0'); |
| 307 | |
| 308 | return `${yyyy}-${mm}-${dd}`; |
| 309 | })() |
| 310 | } |
| 311 | </div> |
| 312 | |
| 313 | |
22301009 | 207e2db | 2025-06-09 00:27:28 +0800 | [diff] [blame] | 314 | <div className="seed-item-downloads">{seed.leechers ?? 0} 次下载</div> |
22301009 | 1e2aea7 | 2025-06-08 16:35:54 +0800 | [diff] [blame] | 315 | <div className="seed-item-actions" onClick={e => e.stopPropagation()}> |
22301009 | 207e2db | 2025-06-09 00:27:28 +0800 | [diff] [blame] | 316 | <AuthButton |
22301009 | cbd5aac | 2025-06-09 23:08:53 +0800 | [diff] [blame] | 317 | roles={["cookie", "chocolate", "ice-cream"]} |
22301009 | 80aaf0d | 2025-06-05 23:20:05 +0800 | [diff] [blame] | 318 | className="btn-primary" |
| 319 | onClick={e => { |
| 320 | e.preventDefault(); |
| 321 | e.stopPropagation(); |
22301009 | 1e2aea7 | 2025-06-08 16:35:54 +0800 | [diff] [blame] | 322 | if (!user || !user.userId) { |
| 323 | toast.error('请先登录再下载种子文件'); |
| 324 | return; |
| 325 | } |
| 326 | confirmAlert({ |
| 327 | title: '确认下载', |
| 328 | message: `是否下载种子「${seed.title}」?`, |
| 329 | buttons: [ |
| 330 | { |
| 331 | label: '确认', |
| 332 | onClick: () => handleDownload(seed.id) |
| 333 | }, |
| 334 | { |
| 335 | label: '取消', |
| 336 | onClick: () => { } |
| 337 | } |
| 338 | ] |
| 339 | }); |
22301009 | 80aaf0d | 2025-06-05 23:20:05 +0800 | [diff] [blame] | 340 | }} |
| 341 | > |
| 342 | 下载 |
22301009 | 207e2db | 2025-06-09 00:27:28 +0800 | [diff] [blame] | 343 | </AuthButton> |
| 344 | <AuthButton |
| 345 | roles={["cookie", "chocolate", "ice-cream"]} |
22301009 | 01d3ff9 | 2025-06-07 16:16:26 +0800 | [diff] [blame] | 346 | className="btn-outline" |
| 347 | onClick={async (e) => { |
| 348 | e.preventDefault(); |
| 349 | e.stopPropagation(); |
22301009 | 80aaf0d | 2025-06-05 23:20:05 +0800 | [diff] [blame] | 350 | |
22301009 | 01d3ff9 | 2025-06-07 16:16:26 +0800 | [diff] [blame] | 351 | if (!user || !user.userId) { |
22301009 | 1e2aea7 | 2025-06-08 16:35:54 +0800 | [diff] [blame] | 352 | toast.error('请先登录再收藏'); |
22301009 | 01d3ff9 | 2025-06-07 16:16:26 +0800 | [diff] [blame] | 353 | return; |
| 354 | } |
22301009 | 80aaf0d | 2025-06-05 23:20:05 +0800 | [diff] [blame] | 355 | |
22301009 | 01d3ff9 | 2025-06-07 16:16:26 +0800 | [diff] [blame] | 356 | try { |
| 357 | const res = await axios.post(`/seeds/${seed.id}/favorite-toggle`, null, { |
| 358 | params: { user_id: user.userId }, |
| 359 | }); |
22301009 | 80aaf0d | 2025-06-05 23:20:05 +0800 | [diff] [blame] | 360 | |
22301009 | 01d3ff9 | 2025-06-07 16:16:26 +0800 | [diff] [blame] | 361 | if (res.data.code === 0) { |
22301009 | 1e2aea7 | 2025-06-08 16:35:54 +0800 | [diff] [blame] | 362 | toast.success('操作成功'); |
22301009 | 01d3ff9 | 2025-06-07 16:16:26 +0800 | [diff] [blame] | 363 | } else { |
22301009 | 1e2aea7 | 2025-06-08 16:35:54 +0800 | [diff] [blame] | 364 | toast.error(res.data.msg || '操作失败'); |
22301009 | 01d3ff9 | 2025-06-07 16:16:26 +0800 | [diff] [blame] | 365 | } |
| 366 | } catch (err) { |
| 367 | console.error('收藏失败:', err); |
22301009 | 1e2aea7 | 2025-06-08 16:35:54 +0800 | [diff] [blame] | 368 | toast.error('收藏失败,请稍后再试。'); |
22301009 | 01d3ff9 | 2025-06-07 16:16:26 +0800 | [diff] [blame] | 369 | } |
| 370 | }} |
| 371 | > |
| 372 | 收藏 |
22301009 | 207e2db | 2025-06-09 00:27:28 +0800 | [diff] [blame] | 373 | </AuthButton> |
22301009 | 80aaf0d | 2025-06-05 23:20:05 +0800 | [diff] [blame] | 374 | </div> |
Krishya | 25590de | 2025-04-21 19:03:49 +0800 | [diff] [blame] | 375 | </div> |
22301009 | 80aaf0d | 2025-06-05 23:20:05 +0800 | [diff] [blame] | 376 | </Link> |
| 377 | ); |
| 378 | })} |
Krishya | 25590de | 2025-04-21 19:03:49 +0800 | [diff] [blame] | 379 | </div> |
22301009 | ecc1c1c | 2025-04-09 21:56:23 +0800 | [diff] [blame] | 380 | </div> |
| 381 | )} |
| 382 | </div> |
| 383 | </div> |
| 384 | ); |
| 385 | }; |
| 386 | |
| 387 | export default SeedList; |