blob: e52615144e59fdd2f4c74bfd4480f9ad058134af [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/** 查询种子列表 */
22export 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/** 获取种子详情 */
30export async function getBtTorrent(torrentId: number) {
31 return request<BtTorrent>(`/api/system/torrent/${torrentId}`, {
32 method: 'get',
33 });
34}
35
36/** 新增种子 */
37export async function addBtTorrent(data: BtTorrent) {
38 return request('/api/system/torrent', {
39 method: 'post',
40 data,
41 });
42}
43
44/** 修改种子 */
45export async function updateBtTorrent(data: BtTorrent) {
46 return request('/api/system/torrent', {
47 method: 'put',
48 data,
49 });
50}
51
52/** 删除种子(支持批量) */
53export 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/** 查询种子文件列表 */
64export 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/** 获取文件详情 */
72export async function getBtTorrentFile(id: number) {
BirdNETMb0f71532025-05-26 17:37:33 +080073
86133ec55c542025-04-21 11:51:32 +080074 return request<BtTorrentFile>(`/api/system/file/${id}`, {
75 method: 'get',
76 });
77}
78
79/** 新增文件 */
80export async function addBtTorrentFile(data: BtTorrentFile) {
81 return request('/api/system/file', {
82 method: 'post',
83 data,
84 });
85}
86
87/** 修改文件 */
88export async function updateBtTorrentFile(data: BtTorrentFile) {
89 return request('/api/system/file', {
90 method: 'put',
91 data,
92 });
93}
94
95/** 删除文件(支持批量) */
96export 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 列表 */
107export 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 */
115export async function getBtTorrentAnnounce(id: number) {
116 return request<BtTorrentAnnounce>(`/api/system/announce/${id}`, {
117 method: 'get',
118 });
119}
120
121/** 新增 Tracker */
122export async function addBtTorrentAnnounce(data: BtTorrentAnnounce) {
123 return request('/api/system/announce', {
124 method: 'post',
125 data,
126 });
127}
128
129/** 修改 Tracker */
130export async function updateBtTorrentAnnounce(data: BtTorrentAnnounce) {
131 return request('/api/system/announce', {
132 method: 'put',
133 data,
134 });
135}
136
137/** 删除 Tracker(支持批量) */
138export 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/** 查询标签列表 */
149export 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/** 获取标签详情 */
157export async function getBtTorrentTag(id: number) {
158 return request<BtTorrentTag>(`/api/system/tags/${id}`, {
159 method: 'get',
160 });
161}
162
163/** 新增标签 */
164export async function addBtTorrentTag(data: BtTorrentTag) {
165 return request('/api/system/tags', {
166 method: 'post',
167 data,
168 });
169}
170
171/** 修改标签 */
172export async function updateBtTorrentTag(data: BtTorrentTag) {
173 return request('/api/system/tags', {
174 method: 'put',
175 data,
176 });
177}
861332d0a1792025-04-21 20:45:00 +0800178/**
179 * 上传并解析种子文件
180 * @param file The .torrent file to upload
181 * @returns The parsed torrent data or error message
182 */
183export async function uploadTorrent(file: File) {
184 const formData = new FormData();
185 formData.append('file', file);
86133ec55c542025-04-21 11:51:32 +0800186
861332d0a1792025-04-21 20:45:00 +0800187 return request('/api/system/torrent/uploadTorrent', {
188 method: 'POST',
189 data: formData,
190 headers: {
191 'Content-Type': 'multipart/form-data',
192 },
193 });
194}
86133ec55c542025-04-21 11:51:32 +0800195/** 删除标签(支持批量) */
196export async function removeBtTorrentTag(ids: number[]) {
197 return request(`/api/system/tags/${ids.join(',')}`, {
198 method: 'delete',
199 });
200}