Update on frontend pages May 27th
Change-Id: I452e5a0ae089114f5b68920e507e56db897856f8
diff --git a/frontend/my-app/src/services/torrentService.js b/frontend/my-app/src/services/torrentService.js
new file mode 100644
index 0000000..a50f8ac
--- /dev/null
+++ b/frontend/my-app/src/services/torrentService.js
@@ -0,0 +1,28 @@
+// ./services/torrentService.js
+import axios from 'axios';
+
+// IMPORTANT: Replace with your actual backend API URL
+const API_BASE_URL = 'http://localhost:5000/api';
+
+export const uploadTorrent = async (formData) => {
+ try {
+ const response = await axios.post(`${API_BASE_URL}/torrents/upload`, formData, {
+ headers: {
+ 'Content-Type': 'multipart/form-data', // Essential for file uploads
+ // Add any authentication tokens here if your backend requires them
+ // 'Authorization': `Bearer ${localStorage.getItem('authToken')}`
+ },
+ onUploadProgress: (progressEvent) => {
+ // You can use this to show upload progress to the user
+ const percentCompleted = Math.round((progressEvent.loaded * 100) / progressEvent.total);
+ console.log(`Upload progress: ${percentCompleted}%`);
+ // You could pass this percentage back to the component via a callback
+ },
+ });
+ return response.data; // Your backend should return the parsed torrent info here
+ } catch (error) {
+ console.error('Error in uploadTorrent service:', error.response ? error.response.data : error.message);
+ // Throw a more specific error message based on backend response if available
+ throw new Error(error.response?.data?.message || '文件上传失败,请稍后再试。');
+ }
+};
\ No newline at end of file