blob: 7118436ec1175a96d0b98c8c198c34a784e2cdf0 [file] [log] [blame]
Akane121765b61a72025-05-17 13:52:25 +08001// src/api/torrent.js
2import { api } from './auth'; // 复用已有的axios实例
3
4export const createTorrent = (torrentName, description, username, category, region, resolution, subtitle, filePath) => {
5 return api.post('/torrent', {
6 torrentName,
7 description,
8 username,
9 category,
10 region,
11 resolution,
12 subtitle,
13 filePath
14 });
15};
16
17export const getTorrents = (page = 1, size = 5) => {
18 return api.get('/torrent', {
19 params: { page, size }
20 });
21};
22
23export const getTorrentDetail = (torrentId) => {
24 return api.get(`/torrent/${torrentId}`).then(response => {
25 // 确保数据结构一致
26 if (response.data && response.data.data) {
27 return {
28 ...response,
29 data: {
30 ...response.data,
31 data: {
32 torrent: response.data.data.post || response.data.data.torrent,
33 comments: response.data.data.comments || []
34 }
35 }
36 };
37 }
38 return response;
39 });
40};
41
42export const likeTorrent = (torrentId) => {
43 return api.post(`/torrent/${torrentId}/like`);
44};
45
46export const addTorrentComment = (torrentId, commentData) => {
47 return api.post(`/torrent/${torrentId}/comments`, commentData);
48};