前段
Change-Id: I718d4d07ea03c6d2b6bcbd4d426c5d1af2201bf4
diff --git a/src/api/torrent.js b/src/api/torrent.js
new file mode 100644
index 0000000..7118436
--- /dev/null
+++ b/src/api/torrent.js
@@ -0,0 +1,48 @@
+// src/api/torrent.js
+import { api } from './auth'; // 复用已有的axios实例
+
+export const createTorrent = (torrentName, description, username, category, region, resolution, subtitle, filePath) => {
+ return api.post('/torrent', {
+ torrentName,
+ description,
+ username,
+ category,
+ region,
+ resolution,
+ subtitle,
+ filePath
+ });
+};
+
+export const getTorrents = (page = 1, size = 5) => {
+ return api.get('/torrent', {
+ params: { page, size }
+ });
+};
+
+export const getTorrentDetail = (torrentId) => {
+ return api.get(`/torrent/${torrentId}`).then(response => {
+ // 确保数据结构一致
+ if (response.data && response.data.data) {
+ return {
+ ...response,
+ data: {
+ ...response.data,
+ data: {
+ torrent: response.data.data.post || response.data.data.torrent,
+ comments: response.data.data.comments || []
+ }
+ }
+ };
+ }
+ return response;
+ });
+};
+
+export const likeTorrent = (torrentId) => {
+ return api.post(`/torrent/${torrentId}/like`);
+};
+
+export const addTorrentComment = (torrentId, commentData) => {
+ return api.post(`/torrent/${torrentId}/comments`, commentData);
+};
\ No newline at end of file