update publish timeout (#245)
* update publish timeout * add publish error message
This commit is contained in:
@@ -182,6 +182,7 @@ func (s *XiaohongshuService) PublishContent(ctx context.Context, req *PublishReq
|
|||||||
|
|
||||||
// 执行发布
|
// 执行发布
|
||||||
if err := s.publishContent(ctx, content); err != nil {
|
if err := s.publishContent(ctx, content); err != nil {
|
||||||
|
logrus.Errorf("发布内容失败: title=%s %v", content.Title, err)
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -33,7 +33,7 @@ const (
|
|||||||
|
|
||||||
func NewPublishImageAction(page *rod.Page) (*PublishAction, error) {
|
func NewPublishImageAction(page *rod.Page) (*PublishAction, error) {
|
||||||
|
|
||||||
pp := page.Timeout(180 * time.Second)
|
pp := page.Timeout(300 * time.Second)
|
||||||
|
|
||||||
pp.MustNavigate(urlOfPublic).MustWaitIdle().MustWaitDOMStable()
|
pp.MustNavigate(urlOfPublic).MustWaitIdle().MustWaitDOMStable()
|
||||||
time.Sleep(1 * time.Second)
|
time.Sleep(1 * time.Second)
|
||||||
@@ -61,7 +61,15 @@ func (p *PublishAction) Publish(ctx context.Context, content PublishImageContent
|
|||||||
return errors.Wrap(err, "小红书上传图片失败")
|
return errors.Wrap(err, "小红书上传图片失败")
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := submitPublish(page, content.Title, content.Content, content.Tags); err != nil {
|
tags := content.Tags
|
||||||
|
if len(tags) >= 10 {
|
||||||
|
logrus.Warnf("标签数量超过10,截取前10个标签")
|
||||||
|
tags = tags[:10]
|
||||||
|
}
|
||||||
|
|
||||||
|
logrus.Infof("发布内容: title=%s, images=%v, tags=%v", content.Title, len(content.ImagePaths), tags)
|
||||||
|
|
||||||
|
if err := submitPublish(page, content.Title, content.Content, tags); err != nil {
|
||||||
return errors.Wrap(err, "小红书发布失败")
|
return errors.Wrap(err, "小红书发布失败")
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -179,20 +187,25 @@ func uploadImages(page *rod.Page, imagesPaths []string) error {
|
|||||||
pp := page.Timeout(30 * time.Second)
|
pp := page.Timeout(30 * time.Second)
|
||||||
|
|
||||||
// 验证文件路径有效性
|
// 验证文件路径有效性
|
||||||
|
validPaths := make([]string, 0, len(imagesPaths))
|
||||||
for _, path := range imagesPaths {
|
for _, path := range imagesPaths {
|
||||||
if _, err := os.Stat(path); os.IsNotExist(err) {
|
if _, err := os.Stat(path); os.IsNotExist(err) {
|
||||||
return errors.Wrapf(err, "图片文件不存在: %s", path)
|
logrus.Warnf("图片文件不存在: %s", path)
|
||||||
|
continue
|
||||||
}
|
}
|
||||||
|
validPaths = append(validPaths, path)
|
||||||
|
|
||||||
|
logrus.Infof("获取有效图片:%s", path)
|
||||||
}
|
}
|
||||||
|
|
||||||
// 等待上传输入框出现
|
// 等待上传输入框出现
|
||||||
uploadInput := pp.MustElement(".upload-input")
|
uploadInput := pp.MustElement(".upload-input")
|
||||||
|
|
||||||
// 上传多个文件
|
// 上传多个文件
|
||||||
uploadInput.MustSetFiles(imagesPaths...)
|
uploadInput.MustSetFiles(validPaths...)
|
||||||
|
|
||||||
// 等待并验证上传完成
|
// 等待并验证上传完成
|
||||||
return waitForUploadComplete(pp, len(imagesPaths))
|
return waitForUploadComplete(pp, len(validPaths))
|
||||||
}
|
}
|
||||||
|
|
||||||
// waitForUploadComplete 等待并验证上传完成
|
// waitForUploadComplete 等待并验证上传完成
|
||||||
|
|||||||
Reference in New Issue
Block a user