* 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>
94 lines
2.8 KiB
Go
94 lines
2.8 KiB
Go
package main
|
||
|
||
import "github.com/xpzouying/xiaohongshu-mcp/xiaohongshu"
|
||
|
||
// HTTP API 响应类型
|
||
|
||
// ErrorResponse 错误响应
|
||
type ErrorResponse struct {
|
||
Error string `json:"error"`
|
||
Code string `json:"code"`
|
||
Details any `json:"details,omitempty"`
|
||
}
|
||
|
||
// SuccessResponse 成功响应
|
||
type SuccessResponse struct {
|
||
Success bool `json:"success"`
|
||
Data any `json:"data"`
|
||
Message string `json:"message,omitempty"`
|
||
}
|
||
|
||
// MCP 相关类型(用于内部转换)
|
||
|
||
// MCPToolResult MCP 工具结果(内部使用)
|
||
type MCPToolResult struct {
|
||
Content []MCPContent `json:"content"`
|
||
IsError bool `json:"isError,omitempty"`
|
||
}
|
||
|
||
// MCPContent MCP 内容(内部使用)
|
||
type MCPContent struct {
|
||
Type string `json:"type"`
|
||
Text string `json:"text"`
|
||
MimeType string `json:"mimeType"`
|
||
Data string `json:"data"`
|
||
}
|
||
|
||
// CommentLoadConfig 评论加载配置
|
||
type CommentLoadConfig struct {
|
||
// 是否点击"更多回复"按钮
|
||
ClickMoreReplies bool `json:"click_more_replies,omitempty"`
|
||
// 回复数量阈值,超过这个数量的"更多"按钮将被跳过(0表示不跳过任何)
|
||
MaxRepliesThreshold int `json:"max_replies_threshold,omitempty"`
|
||
// 最大加载评论数(comment-item数量),0表示加载所有
|
||
MaxCommentItems int `json:"max_comment_items,omitempty"`
|
||
// 滚动速度等级: slow(慢速), normal(正常), fast(快速)
|
||
ScrollSpeed string `json:"scroll_speed,omitempty"`
|
||
}
|
||
|
||
// FeedDetailRequest Feed详情请求
|
||
type FeedDetailRequest struct {
|
||
FeedID string `json:"feed_id" binding:"required"`
|
||
XsecToken string `json:"xsec_token" binding:"required"`
|
||
LoadAllComments bool `json:"load_all_comments,omitempty"`
|
||
CommentConfig *CommentLoadConfig `json:"comment_config,omitempty"`
|
||
}
|
||
|
||
type SearchFeedsRequest struct {
|
||
Keyword string `json:"keyword" binding:"required"`
|
||
Filters xiaohongshu.FilterOption `json:"filters,omitempty"`
|
||
}
|
||
|
||
// FeedDetailResponse Feed详情响应
|
||
type FeedDetailResponse struct {
|
||
FeedID string `json:"feed_id"`
|
||
Data any `json:"data"`
|
||
}
|
||
|
||
// PostCommentRequest 发表评论请求
|
||
type PostCommentRequest struct {
|
||
FeedID string `json:"feed_id" binding:"required"`
|
||
XsecToken string `json:"xsec_token" binding:"required"`
|
||
Content string `json:"content" binding:"required"`
|
||
}
|
||
|
||
// PostCommentResponse 发表评论响应
|
||
type PostCommentResponse struct {
|
||
FeedID string `json:"feed_id"`
|
||
Success bool `json:"success"`
|
||
Message string `json:"message"`
|
||
}
|
||
|
||
// UserProfileRequest 用户主页请求
|
||
type UserProfileRequest struct {
|
||
UserID string `json:"user_id" binding:"required"`
|
||
XsecToken string `json:"xsec_token" binding:"required"`
|
||
}
|
||
|
||
// ActionResult 通用动作响应(点赞/收藏等)
|
||
type ActionResult struct {
|
||
FeedID string `json:"feed_id"`
|
||
Success bool `json:"success"`
|
||
Message string `json:"message"`
|
||
}
|