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