Akane1217 | 65b61a7 | 2025-05-17 13:52:25 +0800 | [diff] [blame^] | 1 | // src/api/torrent.js
|
| 2 | import { api } from './auth'; // 复用已有的axios实例
|
| 3 |
|
| 4 | export 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 |
|
| 17 | export const getTorrents = (page = 1, size = 5) => {
|
| 18 | return api.get('/torrent', {
|
| 19 | params: { page, size }
|
| 20 | });
|
| 21 | };
|
| 22 |
|
| 23 | export 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 |
|
| 42 | export const likeTorrent = (torrentId) => {
|
| 43 | return api.post(`/torrent/${torrentId}/like`);
|
| 44 | };
|
| 45 |
|
| 46 | export const addTorrentComment = (torrentId, commentData) => {
|
| 47 | return api.post(`/torrent/${torrentId}/comments`, commentData);
|
| 48 | }; |