Documentation
¶
Overview ¶
Package database 管理 Pixiv 与 FANBOX 鉴权状态的单一 SQLite 数据库。
数据库只保存鉴权数据与 Pixiv 账号池调度状态,不保存普通配置、下载 archive、缓存、 请求日志或浏览器 profile。
包的组成:Open 打开或创建数据库并完成迁移,DB 提供账号读写端口; repository.go 与 pool.go 分别承载账号查询和账号池调度,migrate.go 维护迁移 ledger。
Index ¶
- func DatabasePath(appDataDir string) string
- type DB
- func (d *DB) Close() error
- func (d *DB) Freeze(ctx context.Context, userID, frozenUntil int64) error
- func (d *DB) GetFanbox(ctx context.Context, userID int64) (fanboxaccount.Account, error)
- func (d *DB) GetPixiv(ctx context.Context, userID int64) (pixivaccount.Account, error)
- func (d *DB) ListFanbox(ctx context.Context) ([]fanboxaccount.Account, error)
- func (d *DB) ListPixiv(ctx context.Context) ([]pixivaccount.Account, error)
- func (d *DB) ListPixivPoolStatus(ctx context.Context, now int64) (account.PoolStatus, error)
- func (d *DB) Path() string
- func (d *DB) RemoveFanbox(ctx context.Context, userID int64) error
- func (d *DB) RemovePixiv(ctx context.Context, userID int64) error
- func (d *DB) RotatePixivCredentials(ctx context.Context, userID, expectedRevision int64, refreshToken []byte) error
- func (d *DB) SaveFanboxCredential(ctx context.Context, account fanboxaccount.Account) error
- func (d *DB) SavePixivCredential(ctx context.Context, account pixivaccount.Account) error
- func (d *DB) SavePixivCredentials(ctx context.Context, accounts []pixivaccount.Account) error
- func (d *DB) SelectPixiv(ctx context.Context, now int64, attemptedUserIDs []int64, ...) (pixivaccount.Account, error)
- func (d *DB) SetAllPixivSchedulable(ctx context.Context, schedulable bool) error
- func (d *DB) SetPixivSchedulable(ctx context.Context, userIDs []int64, schedulable bool) error
- func (d *DB) UpdatePixivMetadata(ctx context.Context, userID int64, username string, premiumStatus *bool, ...) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type DB ¶
type DB struct {
// contains filtered or unexported fields
}
DB 持有鉴权数据库的 SQL 与 GORM 句柄;调用方使用后必须 Close。
func (*DB) ListFanbox ¶
ListFanbox 返回全部 FANBOX 账号,按 sort_order 升序。
func (*DB) ListPixivPoolStatus ¶
ListPixivPoolStatus 返回 non-secret 调度状态,并在同一个事务中清理已过期冻结。
func (*DB) RemoveFanbox ¶
RemoveFanbox 删除一个 FANBOX 账号。
func (*DB) RemovePixiv ¶
RemovePixiv 删除一个 Pixiv 账号,其 pool 标记随之自然删除。
func (*DB) RotatePixivCredentials ¶
func (d *DB) RotatePixivCredentials(ctx context.Context, userID, expectedRevision int64, refreshToken []byte) error
RotatePixivCredentials 提交一次 refresh token rotation:更新 token 并递增 credential_revision。expectedRevision 不匹配时返回 ErrCredentialConflict。
func (*DB) SaveFanboxCredential ¶
SaveFanboxCredential 保存一次已验证的 FANBOX credential。 新账号固定从 revision 1 开始;已有账号在 SQL 内递增 revision。
func (*DB) SavePixivCredential ¶
SavePixivCredential 保存一次已验证的 Pixiv credential。 新账号固定从 revision 1 开始;已有账号在 SQL 内递增 revision,不能由调用方回退。
func (*DB) SavePixivCredentials ¶
SavePixivCredentials 在一个事务中保存一组首次导入的 Pixiv credentials。 迁移调用它保证任一账号失败时不会留下部分提交。
func (*DB) SelectPixiv ¶
func (d *DB) SelectPixiv(ctx context.Context, now int64, attemptedUserIDs []int64, chooser pixivaccount.Chooser) (pixivaccount.Account, error)
SelectPixiv 在一个短事务内加载候选快照,并把纯 chooser 的结果验证后提交 为 pool_last_selected marker。chooser 不接触 SQL;attemptedUserIDs 只属于当前 operation,不会写入数据库;过期冻结在选择时清理。
func (*DB) SetAllPixivSchedulable ¶
SetAllPixivSchedulable 在一个事务内更新当前所有 Pixiv 账号。
func (*DB) SetPixivSchedulable ¶
SetPixivSchedulable 在持锁事务中一次更新给定账号的调度开关。任一 UID 不存在时 整批回滚并返回 account.ErrNotFound。