blob: 4a97406a264f0202ae642c23ee2fac097fc4f159 [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,
148 requestType: 'form',
149 responseType: 'blob',
150 });
151}
152
153// 更新种子
154export async function updateTorrent(entity: TorrentEntity) {
155 return request('/api/torrent/update', {
156 method: 'POST',
157 data: entity,
158 });
159}
160
161// 删除种子
162export async function deleteTorrent(ids: number[]) {
163 return request('/api/torrent/delete', {
164 method: 'POST',
165 data: ids,
166 });
167}
168
169// 获取服务器Tracker
170export async function getTracker() {
171 return request('/api/torrent/tracker', {
172 method: 'POST',
173 });
174}