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.
This commit is contained in:
chekayo
2025-10-09 21:38:52 +08:00
parent 7c2658dae5
commit e6bf9921ea
2 changed files with 61 additions and 16 deletions

View File

@@ -7,6 +7,8 @@ import (
"os"
"strings"
"time"
"unicode"
"unicode/utf8"
"github.com/go-rod/rod"
"github.com/go-rod/rod/lib/input"
@@ -55,6 +57,11 @@ func (p *PublishAction) Publish(ctx context.Context, content PublishImageContent
return errors.New("图片不能为空")
}
trimmedContent := strings.TrimRightFunc(content.Content, unicode.IsSpace)
if utf8.RuneCountInString(trimmedContent) > 1000 {
return errors.New("正文内容不能超过1000个字符")
}
page := p.page.Context(ctx)
if err := uploadImages(page, content.ImagePaths); err != nil {