application

package
v0.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 13, 2026 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GeneratePKCEPair

func GeneratePKCEPair() (verifier, challenge string, err error)

func ParseUID

func ParseUID(raw string) (int64, error)

func RandomURLToken

func RandomURLToken(size int) (string, error)

func ResolveRefreshToken

func ResolveRefreshToken(store auth.AuthStore, requestedUserID int64, requestedToken string, refreshTokenEnv func() string) (string, error)

Types

type AccountAddRequest

type AccountAddRequest struct {
	TokenInput         string
	HTTPSProxyOverride *string
}

type AccountCheckRequest

type AccountCheckRequest struct {
	UserID             int64
	HTTPSProxyOverride *string
}

type AccountListResult

type AccountListResult struct {
	DefaultUserID int64
	Accounts      []AccountResult
}

type AccountResult

type AccountResult struct {
	UserID   int64  `json:"user_id,omitempty"`
	Username string `json:"username,omitempty"`
	Default  bool   `json:"default"`
	HasToken bool   `json:"has_token"`
	Warning  string `json:"warning,omitempty"`
}

type AccountService

type AccountService struct {
	Auth            AuthRepository
	LoadRuntime     func() (config.RuntimeConfig, error)
	RefreshTokenEnv func() string
	NewClient       AuthenticatedPixivFactory
}

func (AccountService) Add

func (AccountService) Check

func (s AccountService) Check(ctx context.Context, userID int64) (AccountResult, error)

func (AccountService) CheckWithRequest

func (s AccountService) CheckWithRequest(ctx context.Context, req AccountCheckRequest) (AccountResult, error)

func (AccountService) List

func (AccountService) Remove

func (s AccountService) Remove(userID int64) (AccountResult, int64, error)

func (AccountService) Use

func (s AccountService) Use(userID int64) (int64, error)

type ArtworkClient

type ArtworkClient interface {
	SearchIllust(context.Context, string, string, string, string, int) (*pixiv.IllustList, error)
	IllustDetail(context.Context, int64) (*pixiv.IllustDetail, error)
	IllustRanking(context.Context, string, string, int) (*pixiv.IllustList, error)
	IllustRecommended(context.Context, int) (*pixiv.IllustList, error)
}

type ArtworkService

type ArtworkService struct {
	Resolver ClientResolver
}

func (ArtworkService) Detail

func (s ArtworkService) Detail(ctx context.Context, clientReq ClientRequest, id int64) (*pixiv.IllustDetail, bool, error)

func (ArtworkService) Ranking

func (ArtworkService) Recommended

func (ArtworkService) Search

type AuthRepository

type AuthRepository interface {
	Load() (auth.AuthStore, error)
	Save(auth.AuthStore) error
}

type AuthenticatedPixivClient

type AuthenticatedPixivClient interface {
	Refresh(context.Context) error
	RefreshTokenValue() string
	UserID() int64
	UserName() string
	UserDetail(context.Context, int64) (*pixiv.User, error)
}

type AuthenticatedPixivFactory

type AuthenticatedPixivFactory func(config.RuntimeConfig) (AuthenticatedPixivClient, error)

type ClientBundle

type ClientBundle struct {
	Auth     AuthenticatedPixivClient
	Artwork  ArtworkClient
	Download DownloadClient
}

type ClientRequest

type ClientRequest struct {
	UserID                   int64
	RefreshToken             string
	HTTPSProxyOverride       *string
	DownloadPathOverride     *string
	FilenameTemplateOverride *string
	JSONOverride             *bool
	NeedsAuth                bool
}

type ClientResolver

type ClientResolver struct {
	Auth            AuthRepository
	LoadRuntime     func() (config.RuntimeConfig, error)
	RefreshTokenEnv func() string
	NewClient       PixivClientFactory
}

func (ClientResolver) Resolve

type ClientSession

type ClientSession struct {
	Client  ClientBundle
	Config  config.RuntimeConfig
	JSONOut bool
}

type ConfigMutationResult

type ConfigMutationResult struct {
	Alias       string
	EnvOverride string
	HasOverride bool
}

type ConfigService

type ConfigService struct {
	Store ConfigStore
}

func (ConfigService) Get

func (s ConfigService) Get(alias string) (config.SettingValue, error)

func (ConfigService) Path

func (s ConfigService) Path() (string, error)

func (ConfigService) Set

func (s ConfigService) Set(alias, raw string) (ConfigMutationResult, error)

func (ConfigService) Unset

func (s ConfigService) Unset(alias string) (ConfigMutationResult, error)

type ConfigStore

