前端
Change-Id: If55994fd11ad8d1f70a52e9c3bd53eded5f37544
diff --git a/src/api/request.js b/src/api/request.js
index 0e06f0a..01da8a3 100644
--- a/src/api/request.js
+++ b/src/api/request.js
@@ -5,7 +5,7 @@
const request = axios.create({
// 关键:不要设置baseURL,或者设置为空字符串
// 这样请求会发送到当前域名(8080),然后被代理转发到8081
- baseURL: process.env.VUE_APP_BASE_API || '/api',
+ baseURL: process.env.VUE_APP_BASE_API || '',
timeout: 10000,
headers: {
// 'Content-Type': 'application/json'
@@ -15,15 +15,27 @@
request.interceptors.request.use(
config => {
const token = localStorage.getItem('token')
- console.log('📤 添加 token 到请求头:', token)
+ console.log('📤 Token长度:', token ? token.length : 0)
+ console.log('📤 Token前50字符:', token ? token.substring(0, 50) + '...' : 'null')
+
if (token) {
+ // 检查token是否过大
+ if (token.length > 8000) {
+ console.warn('⚠️ Token过大,长度:', token.length)
+ // 清除过大的token
+ localStorage.removeItem('token')
+ localStorage.removeItem('tokenInfo')
+ localStorage.removeItem('userInfo')
+ localStorage.removeItem('isLoggedIn')
+ ElMessage.error('登录信息过大,请重新登录')
+ router.push('/login')
+ return Promise.reject(new Error('Token过大'))
+ }
config.headers.Authorization = `Bearer ${token}`
}
console.log('🚀 发送请求:', config.method?.toUpperCase(), config.url)
console.log('📤 请求数据:', config.data)
- console.log('🔍 VUE_APP_BASE_API:', process.env.VUE_APP_BASE_API)
- console.log('🔍 VUE_APP_BACKEND:', process.env.VUE_APP_BACKEND)
return config
},
@@ -59,6 +71,15 @@
ElMessage.error('API接口不存在')
console.error('❌ 请求的URL:', error.config.url)
break
+ case 431:
+ console.error('❌ 请求头太大 (431),可能是Token过大')
+ localStorage.removeItem('token')
+ localStorage.removeItem('tokenInfo')
+ localStorage.removeItem('userInfo')
+ localStorage.removeItem('isLoggedIn')
+ ElMessage.error('登录信息过大,请重新登录')
+ router.push('/login')
+ break
case 500:
ElMessage.error('服务器内部错误')
break
diff --git a/src/api/torrent.js b/src/api/torrent.js
index 586e22c..e49887e 100644
--- a/src/api/torrent.js
+++ b/src/api/torrent.js
@@ -140,16 +140,4 @@
url: `/torrent/download/${infoHash}`,
method: 'get'
})
-}
-
-/**
- * 获取种子下载数
- * @param {string} infoHash - 种子的info hash
- * @returns {Promise}
- */
-export function downloadTorrentNum(infoHash) {
- return request({
- url: `/torrent/${infoHash}/downloads`,
- method: 'get'
- })
}
\ No newline at end of file
diff --git a/src/api/user.js b/src/api/user.js
index 2cfb40c..32073b1 100644
--- a/src/api/user.js
+++ b/src/api/user.js
@@ -7,7 +7,18 @@
*/
getCurrentUser() {
return request({
- url: '/user/profile',
+ url: '/auth/status',
+ method: 'get'
+ })
+ },
+
+ /**
+ * 获取用户分享率和统计信息
+ * @returns {Promise<Object>} 分享率统计信息
+ */
+ getUserRatioInfo() {
+ return request({
+ url: '/torrent/ratio/info',
method: 'get'
})
},