Documentation
¶
Overview ¶
Package auth 提供 pixiv auth 命令组:账号列表、选择、导入导出、检查与刷新,以及浏览器 OAuth 登录。
包的组成:New 组装命令树,Support 携带账号服务、登录服务与配置读取端口。 AccountService 适配账号领域访问。 桌面回调与远程登录在 github.com/FlanChanXwO/pixiv-cli/internal/urlscheme。
Index ¶
- func AccountJSON(account AccountSummary) any
- func New(env environment.Env, support Support) *cobra.Command
- type AccountService
- type AccountSummary
- type AccountWithToken
- type Accounts
- func (s *Accounts) AccountsWithTokens(ctx context.Context) ([]AccountWithToken, error)
- func (s *Accounts) CheckAccount(ctx context.Context, userID int64, options pixiv.Options) (AccountSummary, error)
- func (s *Accounts) CurrentUser(ctx context.Context) (*AccountSummary, error)
- func (s *Accounts) ImportAccount(ctx context.Context, refreshToken string, setDefault bool, ...) (AccountSummary, error)
- func (s *Accounts) ListAccounts(ctx context.Context) ([]AccountSummary, error)
- func (s *Accounts) RefreshAccount(ctx context.Context, userID int64, options pixiv.Options) (AccountSummary, error)
- func (s *Accounts) RemoveAccount(ctx context.Context, userID int64) error
- func (s *Accounts) RestoreAccounts(ctx context.Context, inputs []RestoreAccountInput) (RestoreAccountsResult, error)
- func (s *Accounts) SelectedUserID(ctx context.Context) (int64, error)
- func (s *Accounts) SetAllPoolSchedulable(ctx context.Context, schedulable bool) error
- func (s *Accounts) SetPoolSchedulable(ctx context.Context, userIDs []int64, schedulable bool) error
- func (s *Accounts) UseAccount(ctx context.Context, userID int64) error
- func (s *Accounts) UseAuto() error
- type LoginCompleteRequest
- type LoginService
- type RestoreAccountInput
- type RestoreAccountOutcome
- type RestoreAccountsResult
- type Support
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AccountJSON ¶
func AccountJSON(account AccountSummary) any
AccountJSON 返回与 `pixiv auth list --json` 单账号项相同的公开摘要;不含凭据。
Types ¶
type AccountService ¶
AccountService 把账号领域服务接到 auth 命令上。 默认账号由 Accounts 解析;代理和运行时开关在这里转换为 SDK options。
type AccountSummary ¶ added in v1.4.0
type AccountSummary struct {
UserID int64
Username string
Default bool
Premium *bool
Schedulable bool
PoolFrozenUntil *int64
PoolLastSelected bool
Eligible bool
PoolStatusKnown bool
}
AccountSummary 汇总 Pixiv 账号的公开摘要。
type AccountWithToken ¶ added in v1.4.0
type AccountWithToken struct {
UserID int64 `json:"user_id"`
Username string `json:"username"`
Default bool `json:"default"`
Credential credential.Secret `json:"-"`
}
AccountWithToken 携带仅用于显式 auth export 的账号+token 摘要。 RefreshToken 供显式导出流程读取凭据;通用 JSON 编码忽略 Credential。
func (AccountWithToken) RefreshToken ¶ added in v1.4.0
func (a AccountWithToken) RefreshToken() string
RefreshToken 返回仅供显式 auth export 使用的 refresh token。
type Accounts ¶ added in v1.4.0
type Accounts struct {
// contains filtered or unexported fields
}
Accounts 将默认账号配置与 Pixiv 账号存储接到命令,保持输出摘要契约。
func NewAccounts ¶ added in v1.4.0
NewAccounts 绑定账号文件与调用方的默认账号配置。
func (*Accounts) AccountsWithTokens ¶ added in v1.4.0
func (s *Accounts) AccountsWithTokens(ctx context.Context) ([]AccountWithToken, error)
AccountsWithTokens 返回全部账号及其 refresh token,仅用于显式 auth export。
func (*Accounts) CheckAccount ¶ added in v1.4.0
func (s *Accounts) CheckAccount(ctx context.Context, userID int64, options pixiv.Options) (AccountSummary, error)
CheckAccount 在线校验指定账号的 refresh token,并持久化 OAuth 返回的 rotation。
func (*Accounts) CurrentUser ¶ added in v1.4.0
func (s *Accounts) CurrentUser(ctx context.Context) (*AccountSummary, error)
CurrentUser 返回当前选中账号的身份摘要。
func (*Accounts) ImportAccount ¶ added in v1.4.0
func (s *Accounts) ImportAccount(ctx context.Context, refreshToken string, setDefault bool, options pixiv.Options) (AccountSummary, error)
ImportAccount 导入一个 refresh token 并在线验证;连接选项由调用方组装, 服务不读取配置或推断网络策略。
func (*Accounts) ListAccounts ¶ added in v1.4.0
func (s *Accounts) ListAccounts(ctx context.Context) ([]AccountSummary, error)
ListAccounts 返回按显示顺序排列的 Pixiv 账号。
func (*Accounts) RefreshAccount ¶ added in v1.4.0
func (s *Accounts) RefreshAccount(ctx context.Context, userID int64, options pixiv.Options) (AccountSummary, error)
RefreshAccount 刷新指定账号的凭据并强制读取当前 profile,把会员资格快照写回 账号文件,最后返回账号摘要。
func (*Accounts) RemoveAccount ¶ added in v1.4.0
RemoveAccount 删除 Pixiv 账号;若它是显式默认账号,先清除配置以恢复自动选择。
func (*Accounts) RestoreAccounts ¶ added in v1.4.0
func (s *Accounts) RestoreAccounts(ctx context.Context, inputs []RestoreAccountInput) (RestoreAccountsResult, error)
RestoreAccounts 原子合并一个 bundle:先读取恢复前 default 与已有 UID 集合, 再用一次批量事务写入全部凭据,最后仅在本地无 default 时采用 bundle default。 任一凭据写入失败时事务整体回滚,default 配置保持不变。
func (*Accounts) SelectedUserID ¶ added in v1.4.0
SelectedUserID 读取显式默认或首个账号,并保留存储和取消错误。
func (*Accounts) SetAllPoolSchedulable ¶ added in v1.4.0
SetAllPoolSchedulable 原子更新当前全部本地账号。
func (*Accounts) SetPoolSchedulable ¶ added in v1.4.0
SetPoolSchedulable 原子更新一组已存在的本地账号;未知 UID 会使整批失败。
func (*Accounts) UseAccount ¶ added in v1.4.0
UseAccount 设置显式默认账号。
type LoginCompleteRequest ¶ added in v1.4.0
LoginCompleteRequest 将登录凭据保存与调用方的默认账号选择分开编排。
type LoginService ¶ added in v1.4.0
type LoginService struct {
Pixiv *Accounts
}
LoginService 在账号 owner 完成一次性登录后,编排调用方的默认账号选择。
func (LoginService) Complete ¶ added in v1.4.0
func (s LoginService) Complete(ctx context.Context, start account.LoginStart, request LoginCompleteRequest) (AccountSummary, error)
Complete 用回调 URL 或授权码兑换凭据并保存账号,随后释放该登录 session 的 HTTP 传输。保存后读取失败时,错误与已持久化的身份一起返回。
func (LoginService) Start ¶ added in v1.4.0
func (s LoginService) Start(request account.LoginRequest) (account.LoginStart, error)
Start 开始账号 owner 的一次性登录,网络选项由调用方提供。
type RestoreAccountInput ¶ added in v1.4.0
type RestoreAccountInput struct {
Account AccountSummary
RefreshToken string
IsBundleDefault bool
}
RestoreAccountInput 描述一次 bundle 恢复的单账号输入。
type RestoreAccountOutcome ¶ added in v1.4.0
type RestoreAccountOutcome struct {
Account AccountSummary
IsReplacement bool
}
RestoreAccountOutcome 描述单账号恢复结果。IsReplacement 区分新增与替换。
type RestoreAccountsResult ¶ added in v1.4.0
type RestoreAccountsResult struct {
Accounts []RestoreAccountOutcome
ResultingDefault int64
}
RestoreAccountsResult 汇总一次原子 bundle 恢复的结果与最终选中的默认账号。
type Support ¶
type Support struct {
// Account 延迟打开账号服务;只在执行账号子命令时调用。
Account func(context.Context) (*Accounts, error)
// Login 延迟打开登录服务,避免构造命令树时打开账号文件。
Login func(context.Context) (LoginService, error)
// LoadRuntime 每次调用读取最新的运行时配置。
LoadRuntime func() (config.Config, error)
// WriteBundle 写出含凭据的 bundle;force 为 false 时不得覆盖已有文件。
WriteBundle func(string, []byte, bool) error
}
Support 携带各 auth 叶子命令共用的账号、登录和 bundle 写入端口;输入输出与交互式提问 由 environment.Env 提供。