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:
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user