refactor: Private bool → Visibility string 支持多种可见范围 (#464)

* docs: 更新 API 文档以包含 private 参数的用途和可选性。

* refactor: visibility 功能从 Private bool 重构为 Visibility string

将发布时可见范围参数从 `Private bool` 改为 `Visibility string`,
支持三种选项:公开可见(默认)、仅自己可见、仅互关好友可见。

- 使用精确 CSS selector 替代遍历 span/label/div 的宽泛选择器
- 新增参数校验,不支持的选项直接返回错误
- 更新 API 文档和 MCP jsonschema 描述
- 与 upstream IsOriginal(原创声明) 功能共存

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

---------

Co-authored-by: yryangang <dd101bb@qq.com>
Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
zy
2026-02-28 00:37:47 +08:00
committed by GitHub
parent 7d87b9e5ee
commit fcbf554016
6 changed files with 95 additions and 9 deletions

View File

@@ -20,6 +20,7 @@ type PublishVideoContent struct {
Tags []string
VideoPath string
ScheduleTime *time.Time // 定时发布时间nil 表示立即发布
Visibility string // 可见范围: "公开可见"(默认), "仅自己可见", "仅互关好友可见"
}
// NewPublishVideoAction 进入发布页并切换到"上传视频"
@@ -62,7 +63,7 @@ func (p *PublishAction) PublishVideo(ctx context.Context, content PublishVideoCo
return errors.Wrap(err, "小红书上传视频失败")
}
if err := submitPublishVideo(page, content.Title, content.Content, content.Tags, content.ScheduleTime); err != nil {
if err := submitPublishVideo(page, content.Title, content.Content, content.Tags, content.ScheduleTime, content.Visibility); err != nil {
return errors.Wrap(err, "小红书发布失败")
}
return nil
@@ -130,7 +131,7 @@ func waitForPublishButtonClickable(page *rod.Page) (*rod.Element, error) {
}
// submitPublishVideo 填写标题、正文、标签并点击发布(等待按钮可点击后再提交)
func submitPublishVideo(page *rod.Page, title, content string, tags []string, scheduleTime *time.Time) error {
func submitPublishVideo(page *rod.Page, title, content string, tags []string, scheduleTime *time.Time, visibility string) error {
// 标题
titleElem, err := page.Element("div.d-input input")
if err != nil {
@@ -163,6 +164,11 @@ func submitPublishVideo(page *rod.Page, title, content string, tags []string, sc
slog.Info("定时发布设置完成", "schedule_time", scheduleTime.Format("2006-01-02 15:04"))
}
// 设置可见范围
if err := setVisibility(page, visibility); err != nil {
return errors.Wrap(err, "设置可见范围失败")
}
// 等待发布按钮可点击
btn, err := waitForPublishButtonClickable(page)
if err != nil {