type ConfigStore interface {
	Path() (string, error)
	Get(string) (config.SettingValue, error)
	Set(string, string) (ConfigMutationResult, error)
	Unset(string) (ConfigMutationResult, error)
}

type DownloadClient

type DownloadClient interface {
	download.PixivClient
}

type DownloadFactory

type DownloadFactory func(DownloadClient, config.RuntimeConfig) Downloader

type DownloadService

type DownloadService struct {
	Resolver      ClientResolver
	NewDownloader DownloadFactory
}

func (DownloadService) Download

func (s DownloadService) Download(ctx context.Context, clientReq ClientRequest, ids []int64) ([]download.DownloadedArtwork, bool, error)

type Downloader

type Downloader interface {
	Download(context.Context, []int64) ([]download.DownloadedArtwork, error)
}

type LoginCompleteRequest

type LoginCompleteRequest struct {
	Code               string
	Verifier           string
	OAuthBase          string
	UseAfterLogin      bool
	HTTPSProxyOverride *string
}

type LoginService

type LoginService struct {
	Auth        AuthRepository
	LoadRuntime func() (config.RuntimeConfig, error)
	NewOAuth    OAuthClientFactory
}

func (LoginService) Complete

func (LoginService) Start

func (s LoginService) Start() (LoginStart, error)

type LoginStart

type LoginStart struct {
	Verifier  string
	Challenge string
	State     string
}

type OAuthClientFactory

type OAuthClientFactory func(config.RuntimeConfig, string) (OAuthExchanger, error)

type OAuthExchanger

type OAuthExchanger interface {
	ExchangeAuthorizationCode(context.Context, string, string) (OAuthToken, error)
}

type OAuthToken

type OAuthToken struct {
	RefreshToken string
	UserID       int64
	Username     string
}

type PixivClientFactory

type PixivClientFactory func(config.RuntimeConfig) (ClientBundle, error)

type RankingRequest

type RankingRequest struct {
	Client ClientRequest
	Mode   string
	Date   string
	Offset int
}

type RecommendedRequest

type RecommendedRequest struct {
	Client ClientRequest
	Offset int
}

type SDKClient added in v0.2.0

SDKClient 是 CLI 数据命令所需的窄 facade。它刻意不复用或导出旧 Source 的大接口, 让 CLI 通过公共 SDK 获得 cursor、错误和路由语义。

type SDKClientFactory added in v0.2.0

type SDKClientFactory func(SDKClientRequest) (SDKClient, error)

type SDKClientRequest added in v0.2.0

type SDKClientRequest struct {
	UserID             int64
	RefreshToken       string
	HTTPSProxyOverride *string
	// AuthFilePath 允许 MCP 等长驻调用方把 OAuth rotation 固定到同一个受保护 store。
	// 为空时继续使用 OpenDefault 的标准路径。
	AuthFilePath string
}

SDKClientRequest 只携带 CLI 显式覆写;其余 config/auth 优先级由 OpenDefault 在每次 SDK 操作快照中处理。

type SDKService added in v0.2.0

type SDKService struct {
	NewClient   SDKClientFactory
	LoadRuntime func() (config.RuntimeConfig, error)
}

func (SDKService) Client added in v0.2.0

func (s SDKService) Client(req SDKClientRequest) (SDKClient, error)

func (SDKService) CurrentUserID added in v0.2.0

func (s SDKService) CurrentUserID(ctx context.Context, req SDKClientRequest) (SDKClient, int64, error)

CurrentUserID 通过 SDK OAuth 快照获取真实身份。这样 --refresh-token 和环境 token 都不会被本地默认账号误替代。

func (SDKService) JSONOut added in v0.2.0

func (s SDKService) JSONOut(override *bool) (bool, error)

JSONOut 与既有 CLI config 语义一致:命令显式 --json 覆盖 runtime 配置。

func (SDKService) OpenOperation added in v0.2.0

func (s SDKService) OpenOperation(ctx context.Context, req SDKClientRequest) (SDKClient, error)

OpenOperation 让一个 CLI 命令的 self 身份解析和所有 cursor 页面共享同一个 OpenDefault 快照,避免 OAuth rotation 在命令进行中使旧 refresh token 失效。

type SearchRequest

type SearchRequest struct {
	Client   ClientRequest
	Word     string
	Target   string
	Sort     string
	Duration string
	Offset   int
}

type Services

type Services struct {
	Account  AccountService
	Config   ConfigService
	Artwork  ArtworkService
	Download DownloadService
	Login    LoginService
	SDK      SDKService
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL