86133 | ec55c54 | 2025-04-21 11:51:32 +0800 | [diff] [blame] | 1 | import { request } from '@umijs/max'; |
| 2 | import type { |
| 3 | BtTorrent, |
| 4 | BtTorrentFile, |
| 5 | BtTorrentAnnounce, |
| 6 | BtTorrentTag, |
| 7 | } from '@/pages/Torrent/data'; // 假设你把 data.d.ts 放这里 |
| 8 | |
BirdNETM | b0f7153 | 2025-05-26 17:37:33 +0800 | [diff] [blame] | 9 | /** 下载种子文件 */ |
| 10 | export async function downloadTorrent(torrentId: number) { |
| 11 | return request(`/api/system/torrent/download/${torrentId}`, { |
| 12 | method: 'get', |
| 13 | responseType: 'blob', |
| 14 | }); |
| 15 | } |
| 16 | |
86133 | ec55c54 | 2025-04-21 11:51:32 +0800 | [diff] [blame] | 17 | // ================================ |
| 18 | // 种子主表(bt_torrent)接口 |
| 19 | // ================================ |
| 20 | |
| 21 | /** 查询种子列表 */ |
Atopos0524 | 878db00 | 2025-06-08 22:36:57 +0800 | [diff] [blame^] | 22 | export async function listBtTorrent(userId: string) { |
| 23 | return request(`/api/system/torrent/recommend`, { |
| 24 | method: 'post', |
86133 | ec55c54 | 2025-04-21 11:51:32 +0800 | [diff] [blame] | 25 | }); |
| 26 | } |
| 27 | |
| 28 | /** 获取种子详情 */ |
| 29 | export async function getBtTorrent(torrentId: number) { |
| 30 | return request<BtTorrent>(`/api/system/torrent/${torrentId}`, { |
| 31 | method: 'get', |
| 32 | }); |
| 33 | } |
| 34 | |
| 35 | /** 新增种子 */ |
| 36 | export async function addBtTorrent(data: BtTorrent) { |
| 37 | return request('/api/system/torrent', { |
| 38 | method: 'post', |
| 39 | data, |
| 40 | }); |
| 41 | } |
| 42 | |
| 43 | /** 修改种子 */ |
| 44 | export async function updateBtTorrent(data: BtTorrent) { |
| 45 | return request('/api/system/torrent', { |
| 46 | method: 'put', |
| 47 | data, |
| 48 | }); |
| 49 | } |
| 50 | |
| 51 | /** 删除种子(支持批量) */ |
| 52 | export async function removeBtTorrent(torrentIds: number[]) { |
| 53 | return request(`/api/system/torrent/${torrentIds.join(',')}`, { |
| 54 | method: 'delete', |
| 55 | }); |
| 56 | } |
| 57 | |
| 58 | // ================================ |
| 59 | // 种子文件(bt_torrent_file)接口 |
| 60 | // ================================ |
| 61 | |
| 62 | /** 查询种子文件列表 */ |
| 63 | export async function listBtTorrentFile(params?: Partial<BtTorrentFile>) { |
| 64 | const queryString = params ? `?${new URLSearchParams(params as any)}` : ''; |
| 65 | return request(`/api/system/file/list${queryString}`, { |
| 66 | method: 'get', |
| 67 | }); |
| 68 | } |
| 69 | |
| 70 | /** 获取文件详情 */ |
| 71 | export async function getBtTorrentFile(id: number) { |
BirdNETM | b0f7153 | 2025-05-26 17:37:33 +0800 | [diff] [blame] | 72 | |
86133 | ec55c54 | 2025-04-21 11:51:32 +0800 | [diff] [blame] | 73 | return request<BtTorrentFile>(`/api/system/file/${id}`, { |
| 74 | method: 'get', |
| 75 | }); |
| 76 | } |
| 77 | |
| 78 | /** 新增文件 */ |
| 79 | export async function addBtTorrentFile(data: BtTorrentFile) { |
| 80 | return request('/api/system/file', { |
| 81 | method: 'post', |
| 82 | data, |
| 83 | }); |
| 84 | } |
| 85 | |
| 86 | /** 修改文件 */ |
| 87 | export async function updateBtTorrentFile(data: BtTorrentFile) { |
| 88 | return request('/api/system/file', { |
| 89 | method: 'put', |
| 90 | data, |
| 91 | }); |
| 92 | } |
| 93 | |
| 94 | /** 删除文件(支持批量) */ |
| 95 | export async function removeBtTorrentFile(ids: number[]) { |
| 96 | return request(`/api/system/file/${ids.join(',')}`, { |
| 97 | method: 'delete', |
| 98 | }); |
| 99 | } |
| 100 | |
| 101 | // ================================ |
| 102 | // Tracker 列表(bt_torrent_announce)接口 |
| 103 | // ================================ |
| 104 | |
| 105 | /** 查询 Tracker 列表 */ |
| 106 | export async function listBtTorrentAnnounce(params?: Partial<BtTorrentAnnounce>) { |
| 107 | const queryString = params ? `?${new URLSearchParams(params as any)}` : ''; |
| 108 | return request(`/api/system/announce/list${queryString}`, { |
| 109 | method: 'get', |
| 110 | }); |
| 111 | } |
| 112 | |
| 113 | /** 获取单个 Tracker */ |
| 114 | export async function getBtTorrentAnnounce(id: number) { |
| 115 | return request<BtTorrentAnnounce>(`/api/system/announce/${id}`, { |
| 116 | method: 'get', |
| 117 | }); |
| 118 | } |
| 119 | |
| 120 | /** 新增 Tracker */ |
| 121 | export async function addBtTorrentAnnounce(data: BtTorrentAnnounce) { |
| 122 | return request('/api/system/announce', { |
| 123 | method: 'post', |
| 124 | data, |
| 125 | }); |
| 126 | } |
| 127 | |
| 128 | /** 修改 Tracker */ |
| 129 | export async function updateBtTorrentAnnounce(data: BtTorrentAnnounce) { |
| 130 | return request('/api/system/announce', { |
| 131 | method: 'put', |
| 132 | data, |
| 133 | }); |
| 134 | } |
| 135 | |
| 136 | /** 删除 Tracker(支持批量) */ |
| 137 | export async function removeBtTorrentAnnounce(ids: number[]) { |
| 138 | return request(`/api/system/announce/${ids.join(',')}`, { |
| 139 | method: 'delete', |
| 140 | }); |
| 141 | } |
| 142 | |
| 143 | // ================================ |
| 144 | // 种子标签(bt_torrent_tags)接口 |
| 145 | // ================================ |
| 146 | |
| 147 | /** 查询标签列表 */ |
| 148 | export async function listBtTorrentTags(params?: Partial<BtTorrentTag>) { |
| 149 | const queryString = params ? `?${new URLSearchParams(params as any)}` : ''; |
| 150 | return request(`/api/system/tags/list${queryString}`, { |
| 151 | method: 'get', |
| 152 | }); |
| 153 | } |
| 154 | |
| 155 | /** 获取标签详情 */ |
| 156 | export async function getBtTorrentTag(id: number) { |
| 157 | return request<BtTorrentTag>(`/api/system/tags/${id}`, { |
| 158 | method: 'get', |
| 159 | }); |
| 160 | } |
| 161 | |
| 162 | /** 新增标签 */ |
| 163 | export async function addBtTorrentTag(data: BtTorrentTag) { |
| 164 | return request('/api/system/tags', { |
| 165 | method: 'post', |
| 166 | data, |
| 167 | }); |
| 168 | } |
| 169 | |
| 170 | /** 修改标签 */ |
| 171 | export async function updateBtTorrentTag(data: BtTorrentTag) { |
| 172 | return request('/api/system/tags', { |
| 173 | method: 'put', |
| 174 | data, |
| 175 | }); |
| 176 | } |
86133 | 2d0a179 | 2025-04-21 20:45:00 +0800 | [diff] [blame] | 177 | /** |
| 178 | * 上传并解析种子文件 |
| 179 | * @param file The .torrent file to upload |
| 180 | * @returns The parsed torrent data or error message |
| 181 | */ |
| 182 | export async function uploadTorrent(file: File) { |
| 183 | const formData = new FormData(); |
| 184 | formData.append('file', file); |
86133 | ec55c54 | 2025-04-21 11:51:32 +0800 | [diff] [blame] | 185 | |
86133 | 2d0a179 | 2025-04-21 20:45:00 +0800 | [diff] [blame] | 186 | return request('/api/system/torrent/uploadTorrent', { |
| 187 | method: 'POST', |
| 188 | data: formData, |
| 189 | headers: { |
| 190 | 'Content-Type': 'multipart/form-data', |
| 191 | }, |
| 192 | }); |
| 193 | } |
86133 | ec55c54 | 2025-04-21 11:51:32 +0800 | [diff] [blame] | 194 | /** 删除标签(支持批量) */ |
| 195 | export async function removeBtTorrentTag(ids: number[]) { |
| 196 | return request(`/api/system/tags/${ids.join(',')}`, { |
| 197 | method: 'delete', |
| 198 | }); |
| 199 | } |