feat: 支持返回登录二维码与 Docker 部署 (#155)

* feat: 支持返回登录二维码与 Docker 部署

* feat: 完善扫码登录功能

* fix: 修复当存在已经登录的情况,上层还会启动 goroutine的问题,并把 mcp 的返回增加为图片格式
This commit is contained in:
lmxdawn
2025-09-25 19:44:01 +08:00
committed by GitHub
parent cc5038decd
commit a8a2743a51
14 changed files with 314 additions and 5 deletions

View File

@@ -4,8 +4,9 @@ import (
"context"
"encoding/json"
"fmt"
"github.com/sirupsen/logrus"
"strings"
"time"
)
// MCP 工具处理函数
@@ -34,6 +35,46 @@ func (s *AppServer) handleCheckLoginStatus(ctx context.Context) *MCPToolResult {
}
}
// handleGetLoginQrcode 处理获取登录二维码请求。
// 返回二维码图片的 Base64 编码和超时时间,供前端展示扫码登录。
func (s *AppServer) handleGetLoginQrcode(ctx context.Context) *MCPToolResult {
logrus.Info("MCP: 获取登录扫码图片")
result, err := s.xiaohongshuService.GetLoginQrcode(ctx)
if err != nil {
return &MCPToolResult{
Content: []MCPContent{{Type: "text", Text: "获取登录扫码图片失败: " + err.Error()}},
IsError: true,
}
}
if result.IsLoggedIn {
return &MCPToolResult{
Content: []MCPContent{{Type: "text", Text: "你当前已处于登录状态"}},
}
}
now := time.Now()
deadline := func() string {
d, err := time.ParseDuration(result.Timeout)
if err != nil {
return now.Format("2006-01-02 15:04:05")
}
return now.Add(d).Format("2006-01-02 15:04:05")
}()
// 已登录:文本 + 图片
contents := []MCPContent{
{Type: "text", Text: "请用小红书 App 在 " + deadline + " 前扫码登录 👇"},
{
Type: "image",
MimeType: "image/png",
Data: strings.TrimPrefix(result.Img, "data:image/png;base64,"),
},
}
return &MCPToolResult{Content: contents}
}
// handlePublishContent 处理发布内容
func (s *AppServer) handlePublishContent(ctx context.Context, args map[string]interface{}) *MCPToolResult {
logrus.Info("MCP: 发布内容")