63 lines
1.8 KiB
Go
63 lines
1.8 KiB
Go
// xiaohongshu 小红书执行器(CDP:creator.xiaohongshu.com)。
|
||
package xiaohongshu
|
||
|
||
import (
|
||
"context"
|
||
"time"
|
||
|
||
"everypublish/agentcore/internal/exec"
|
||
"everypublish/agentcore/internal/exec/cdnbase"
|
||
"everypublish/agentcore/internal/exec/cdp"
|
||
"everypublish/agentcore/internal/vault"
|
||
"everypublish/shared/proto"
|
||
)
|
||
|
||
// Executor 小红书发布执行器
|
||
type Executor struct {
|
||
base *cdnbase.Platform
|
||
}
|
||
|
||
// New 构造执行器
|
||
func New(v *vault.Vault, rootDir, proxy, chromePath string, headless bool) *Executor {
|
||
p := &cdnbase.Platform{
|
||
Vault: v,
|
||
RootDir: rootDir,
|
||
Proxy: proxy,
|
||
ChromePath: chromePath,
|
||
Headless: headless,
|
||
ReceiptDir: rootDir + "/receipts",
|
||
Name: "xiaohongshu",
|
||
LoginDomain: ".xiaohongshu.com",
|
||
PublishCfg: cdp.PublishConfig{
|
||
UploadURL: "https://creator.xiaohongshu.com/publish/publish",
|
||
SuccessMarker: "publish/success",
|
||
FileInputSel: "input[type=\"file\"]",
|
||
TitleSel: "input[placeholder*=\"填写标题\"]",
|
||
DescSel: "#post-textarea",
|
||
PublishBtnSel: "button:has-text(\"发布\")",
|
||
FormWait: 180 * time.Second,
|
||
SuccessWait: 120 * time.Second,
|
||
},
|
||
LoginCfg: cdp.QRLoginConfig{
|
||
LoginURL: "https://creator.xiaohongshu.com/login",
|
||
LoginPathMarker: "creator.xiaohongshu.com/login",
|
||
QRSelector: ".qrcode-img, img[src*=qrcode], .qrcode img",
|
||
SuccessWait: 3 * time.Minute,
|
||
},
|
||
}
|
||
return &Executor{base: p}
|
||
}
|
||
|
||
// Platform 平台标识
|
||
func (e *Executor) Platform() string { return "xiaohongshu" }
|
||
|
||
// Execute 发布
|
||
func (e *Executor) Execute(ctx context.Context, task exec.Task) exec.Result {
|
||
return e.base.Publish(ctx, task)
|
||
}
|
||
|
||
// SolveChallenge 扫码登录
|
||
func (e *Executor) SolveChallenge(ctx context.Context, ch proto.Challenge, onQR func(qrToken, qrURL string)) (bool, string) {
|
||
return e.base.SolveChallenge(ctx, ch, onQR)
|
||
}
|