feat: add delete cookies functionality for login reset (#275)
This commit is contained in:
@@ -5,6 +5,7 @@ import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"github.com/sirupsen/logrus"
|
||||
"github.com/xpzouying/xiaohongshu-mcp/cookies"
|
||||
"github.com/xpzouying/xiaohongshu-mcp/xiaohongshu"
|
||||
"strings"
|
||||
"time"
|
||||
@@ -27,7 +28,14 @@ func (s *AppServer) handleCheckLoginStatus(ctx context.Context) *MCPToolResult {
|
||||
}
|
||||
}
|
||||
|
||||
resultText := fmt.Sprintf("登录状态检查成功: %+v", status)
|
||||
// 根据 IsLoggedIn 判断并返回友好的提示
|
||||
var resultText string
|
||||
if status.IsLoggedIn {
|
||||
resultText = fmt.Sprintf("✅ 已登录\n用户名: %s\n\n你可以使用其他功能了。", status.Username)
|
||||
} else {
|
||||
resultText = fmt.Sprintf("❌ 未登录\n\n请使用 get_login_qrcode 工具获取二维码进行登录。")
|
||||
}
|
||||
|
||||
return &MCPToolResult{
|
||||
Content: []MCPContent{{
|
||||
Type: "text",
|
||||
@@ -76,6 +84,28 @@ func (s *AppServer) handleGetLoginQrcode(ctx context.Context) *MCPToolResult {
|
||||
return &MCPToolResult{Content: contents}
|
||||
}
|
||||
|
||||
// handleDeleteCookies 处理删除 cookies 请求,用于登录重置
|
||||
func (s *AppServer) handleDeleteCookies(ctx context.Context) *MCPToolResult {
|
||||
logrus.Info("MCP: 删除 cookies,重置登录状态")
|
||||
|
||||
err := s.xiaohongshuService.DeleteCookies(ctx)
|
||||
if err != nil {
|
||||
return &MCPToolResult{
|
||||
Content: []MCPContent{{Type: "text", Text: "删除 cookies 失败: " + err.Error()}},
|
||||
IsError: true,
|
||||
}
|
||||
}
|
||||
|
||||
cookiePath := cookies.GetCookiesFilePath()
|
||||
resultText := fmt.Sprintf("Cookies 已成功删除,登录状态已重置。\n\n删除的文件路径: %s\n\n下次操作时,需要重新登录。", cookiePath)
|
||||
return &MCPToolResult{
|
||||
Content: []MCPContent{{
|
||||
Type: "text",
|
||||
Text: resultText,
|
||||
}},
|
||||
}
|
||||
}
|
||||
|
||||
// handlePublishContent 处理发布内容
|
||||
func (s *AppServer) handlePublishContent(ctx context.Context, args map[string]interface{}) *MCPToolResult {
|
||||
logrus.Info("MCP: 发布内容")
|
||||
|
||||
Reference in New Issue
Block a user