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