blob: 35d2312c288046d9bf9f2a4f1a4b059115cc5181 [file] [log] [blame]
86133ec55c542025-04-21 11:51:32 +08001import { request } from '@umijs/max';
2import type {
3 BtTorrent,
4 BtTorrentFile,
5 BtTorrentAnnounce,
6 BtTorrentTag,
7} from '@/pages/Torrent/data'; // 假设你把 data.d.ts 放这里
8
BirdNETMb0f71532025-05-26 17:37:33 +08009/** 下载种子文件 */
10export async function downloadTorrent(torrentId: number) {
11 return request(`/api/system/torrent/download/${torrentId}`, {
12 method: 'get',
13 responseType: 'blob',
14 });
15}
16
86133ec55c542025-04-21 11:51:32 +080017// ================================
18// 种子主表(bt_torrent)接口
19// ================================
20
21/** 查询种子列表 */
Atopos0524878db002025-06-08 22:36:57 +080022export async function listBtTorrent(userId: string) {
23 return request(`/api/system/torrent/recommend`, {
24 method: 'post',
86133ec55c542025-04-21 11:51:32 +080025 });
26}
27
28/** 获取种子详情 */
29export async function getBtTorrent(torrentId: number) {
30 return request<BtTorrent>(`/api/system/torrent/${torrentId}`, {
31 method: 'get',
32 });
33}
34
35/** 新增种子 */
36export async function addBtTorrent(data: BtTorrent) {
37 return request('/api/system/torrent', {
38 method: 'post',
39 data,
40 });
41}
42
43/** 修改种子 */
44export async function updateBtTorrent(data: BtTorrent) {
45 return request('/api/system/torrent', {
46 method: 'put',
47 data,
48 });
49}
50
51/** 删除种子(支持批量) */
52export 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/** 查询种子文件列表 */
63export 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/** 获取文件详情 */
71export async function getBtTorrentFile(id: number) {
BirdNETMb0f71532025-05-26 17:37:33 +080072
86133ec55c542025-04-21 11:51:32 +080073 return request<BtTorrentFile>(`/api/system/file/${id}`, {
74 method: 'get',
75 });
76}
77
78/** 新增文件 */
79export async function addBtTorrentFile(data: BtTorrentFile) {
80 return request('/api/system/file', {
81 method: 'post',
82 data,
83 });
84}
85
86/** 修改文件 */
87export async function updateBtTorrentFile(data: BtTorrentFile) {
88 return request('/api/system/file', {
89 method: 'put',
90 data,
91 });
92}
93
94/** 删除文件(支持批量) */
95export 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 列表 */
106export 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 */
114export async function getBtTorrentAnnounce(id: number) {
115 return request<BtTorrentAnnounce>(`/api/system/announce/${id}`, {
116 method: 'get',
117 });
118}
119
120/** 新增 Tracker */
121export async function addBtTorrentAnnounce(data: BtTorrentAnnounce) {
122 return request('/api/system/announce', {
123 method: 'post',
124 data,
125 });
126}
127
128/** 修改 Tracker */
129export async function updateBtTorrentAnnounce(data: BtTorrentAnnounce) {
130 return request('/api/system/announce', {
131 method: 'put',
132 data,
133 });
134}
135
136/** 删除 Tracker(支持批量) */
137export 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/** 查询标签列表 */
148export 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/** 获取标签详情 */
156export async function getBtTorrentTag(id: number) {
157 return request<BtTorrentTag>(`/api/system/tags/${id}`, {
158 method: 'get',
159 });
160}
161
162/** 新增标签 */
163export async function addBtTorrentTag(data: BtTorrentTag) {
164 return request('/api/system/tags', {
165 method: 'post',
166 data,
167 });
168}
169
170/** 修改标签 */
171export async function updateBtTorrentTag(data: BtTorrentTag) {
172 return request('/api/system/tags', {
173 method: 'put',
174 data,
175 });
176}
861332d0a1792025-04-21 20:45:00 +0800177/**
178 * 上传并解析种子文件
179 * @param file The .torrent file to upload
180 * @returns The parsed torrent data or error message
181 */
182export async function uploadTorrent(file: File) {
183 const formData = new FormData();
184 formData.append('file', file);
86133ec55c542025-04-21 11:51:32 +0800185
861332d0a1792025-04-21 20:45:00 +0800186 return request('/api/system/torrent/uploadTorrent', {
187 method: 'POST',
188 data: formData,
189 headers: {
190 'Content-Type': 'multipart/form-data',
191 },
192 });
193}
86133ec55c542025-04-21 11:51:32 +0800194/** 删除标签(支持批量) */
195export async function removeBtTorrentTag(ids: number[]) {
196 return request(`/api/system/tags/${ids.join(',')}`, {
197 method: 'delete',
198 });
199}