Jiarenxiang | 3672848 | 2025-06-07 21:51:26 +0800 | [diff] [blame] | 1 | import { request } from '@umijs/max'; |
| 2 | |
| 3 | // 获取分类 |
| 4 | export async function getCategories() { |
| 5 | return request('/api/tag/all_cat'); |
| 6 | } |
| 7 | |
| 8 | // 获取种子列表 |
| 9 | export async function getTorrentList(params: { |
| 10 | category?: string; |
| 11 | sortField: string; |
| 12 | sortDirection: string; |
| 13 | pageNum: number; |
| 14 | pageSize: number; |
| 15 | }) { |
| 16 | return request('/api/torrent/torrentList', { |
| 17 | method: 'POST', |
| 18 | data: params, |
| 19 | }); |
| 20 | } |
| 21 | |
Jiarenxiang | 56cbf66 | 2025-06-09 21:46:47 +0800 | [diff] [blame^] | 22 | export async function getMyTorrentList() { |
| 23 | return request('/api/torrent/myList', { |
| 24 | method: 'POST', |
| 25 | }); |
| 26 | } |
| 27 | |
Jiarenxiang | 3672848 | 2025-06-07 21:51:26 +0800 | [diff] [blame] | 28 | export async function getTorrentInfo(params: { |
| 29 | id: string | number; |
| 30 | }) { |
| 31 | return request(`/api/torrent/info/${params.id}`, { |
| 32 | method: 'POST', |
| 33 | }); |
| 34 | } |
| 35 | |
| 36 | |
| 37 | export async function downloadTorrent(params: { |
| 38 | id: string | number; |
| 39 | passkey?: string; |
| 40 | }) { |
| 41 | return request('/api/torrent/download', { |
| 42 | method: 'GET', |
| 43 | params: { |
| 44 | id: params.id, |
| 45 | }, |
| 46 | responseType: 'blob', |
| 47 | }); |
| 48 | } |
| 49 | |
| 50 | export async function addComment(params: { |
| 51 | torrentId: number; |
| 52 | pid?: number; |
| 53 | comment: string; |
| 54 | }) { |
| 55 | return request('/api/torrent/addComment', { |
| 56 | method: 'POST', |
| 57 | data: params, |
| 58 | }); |
| 59 | } |
| 60 | |
| 61 | export async function getComments(params: { |
| 62 | torrentId: number; |
| 63 | pageNum?: number; |
| 64 | pageSize?: number; |
| 65 | }) { |
| 66 | return request('/api/torrent/comments', { |
| 67 | method: 'GET', |
| 68 | params, |
| 69 | }); |
| 70 | } |
| 71 | |
| 72 | export interface TorrentAddParam { |
| 73 | name: string; |
| 74 | title: string; |
| 75 | subheading: string; |
| 76 | cover?: string; |
| 77 | description: string; |
| 78 | category: number; |
| 79 | status?: number; |
| 80 | anonymous?: number; |
| 81 | remark?: string; |
| 82 | } |
| 83 | |
| 84 | // 审核种子参数 |
| 85 | export interface TorrentAuditParam { |
| 86 | id: number; |
| 87 | status: number; |
| 88 | remark?: string; |
| 89 | } |
| 90 | |
| 91 | // 种子实体 |
| 92 | export interface TorrentEntity { |
| 93 | id?: number; |
| 94 | infoHash?: Uint8Array; |
| 95 | name?: string; |
| 96 | filename?: string; |
| 97 | title?: string; |
| 98 | subheading?: string; |
| 99 | cover?: string; |
| 100 | description?: string; |
| 101 | category?: number; |
| 102 | status?: number; |
| 103 | fileStatus?: number; |
| 104 | reviewer?: number; |
| 105 | createTime?: string; |
| 106 | updateTime?: string; |
| 107 | owner?: number; |
| 108 | size?: number; |
| 109 | type?: number; |
| 110 | fileCount?: number; |
| 111 | comments?: number; |
| 112 | views?: number; |
| 113 | hits?: number; |
| 114 | visible?: number; |
| 115 | anonymous?: number; |
| 116 | leechers?: number; |
| 117 | seeders?: number; |
| 118 | completions?: number; |
| 119 | remark?: string; |
| 120 | } |
| 121 | |
| 122 | // 添加种子 |
| 123 | export async function addTorrent(param: TorrentAddParam) { |
| 124 | return request('/api/torrent/add', { |
| 125 | method: 'POST', |
| 126 | data: param, |
| 127 | }); |
| 128 | } |
| 129 | |
| 130 | // 审核种子 |
| 131 | export async function auditTorrent(param: TorrentAuditParam) { |
| 132 | return request('/api/torrent/audit', { |
| 133 | method: 'POST', |
| 134 | data: param, |
| 135 | }); |
| 136 | } |
| 137 | |
| 138 | // 点赞 |
| 139 | export async function favoriteTorrent(id: number) { |
| 140 | return request('/api/torrent/favorite', { |
| 141 | method: 'POST', |
| 142 | params: { id }, |
| 143 | }); |
| 144 | } |
| 145 | |
| 146 | // 上传种子.torrent |
| 147 | export async function uploadTorrentFile(file: File, id: number) { |
| 148 | const formData = new FormData(); |
| 149 | formData.append('file', file); |
| 150 | formData.append('id', id.toString()); |
| 151 | return request('/api/torrent/upload', { |
| 152 | method: 'POST', |
| 153 | data: formData, |
Jiarenxiang | 3672848 | 2025-06-07 21:51:26 +0800 | [diff] [blame] | 154 | }); |
| 155 | } |
| 156 | |
| 157 | // 更新种子 |
| 158 | export async function updateTorrent(entity: TorrentEntity) { |
| 159 | return request('/api/torrent/update', { |
| 160 | method: 'POST', |
| 161 | data: entity, |
| 162 | }); |
| 163 | } |
| 164 | |
| 165 | // 删除种子 |
| 166 | export async function deleteTorrent(ids: number[]) { |
| 167 | return request('/api/torrent/delete', { |
| 168 | method: 'POST', |
| 169 | data: ids, |
| 170 | }); |
| 171 | } |
| 172 | |
| 173 | // 获取服务器Tracker |
| 174 | export async function getTracker() { |
| 175 | return request('/api/torrent/tracker', { |
| 176 | method: 'POST', |
| 177 | }); |
Jiarenxiang | 24d681b | 2025-06-08 19:27:05 +0800 | [diff] [blame] | 178 | } |
| 179 | |
| 180 | export interface TorrentSearchRequest { |
| 181 | infoHash?: string; |
| 182 | category?: number; |
| 183 | status?: number; |
| 184 | fileStatus?: number; |
| 185 | owner?: number; |
| 186 | type?: number; |
| 187 | nameKeyword?: string; |
| 188 | titleKeyword?: string; |
| 189 | descriptionKeyword?: string; |
| 190 | minSize?: number; |
| 191 | maxSize?: number; |
| 192 | createTimeStart?: string; // ISO string |
| 193 | createTimeEnd?: string; // ISO string |
| 194 | sortField?: string; |
| 195 | sortDirection?: string; |
| 196 | pageNum?: number; |
| 197 | pageSize?: number; |
| 198 | } |
| 199 | |
| 200 | export interface UserEntity { |
| 201 | user_id: number; |
| 202 | user_name: string; |
| 203 | nick_name: string; |
| 204 | user_type: string; |
| 205 | email: string; |
| 206 | phonenumber: string; |
| 207 | gender: string; |
| 208 | avatar: string; |
| 209 | password: string; |
| 210 | status: number; |
| 211 | login_ip: string; |
| 212 | login_date: string; |
| 213 | create_by: string; |
| 214 | create_time: string; |
| 215 | update_by: string; |
| 216 | update_time: string; |
| 217 | remark: string; |
| 218 | full_name: string; |
| 219 | state: number; |
| 220 | added: string; |
| 221 | last_login: string; |
| 222 | last_access: string; |
| 223 | last_home: string; |
| 224 | last_offer: string; |
| 225 | forum_access: string; |
| 226 | last_staffmsg: string; |
| 227 | last_pm: string; |
| 228 | last_comment: string; |
| 229 | last_post: string; |
| 230 | last_active: string; |
| 231 | privacy: number; |
| 232 | reg_ip: string; |
| 233 | level: number; |
| 234 | seedtime: number; |
| 235 | leechtime: number; |
| 236 | real_uploaded: number; |
| 237 | real_downloaded: number; |
| 238 | modcomment: string; |
| 239 | warning_by: number; |
| 240 | warning_times: number; |
| 241 | warning: boolean; |
| 242 | warning_until: string; |
| 243 | download: number; |
| 244 | upload: number; |
| 245 | invited_by: number; |
| 246 | bonus: number; |
| 247 | exp: number; |
| 248 | check_code: string; |
| 249 | reg_type: number; |
| 250 | } |
| 251 | |
| 252 | export interface TorrentSearchResult { |
| 253 | torrent: TorrentEntity; |
| 254 | ownerInfo: UserEntity; |
| 255 | } |
| 256 | |
| 257 | export interface TorrentSearchResponse { |
| 258 | records: TorrentSearchResult[]; |
| 259 | total: number; |
| 260 | size: number; |
| 261 | current: number; |
| 262 | pages: number; |
| 263 | } |
| 264 | |
| 265 | export async function searchTorrents(params: TorrentSearchRequest) { |
| 266 | return request<TorrentSearchResponse>('/api/torrent/search', { |
| 267 | method: 'POST', |
| 268 | data: params, |
| 269 | }); |
Jiarenxiang | 56cbf66 | 2025-06-09 21:46:47 +0800 | [diff] [blame^] | 270 | } |
| 271 | |
| 272 | export async function generatePassKey() { |
| 273 | return request('/api/torrent/generatePassKey', { |
| 274 | method: 'GET', |
| 275 | }); |
| 276 | } |
| 277 | |
| 278 | // 用户注册 |
| 279 | export async function registerUser(userName: string, password: string, passKey: string) { |
| 280 | return request('/api/api/register', { |
| 281 | method: 'POST', |
| 282 | data: { |
| 283 | userName, |
| 284 | password, |
| 285 | passKey, |
| 286 | }, |
| 287 | }); |
Jiarenxiang | 3672848 | 2025-06-07 21:51:26 +0800 | [diff] [blame] | 288 | } |