合并stash修改:优化用户认证和API接口配置
Change-Id: Ied7da456956b0c9e5d8db43aa22e0adba690ea65
diff --git a/Merge/front/src/api/search_jwlll.js b/Merge/front/src/api/search_jwlll.js
index 7568f1d..085507b 100644
--- a/Merge/front/src/api/search_jwlll.js
+++ b/Merge/front/src/api/search_jwlll.js
@@ -1,7 +1,11 @@
// 搜索推荐算法相关的API接口
-// 对应 JWLLL 后端服务
+// 仅首页推荐和搜索使用 JWLLL 后端服务
+// 其他功能使用对应的后端服务
-const BASE_URL = 'http://10.126.59.25:5717'
+// JWLLL 后端服务 - 仅用于推荐和搜索
+const JWLLL_BASE_URL = 'http://10.126.59.25:5717'
+// WZY 后端服务 - 用于帖子详情、点赞、评论等
+const WZY_BASE_URL = 'http://10.126.59.25:5714'
// 通用请求函数
const request = async (url, options = {}) => {
@@ -20,11 +24,13 @@
}
}
-// 搜索API
+// 搜索推荐API
export const searchAPI = {
+ // ===== 推荐和搜索功能 - 使用 JWLLL 服务 =====
+
// 搜索内容
search: async (keyword, category = undefined) => {
- return await request(`${BASE_URL}/search`, {
+ return await request(`${JWLLL_BASE_URL}/search`, {
method: 'POST',
body: JSON.stringify({ keyword, category })
})
@@ -32,12 +38,12 @@
// 获取用户标签
getUserTags: async (userId) => {
- return await request(`${BASE_URL}/user_tags?user_id=${userId}`)
+ return await request(`${JWLLL_BASE_URL}/user_tags?user_id=${userId}`)
},
// 标签推荐
recommendByTags: async (userId, tags) => {
- return await request(`${BASE_URL}/recommend_tags`, {
+ return await request(`${JWLLL_BASE_URL}/recommend_tags`, {
method: 'POST',
body: JSON.stringify({ user_id: userId, tags })
})
@@ -45,52 +51,73 @@
// 协同过滤推荐
userBasedRecommend: async (userId, topN = 20) => {
- return await request(`${BASE_URL}/user_based_recommend`, {
+ return await request(`${JWLLL_BASE_URL}/user_based_recommend`, {
method: 'POST',
body: JSON.stringify({ user_id: userId, top_n: topN })
})
},
+ // ===== 其他功能 - 使用 WZY 服务 =====
+
// 获取帖子详情
getPostDetail: async (postId) => {
- return await request(`${BASE_URL}/post/${postId}`)
+ return await request(`${WZY_BASE_URL}/posts/${postId}`)
},
-
// 点赞帖子
likePost: async (postId, userId) => {
- return await request(`${BASE_URL}/like`, {
+ return await request(`${WZY_BASE_URL}/posts/${postId}/like`, {
method: 'POST',
- body: JSON.stringify({ post_id: postId, user_id: userId })
+ body: JSON.stringify({ user_id: userId })
})
},
// 取消点赞
unlikePost: async (postId, userId) => {
- return await request(`${BASE_URL}/unlike`, {
- method: 'POST',
- body: JSON.stringify({ post_id: postId, user_id: userId })
+ return await request(`${WZY_BASE_URL}/posts/${postId}/like`, {
+ method: 'DELETE',
+ body: JSON.stringify({ user_id: userId })
})
},
// 添加评论
addComment: async (postId, userId, content) => {
- return await request(`${BASE_URL}/comment`, {
+ return await request(`${WZY_BASE_URL}/posts/${postId}/comments`, {
method: 'POST',
- body: JSON.stringify({ post_id: postId, user_id: userId, content })
+ body: JSON.stringify({ user_id: userId, content })
})
- },
-
- // 获取评论
+ }, // 获取评论
getComments: async (postId) => {
- return await request(`${BASE_URL}/comments/${postId}`)
+ const comments = await request(`${WZY_BASE_URL}/posts/${postId}/comments`)
+ // 适配数据格式,WZY服务返回数组,而前端期望 {comments: [...]}
+ // 同时转换字段名以适配前端期望的格式
+ const adaptedComments = Array.isArray(comments) ? comments.map(comment => ({
+ ...comment,
+ user_name: comment.user_name || `用户${comment.user_id}`, // 如果没有用户名,使用用户ID生成
+ create_time: comment.created_at // 将 created_at 映射为 create_time
+ })) : []
+ return { comments: adaptedComments }
},
-
// 上传帖子
uploadPost: async (postData) => {
- return await request(`${BASE_URL}/upload`, {
+ // 转换数据格式以适配 WZY 服务
+ const payload = {
+ user_id: postData.user_id || 1, // 默认用户ID
+ title: postData.title,
+ content: postData.content,
+ type: postData.type || 'text', // 默认为文本类型
+ media_urls: postData.media_files || [],
+ status: 'published' // 直接发布,不需要审核
+ }
+
+ const result = await request(`${WZY_BASE_URL}/posts`, {
method: 'POST',
- body: JSON.stringify(postData)
+ body: JSON.stringify(payload)
})
+
+ // 注意:WZY 服务目前不支持标签功能,tags 会被忽略
+ // 如果需要标签功能,需要额外的API调用或使用支持标签的服务
+
+ return result
}
}