修复完善笔记详情内容加载 (#301)
* feat: add like and favorite functionality for feeds - Implemented handleLikeFeed and handleFavoriteFeed methods in mcp_handlers.go to manage liking and favoriting feeds. - Added LikeFavoriteArgs struct in mcp_server.go for handling parameters. - Registered new MCP tools for liking and favoriting feeds in registerTools function. - Introduced LikeFeed and FavoriteFeed methods in XiaohongshuService to interact with the respective actions. - Created LikeFavoriteAction in a new file to encapsulate the logic for liking and favoriting feeds on the Xiaohongshu platform. * "优化评论反馈逻辑:简化回复按钮查找和点击流程 * "Fix-build-errors" * refactor: streamline like and favorite actions in LikeFavoriteAction - Introduced a generic method `performInteractAction` to handle both liking and favoriting feeds, reducing code duplication. - Updated logging to reflect the action type being performed (like or favorite). - Enhanced state verification after interaction to ensure accurate feedback on success or failure. - Removed the `clickLastMatch` function, simplifying the interaction logic. * "Add-unlike-and-unfavorite-functionality" * "Refactor-performInteractAction-function" * "Refactor-split-LikeFavoriteAction-into-separate-actions" * "Add-content-length-validation-for-publish" * refactor: improve comment posting logic with enhanced error handling and stability checks - Updated the PostComment method to include error handling for navigation and element interactions. - Replaced sleep calls with more reliable wait mechanisms to ensure page stability. - Added checks for the presence of input elements and improved logging for better debugging. * feat: add reply comment functionality for Xiaohongshu feeds - Implemented handleReplyComment method in mcp_handlers.go to manage replying to comments on feeds. - Introduced ReplyCommentArgs struct in mcp_server.go for handling parameters related to comment replies. - Registered a new MCP tool for replying to comments in the registerTools function. - Added ReplyCommentToFeed method in service.go to interact with the Xiaohongshu platform for comment replies. - Enhanced error handling for missing parameters in the reply process. * refactor: enhance reply comment functionality with improved error handling and response structure - Simplified error handling in handleReplyComment to check for both comment_id and user_id simultaneously. - Updated response message to include both Comment ID and User ID upon successful reply. - Modified ReplyCommentArgs struct to make comment_id and user_id optional. - Renamed MCP tool for replying to comments for clarity. * feat(feed): Migrate loadAllComments feature for GetFeedDetail * fix * fix * fix * fix * fix: 添加更多自定义选项操作 * fix * fix:优化代码结构 * chore: update dependencies and implement retry logic for page interactions --------- Co-authored-by: chekayo <9827969+chekayo@user.noreply.gitee.com>
This commit is contained in:
@@ -4,11 +4,13 @@ import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/sirupsen/logrus"
|
||||
"github.com/xpzouying/xiaohongshu-mcp/cookies"
|
||||
"github.com/xpzouying/xiaohongshu-mcp/xiaohongshu"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
// MCP 工具处理函数
|
||||
@@ -35,7 +37,7 @@ func (s *AppServer) handleCheckLoginStatus(ctx context.Context) *MCPToolResult {
|
||||
} else {
|
||||
resultText = fmt.Sprintf("❌ 未登录\n\n请使用 get_login_qrcode 工具获取二维码进行登录。")
|
||||
}
|
||||
|
||||
|
||||
return &MCPToolResult{
|
||||
Content: []MCPContent{{
|
||||
Type: "text",
|
||||
@@ -336,9 +338,67 @@ func (s *AppServer) handleGetFeedDetail(ctx context.Context, args map[string]any
|
||||
}
|
||||
}
|
||||
|
||||
logrus.Infof("MCP: 获取Feed详情 - Feed ID: %s", feedID)
|
||||
loadAll := false
|
||||
if raw, ok := args["load_all_comments"]; ok {
|
||||
switch v := raw.(type) {
|
||||
case bool:
|
||||
loadAll = v
|
||||
case string:
|
||||
if parsed, err := strconv.ParseBool(v); err == nil {
|
||||
loadAll = parsed
|
||||
}
|
||||
case float64:
|
||||
loadAll = v != 0
|
||||
}
|
||||
}
|
||||
|
||||
result, err := s.xiaohongshuService.GetFeedDetail(ctx, feedID, xsecToken)
|
||||
// 解析评论配置参数,如果未提供则使用默认值
|
||||
config := xiaohongshu.DefaultCommentLoadConfig()
|
||||
|
||||
if raw, ok := args["click_more_replies"]; ok {
|
||||
switch v := raw.(type) {
|
||||
case bool:
|
||||
config.ClickMoreReplies = v
|
||||
case string:
|
||||
if parsed, err := strconv.ParseBool(v); err == nil {
|
||||
config.ClickMoreReplies = parsed
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if raw, ok := args["max_replies_threshold"]; ok {
|
||||
switch v := raw.(type) {
|
||||
case float64:
|
||||
config.MaxRepliesThreshold = int(v)
|
||||
case string:
|
||||
if parsed, err := strconv.Atoi(v); err == nil {
|
||||
config.MaxRepliesThreshold = parsed
|
||||
}
|
||||
case int:
|
||||
config.MaxRepliesThreshold = v
|
||||
}
|
||||
}
|
||||
|
||||
if raw, ok := args["max_comment_items"]; ok {
|
||||
switch v := raw.(type) {
|
||||
case float64:
|
||||
config.MaxCommentItems = int(v)
|
||||
case string:
|
||||
if parsed, err := strconv.Atoi(v); err == nil {
|
||||
config.MaxCommentItems = parsed
|
||||
}
|
||||
case int:
|
||||
config.MaxCommentItems = v
|
||||
}
|
||||
}
|
||||
|
||||
if raw, ok := args["scroll_speed"].(string); ok && raw != "" {
|
||||
config.ScrollSpeed = raw
|
||||
}
|
||||
|
||||
logrus.Infof("MCP: 获取Feed详情 - Feed ID: %s, loadAllComments=%v, config=%+v", feedID, loadAll, config)
|
||||
|
||||
result, err := s.xiaohongshuService.GetFeedDetailWithConfig(ctx, feedID, xsecToken, loadAll, config)
|
||||
if err != nil {
|
||||
return &MCPToolResult{
|
||||
Content: []MCPContent{{
|
||||
|
||||
Reference in New Issue
Block a user