2026-06-20 06:50:43 +08:00
|
|
|
package bilibili
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"fmt"
|
2026-07-26 22:19:41 +08:00
|
|
|
|
|
|
|
|
"github.com/ssdomei232/goodBaby/internal/meta"
|
2026-06-20 06:50:43 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
// BilibiliAccountConfigValidator B站账号配置验证器
|
|
|
|
|
type BilibiliAccountConfigValidator struct{}
|
|
|
|
|
|
|
|
|
|
func (v *BilibiliAccountConfigValidator) GetType() string {
|
2026-07-26 22:19:41 +08:00
|
|
|
return AccountType
|
2026-06-20 06:50:43 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (v *BilibiliAccountConfigValidator) Validate(config string) error {
|
2026-09-12 15:32:27 +08:00
|
|
|
cfg, err := ParseAccountConfig(config)
|
2026-07-26 22:19:41 +08:00
|
|
|
if err != nil {
|
|
|
|
|
return err
|
2026-06-20 06:50:43 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if cfg.RawCookies == "" {
|
|
|
|
|
return fmt.Errorf("B站账号配置中 cookies 不能为空")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return nil
|
|
|
|
|
}
|
2026-07-26 22:19:41 +08:00
|
|
|
|
|
|
|
|
// Test 用 cookie 拉一次账号信息,验证 cookie 是否还有效
|
|
|
|
|
func (v *BilibiliAccountConfigValidator) Test(config string) error {
|
2026-09-12 15:32:27 +08:00
|
|
|
cfg, err := ParseAccountConfig(config)
|
2026-07-26 22:19:41 +08:00
|
|
|
if err != nil {
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
client := newClient(cfg.RawCookies)
|
|
|
|
|
info, err := client.GetAccountInformation()
|
|
|
|
|
if err != nil {
|
|
|
|
|
return fmt.Errorf("B站 cookie 校验失败: %w", err)
|
|
|
|
|
}
|
|
|
|
|
if info == nil || info.Mid == 0 {
|
|
|
|
|
return fmt.Errorf("B站 cookie 无效或已过期")
|
|
|
|
|
}
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (v *BilibiliAccountConfigValidator) Meta() meta.AccountMeta {
|
|
|
|
|
return meta.AccountMeta{
|
|
|
|
|
Type: AccountType,
|
|
|
|
|
Label: "哔哩哔哩",
|
|
|
|
|
Description: "使用浏览器中的完整 Cookie 登录 B 站,用于发送动态。",
|
|
|
|
|
Docs: "docs/bilibili-config.md",
|
|
|
|
|
Fields: []meta.Field{
|
|
|
|
|
{
|
|
|
|
|
Key: "raw_cookies",
|
|
|
|
|
Label: "Cookies",
|
|
|
|
|
Type: meta.FieldTextarea,
|
|
|
|
|
Required: true,
|
|
|
|
|
Secret: true,
|
|
|
|
|
Placeholder: "SESSDATA=xxx; bili_jct=xxx; DedeUserID=xxx",
|
|
|
|
|
Help: "登录 bilibili.com 后从浏览器开发者工具复制完整的 Cookie 字符串",
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
}
|