add webuser API
Change-Id: I525da55355631991fd9554346b539c1c09593113
diff --git a/front/src/AnimePage.js b/front/src/AnimePage.js
index d17f3cc..118d8fb 100644
--- a/front/src/AnimePage.js
+++ b/front/src/AnimePage.js
@@ -9,6 +9,7 @@
import AccountCircleIcon from "@mui/icons-material/AccountCircle";
import "./App.css";
import { useNavigate } from "react-router-dom";
+import { API_BASE_URL } from "./config";
const navItems = [
{ label: "电影", icon: <MovieIcon />, path: "/movie" },
@@ -55,7 +56,7 @@
React.useEffect(() => {
// 假设后端接口为 /api/animes?area=大陆
const area = areaTabs[activeTab].label;
- fetch(`http://192.168.5.9:8080/api/get-seed-list-by-tag?tag=${encodeURIComponent(area)}`)
+ fetch(`${API_BASE_URL}/api/get-seed-list-by-tag?tag=${encodeURIComponent(area)}`)
.then(res => res.json())
.then(data => setAnimeList(data))
.catch(() => setAnimeList([]));
diff --git a/front/src/GamePage.js b/front/src/GamePage.js
index 2528acd..1de4d30 100644
--- a/front/src/GamePage.js
+++ b/front/src/GamePage.js
@@ -9,6 +9,7 @@
import AccountCircleIcon from "@mui/icons-material/AccountCircle";
import "./App.css";
import { useNavigate } from "react-router-dom";
+import { API_BASE_URL } from "./config";
const navItems = [
{ label: "电影", icon: <MovieIcon />, path: "/movie" },
@@ -46,7 +47,7 @@
React.useEffect(() => {
const area = areaTabs[activeTab].label;
- fetch(`http://192.168.5.9:8080/api/get-seed-list-by-tag?tag=${encodeURIComponent(area)}`)
+ fetch(`${API_BASE_URL}/api/get-seed-list-by-tag?tag=${encodeURIComponent(area)}`)
.then(res => res.json())
.then(data => setGameList(data))
.catch(() => setGameList([]));
diff --git a/front/src/InfoPage.js b/front/src/InfoPage.js
index 755d922..0ed6ade 100644
--- a/front/src/InfoPage.js
+++ b/front/src/InfoPage.js
@@ -9,6 +9,7 @@
import AccountCircleIcon from "@mui/icons-material/AccountCircle";
import "./App.css";
import { useNavigate } from "react-router-dom";
+import { API_BASE_URL } from "./config";
const navItems = [
{ label: "电影", icon: <MovieIcon />, path: "/movie" },
@@ -55,7 +56,7 @@
React.useEffect(() => {
// 这里假设后端接口为 /api/get-seed-list-by-tag?tag=大陆
const area = areaTabs[activeTab].label;
- fetch(`http://192.168.5.9:8080/api/get-seed-list-by-tag?tag=${encodeURIComponent(area)}`)
+ fetch(`${API_BASE_URL}/api/get-seed-list-by-tag?tag=${encodeURIComponent(area)}`)
.then(res => res.json())
.then(data => {
console.log('资料区返回数据:', data);
diff --git a/front/src/LoginPage.js b/front/src/LoginPage.js
index 59a1b2b..acbde03 100644
--- a/front/src/LoginPage.js
+++ b/front/src/LoginPage.js
@@ -21,7 +21,7 @@
// Simulate successful login
setErrorMessage('');
- navigate('/');
+ navigate('/movie');
};
const handleRegister = () => {
diff --git a/front/src/MoviePage.js b/front/src/MoviePage.js
index c84797b..83ccad1 100644
--- a/front/src/MoviePage.js
+++ b/front/src/MoviePage.js
@@ -9,6 +9,7 @@
import AccountCircleIcon from "@mui/icons-material/AccountCircle";
import { useNavigate } from "react-router-dom";
import "./App.css";
+import { API_BASE_URL } from "./config";
const navItems = [
{ label: "电影", icon: <MovieIcon />, path: "/movie" },
@@ -53,7 +54,7 @@
React.useEffect(() => {
// 这里假设后端接口为 /api/get-seed-list-by-tag?tag=大陆
const area = areaTabs[activeTab].label;
- fetch(`http://192.168.5.9:8080/api/get-seed-list-by-tag?tag=${encodeURIComponent(area)}`)
+ fetch(`${API_BASE_URL}/api/get-seed-list-by-tag?tag=${encodeURIComponent(area)}`)
.then(res => res.json())
.then(data => {
console.log('电影区返回数据:', data);
diff --git a/front/src/MusicPage.js b/front/src/MusicPage.js
index b39b0ee..fb03fe1 100644
--- a/front/src/MusicPage.js
+++ b/front/src/MusicPage.js
@@ -9,6 +9,7 @@
import AccountCircleIcon from "@mui/icons-material/AccountCircle";
import "./App.css";
import { useNavigate } from "react-router-dom";
+import { API_BASE_URL } from "./config";
const navItems = [
{ label: "电影", icon: <MovieIcon />, path: "/movie" },
@@ -53,7 +54,7 @@
React.useEffect(() => {
// 假设后端接口为 /api/musics?area=大陆
const area = areaTabs[activeTab].label;
- fetch(`http://192.168.5.9:8080/api/get-seed-list-by-tag?tag=${encodeURIComponent(area)}`)
+ fetch(`${API_BASE_URL}/api/get-seed-list-by-tag?tag=${encodeURIComponent(area)}`)
.then(res => res.json())
.then(data => setMusicList(data))
.catch(() => setMusicList([]));
diff --git a/front/src/PublishPage.js b/front/src/PublishPage.js
index abd4ee2..c6b80c4 100644
--- a/front/src/PublishPage.js
+++ b/front/src/PublishPage.js
@@ -1,6 +1,7 @@
import React, { useState } from 'react';
import './App.css';
import './PublishPage.css';
+import { API_BASE_URL } from "./config";
const PublishPage = () => {
const [formData, setFormData] = useState({
@@ -36,8 +37,11 @@
}
};
- const handleSubmit = (e) => {
+ const handleSubmit = async (e) => {
e.preventDefault();
+
+ console.log('Form Data Submitted:', formData);
+
// 假设userid和tag可以从表单或用户信息中获取,这里用示例数据
const userid = '550e8400-e29b-41d4-a716-446655440000';
const tag = formData.type ? formData.type : '高清';
@@ -55,7 +59,17 @@
// console.log(data.get('tag'));
try {
+
const response = await fetch('http://192.168.5.9:8080/api/save-torrent', {
+
+ // console.log(data.get('userid'));
+ // console.log(data.get('title'));
+ const response = await fetch(`${API_BASE_URL}/api/save-torrent`, {
+
+ // console.log(data.get('userid'));
+ // console.log(data.get('title'));
+ const response = await fetch(`${API_BASE_URL}/api/save-torrent`, {
+
method: 'POST',
body: data,
});
@@ -67,6 +81,7 @@
} catch (err) {
alert('网络错误');
}
+
};
return (
diff --git a/front/src/SportPage.js b/front/src/SportPage.js
index 3299a93..4c9d17d 100644
--- a/front/src/SportPage.js
+++ b/front/src/SportPage.js
@@ -9,6 +9,7 @@
import AccountCircleIcon from "@mui/icons-material/AccountCircle";
import "./App.css";
import { useNavigate } from "react-router-dom";
+import { API_BASE_URL } from "./config";
const navItems = [
{ label: "电影", icon: <MovieIcon />, path: "/movie" },
@@ -55,7 +56,7 @@
React.useEffect(() => {
// 假设后端接口为 /api/sports?area=篮球
const area = areaTabs[activeTab].label;
- fetch(`http://192.168.5.9:8080/api/get-seed-list-by-tag?tag=${encodeURIComponent(area)}`)
+ fetch(`${API_BASE_URL}/api/get-seed-list-by-tag?tag=${encodeURIComponent(area)}`)
.then(res => res.json())
.then(data => setSportList(data))
.catch(() => setSportList([]));
diff --git a/front/src/TVPage.js b/front/src/TVPage.js
index bf1db6c..216dfcc 100644
--- a/front/src/TVPage.js
+++ b/front/src/TVPage.js
@@ -9,6 +9,7 @@
import AccountCircleIcon from "@mui/icons-material/AccountCircle";
import { useNavigate } from "react-router-dom";
import "./App.css";
+import { API_BASE_URL } from "./config";
const navItems = [
{ label: "电影", icon: <MovieIcon />, path: "/movie" },
@@ -45,7 +46,7 @@
React.useEffect(() => {
// 假设后端接口为 /api/tvs?area=大陆
const area = areaTabs[activeTab].label;
- fetch(`http://192.168.5.9:8080/api/get-seed-list-by-tag?tag=${encodeURIComponent(area)}`)
+ fetch(`${API_BASE_URL}/api/get-seed-list-by-tag?tag=${encodeURIComponent(area)}`)
.then(res => res.json())
.then(data => setTvList(data))
.catch(() => setTvList([]));
diff --git a/front/src/TorrentDetailPage.js b/front/src/TorrentDetailPage.js
index 8d3ee43..cc2dd24 100644
--- a/front/src/TorrentDetailPage.js
+++ b/front/src/TorrentDetailPage.js
@@ -1,6 +1,7 @@
import React from 'react';
import { useParams } from 'react-router-dom';
import './App.css';
+import { API_BASE_URL } from "./config";
export default function TorrentDetailPage() {
const { torrentId } = useParams();
@@ -13,7 +14,7 @@
const handleClick = () => {
// 构造下载 URL,包含 userId 和 torrentId 参数
console.log(torrentId)
- const downloadUrl = `http://192.168.5.9:8080/api/get-torrent?userId=${encodeURIComponent(userId)}&torrentId=${encodeURIComponent(torrentId)}`;
+ const downloadUrl = `${API_BASE_URL}/api/get-torrent?userId=${encodeURIComponent(userId)}&torrentId=${encodeURIComponent(torrentId)}`;
// 发起 GET 请求下载文件
fetch(downloadUrl)
@@ -43,7 +44,7 @@
React.useEffect(() => {
setLoading(true);
setError(null);
- fetch(`http://192.168.5.9:8080/api/torrent-detail?id=${encodeURIComponent(torrentId)}`)
+ fetch(`${API_BASE_URL}/api/torrent-detail?id=${encodeURIComponent(torrentId)}`)
.then(res => {
if (!res.ok) throw new Error('网络错误');
return res.json();
diff --git a/front/src/UserProfile.js b/front/src/UserProfile.js
index 4737033..753e901 100644
--- a/front/src/UserProfile.js
+++ b/front/src/UserProfile.js
@@ -1,6 +1,7 @@
import React, { useState, useEffect } from "react";
import AccountCircleIcon from "@mui/icons-material/AccountCircle";
import { useNavigate } from "react-router-dom";
+import { API_BASE_URL } from "./config";
import "./App.css";
export default function UserProfile() {
@@ -31,11 +32,13 @@
const userid = "550e8400-e29b-41d4-a716-446655440000"; // 示例userid
if (!userid) return;
try {
- const res = await fetch(`/api/user-profile?userid=${userid}`);
+ const res = await fetch(`${API_BASE_URL}/api/user-profile?userid=${userid}`);
+
if (res.ok) {
const data = await res.json();
setUserInfo(data);
setTempUserInfo(data);
+ // console.log(data);
}
} catch (err) {
// 可以根据需要处理错误
@@ -52,7 +55,7 @@
const userid = "550e8400-e29b-41d4-a716-446655440000"; // 示例userid
if (!userid) return;
try {
- const res = await fetch(`/api/user-seeds?userid=${userid}`);
+ const res = await fetch(`${API_BASE_URL}/api/user-seeds?userid=${userid}`);
if (res.ok) {
const data = await res.json();
setUserSeeds(data);
@@ -71,7 +74,7 @@
const userid = "550e8400-e29b-41d4-a716-446655440000"; // 示例userid
if (!userid) return;
try {
- const res = await fetch(`/api/user-stats?userid=${userid}`);
+ const res = await fetch(`${API_BASE_URL}/api/user-stats?userid=${userid}`);
if (res.ok) {
const data = await res.json();
setUserStats(data);
@@ -88,12 +91,18 @@
};
const handleSave = async () => {
+ if (tempUserInfo.gender === "男性"){
+ tempUserInfo.gender = "m";
+ }else if (tempUserInfo.gender === "女性"){
+ tempUserInfo.gender = "f";
+ }
setUserInfo({ ...tempUserInfo });
+ console.log("保存的用户信息:", tempUserInfo);
// 获取userid
// const userid = localStorage.getItem("userid");
const userid = "550e8400-e29b-41d4-a716-446655440000"; // 示例userid
try {
- const res = await fetch('/api/change-profile', {
+ const res = await fetch(`${API_BASE_URL}/api/change-profile`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
@@ -112,9 +121,9 @@
};
const handleAvatarClick = () => {
- const avatarUrl = prompt("请输入头像的URL:");
- if (avatarUrl) {
- setTempUserInfo({ ...tempUserInfo, avatar: avatarUrl });
+ const pictureUrl = prompt("请输入头像的URL:");
+ if (pictureUrl) {
+ setTempUserInfo({ ...tempUserInfo, avatar_url: pictureUrl });
}
};
@@ -125,7 +134,7 @@
<div style={{ display: 'flex', flexDirection: 'column', alignItems: 'center', marginBottom: 16 }}>
<div onClick={handleAvatarClick} style={{ cursor: 'pointer', position: 'relative' }}>
<AccountCircleIcon style={{ fontSize: 90, color: '#1a237e', marginBottom: 12 }} />
- {tempUserInfo.avatar && (
+ {tempUserInfo.avatar_url && (
<img
src={tempUserInfo.avatar_url}
alt="用户头像"
@@ -166,7 +175,7 @@
<span
style={{ flex: 1, padding: '6px 10px', borderRadius: 7, border: '1px solid #b2b2b2', minWidth: 0, fontSize: 15, backgroundColor: '#f5f5f5', color: '#888' }}
>
- {tempUserInfo.invite_left}
+ {tempUserInfo.invite_left || "0"}
</span>
</div>
<div style={{ marginBottom: 18, display: 'flex', alignItems: 'center' }}>
@@ -211,7 +220,9 @@
cursor: 'pointer',
}}
>
- {tempUserInfo.gender || "性别"}
+ {tempUserInfo.gender === 'm' ? '男性'
+ : tempUserInfo.gender === 'f' ? '女性'
+ : '性别'}
</button>
{tempUserInfo.showGenderOptions && (
<ul
@@ -229,20 +240,18 @@
zIndex: 10,
}}
>
- {["男", "女", "跨性别男", "跨性别女", "无性别"].map((option) => (
+ {[{ value: 'm', label: '男性' }, { value: 'f', label: '女性' }].map(opt => (
<li
- key={option}
- onClick={() => {
- setTempUserInfo({ ...tempUserInfo, gender: option, showGenderOptions: false });
- }}
+ key={opt.value}
+ onClick={() => setTempUserInfo({ ...tempUserInfo, gender: opt.value, showGenderOptions: false })}
style={{
padding: '6px 10px',
cursor: 'pointer',
borderBottom: '1px solid #e0e0e0',
- backgroundColor: option === tempUserInfo.gender ? '#f0f0f0' : '#fff',
+ backgroundColor: tempUserInfo.gender === opt.value ? '#f0f0f0' : '#fff',
}}
>
- {option}
+ {opt.label}
</li>
))}
</ul>
@@ -284,27 +293,29 @@
onClick={e => {
// 阻止点击删除按钮时跳转
if (e.target.classList.contains('delete-btn')) return;
- navigate(`/torrent/${seed.seed_id}`);
+ navigate(`/torrent/${seed.seedid}`);
}}
>
<span style={{ flex: 2, fontWeight: 500, color: '#1a237e', textDecoration: 'underline' }}>{seed.title}</span>
<span style={{ flex: 1, color: '#5c6bc0' }}>{seed.tags}</span>
- <span style={{ flex: 1, color: '#ff9800', textAlign: 'right' }}>人气: {seed.popularity}</span>
+ <span style={{ flex: 1, color: '#ff9800', textAlign: 'right' }}>人气: {seed.downloadtimes}</span>
<button
className="delete-btn"
style={{ marginLeft: 18, background: '#e53935', color: '#fff', border: 'none', borderRadius: 6, padding: '4px 14px', cursor: 'pointer', fontSize: 14 }}
onClick={async (e) => {
e.stopPropagation();
// const userid = localStorage.getItem("userid");
- const userid = "550e8400-e29b-41d4-a716-446655440000"; // 示例userid
+ // const userid = "550e8400-e29b-41d4-a716-446655440000"; // 示例userid
try {
- const res = await fetch('/api/delete-seed', {
+
+ const res = await fetch(`${API_BASE_URL}/api/delete-seed`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
- body: JSON.stringify({ seed_id: seed.seed_id, userid }),
+ body: JSON.stringify({ seedid: seed.seedid }),
});
+ // console.log(seed.seedid);
if (res.ok) {
- setUserSeeds(userSeeds.filter((s, i) => (s.seed_id || i) !== (seed.seed_id || idx)));
+ setUserSeeds(userSeeds.filter((s, i) => (s.seedid || i) !== (seed.seedid || idx)));
} else {
alert('删除失败,请重试');
}
diff --git a/front/src/config.js b/front/src/config.js
new file mode 100644
index 0000000..d651f0d
--- /dev/null
+++ b/front/src/config.js
@@ -0,0 +1,2 @@
+// src/config.js
+export const API_BASE_URL = "http://10.126.59.25:8081";