application

package
v0.4.1 Latest Latest
Warning

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

Go to latest
Published: Jul 19, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const (
	AccountImportStatusAdded   = "added"
	AccountImportStatusUpdated = "updated"
)

Variables

This section is empty.

Functions

func ParseUID

func ParseUID(raw string) (int64, error)

Types

type AccountBundleImportResult added in v0.4.0

type AccountBundleImportResult struct {
	Accounts      []AccountImportResult `json:"accounts"`
	DefaultUserID int64                 `json:"default_user_id"`
}

type AccountCheckRequest

type AccountCheckRequest struct {
	UserID             int64
	HTTPSProxyOverride *string
}

type AccountExportRequest added in v0.4.0

type AccountExportRequest struct {
	UserID int64
	All    bool
}

type AccountExportResult added in v0.4.0

type AccountExportResult struct {
	RefreshToken string
	Bundle       []byte
	AccountCount int
}

type AccountImportRequest added in v0.4.0

type AccountImportRequest struct {
	TokenInput         string
	HTTPSProxyOverride *string
}

type AccountImportResult added in v0.4.0

type AccountImportResult struct {
	UserID   int64  `json:"user_id"`
	Username string `json:"username"`
	Status   string `json:"status"`
}

AccountImportResult 是 direct import 与 bundle restore 共用的安全报告 DTO。 它刻意不携带 token、default 或 has_token,避免导入报告复用账号列表契约。

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 {
	SDK                 SDKService
	RefreshTokenFromEnv func() (string, error)
}

AccountService 只适配 public SDK 的本地账号 API。账号文件、token rotation 和 OAuth 身份验证均由 SDK 维护,应用层不再复制另一份 auth store 调用链。

func (AccountService) Check

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

func (AccountService) CheckWithRequest

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

func (AccountService) Export added in v0.4.0

Export 只通过 public SDK 读取本地认证快照;它不应用环境 token 或运行时 UID 覆写。

func (AccountService) Import added in v0.4.0

func (AccountService) ImportBundle added in v0.4.0

func (s AccountService) ImportBundle(body []byte) (AccountBundleImportResult, error)

ImportBundle 解码并离线恢复 bundle;身份验证和 transport 均不参与此路径。

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 AuthBundleSDKClient added in v0.4.0

type AuthBundleSDKClient interface {
	ExportAuthBundle(sdk.AuthExportSelection) (*sdk.AuthExportBundle, error)
	RestoreAuthBundle(*sdk.AuthExportBundle) (*sdk.AuthRestoreResult, error)
}

AuthBundleSDKClient 是离线认证 bundle 所需的独立 public SDK facade,避免把 secret-bearing 方法扩散到内容命令和 MCP 的通用测试替身。

type ClientRequest

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

ClientRequest 是 CLI 解析 flags 后的本地请求值。内容与下载命令会进一步转换为 SDKClientRequest;本类型不持有 Pixiv client,也不建立第二条认证或内容调用链。

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 {
	IllustDetail(context.Context, int64) (*sdk.IllustDetail, error)
	UgoiraMetadata(context.Context, int64) (*sdk.UgoiraMetadataResult, error)
	ParseResourceRef(string) (sdk.ResourceRef, error)
	Download(context.Context, sdk.ResourceRef, string) error
}

DownloadClient 是下载实现从 public SDK operation snapshot 使用的最小能力集。 application 只编排用例,不依赖具体下载器或 Pixiv 协议实现。

type DownloadManager added in v0.4.0

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

type DownloadManagerFactory added in v0.4.0

type DownloadManagerFactory func(client DownloadClient, downloadPath, filenameTemplate string) (DownloadManager, error)

type DownloadRequest added in v0.4.0

type DownloadRequest struct {
	IllustIDs        []int64
	DownloadPath     string
	FilenameTemplate string
}

type DownloadService

type DownloadService struct {
	NewManager DownloadManagerFactory
}

func (DownloadService) Download

Download 把 operation snapshot 与本次运行配置交给 composition root 注入的下载器。

type DownloadedArtwork added in v0.4.0

type DownloadedArtwork struct {
	IllustID int64
	Title    string
	Author   string
	Type     string
	Files    []DownloadedFile
}

type DownloadedFile added in v0.4.0

type DownloadedFile struct {
	Path string
	Page int
}

type LoginCompleteRequest

type LoginCompleteRequest struct {
	CallbackOrCode string
	UseAfterLogin  bool
}

type LoginService

type LoginService struct {
	SDK         SDKService
	LoadRuntime func() (config.RuntimeConfig, error)
}

LoginService 将浏览器交互同 public SDK 的一次性 LoginSession 连接起来。应用层不再 自行生成 PKCE、直连 OAuth 或写入 auth store。

func (LoginService) Complete

func (s LoginService) Complete(ctx context.Context, start LoginStart, request LoginCompleteRequest) (AccountResult, error)

func (LoginService) Start

func (s LoginService) Start(requests ...SDKClientRequest) (LoginStart, error)

type LoginStart

type LoginStart struct {
	AuthorizationURL string
	// contains filtered or unexported fields
}

func (LoginStart) AcceptsCallbackURL added in v0.3.0

func (s LoginStart) AcceptsCallbackURL(rawURL string) bool

AcceptsCallbackURL 是浏览器、loopback 和手工 URL 输入的非消耗性校验入口。它把 state/verifier 保持在 public SDK 的不透明 LoginSession 内,调用方只能得到布尔结果。

type PagePlan added in v0.4.0

type PagePlan struct {
	Skip     int
	Limit    int
	OneBatch bool
}

PagePlan 描述与传输协议无关的逻辑分页请求。Limit 为 0 时遍历全部结果。

type PageResult added in v0.4.0

type PageResult struct {
	Returned int
	HasMore  bool
}

PageResult 描述逻辑分页实际返回的条数以及上游是否仍有内容。

func CollectPages added in v0.4.0

func CollectPages[T any](ctx context.Context, plan PagePlan, fetch func(context.Context, sdk.Cursor) ([]T, sdk.Cursor, error)) ([]T, PageResult, error)

CollectPages 使用共享遍历引擎收集结果;失败时丢弃已经收集的部分结果。

func TraversePages added in v0.4.0

func TraversePages[T any](ctx context.Context, plan PagePlan, fetch func(context.Context, sdk.Cursor) ([]T, sdk.Cursor, error), consume func([]T) error) (PageResult, error)

TraversePages 跟随 SDK opaque cursor,并把每批结果交给 consume。

type SDKClient added in v0.2.0

type SDKClient interface {
	ImportAccount(context.Context, string) (*sdk.Account, error)
	ListAccounts() (*sdk.AccountsResult, error)
	SelectAccount(int64) error
	RemoveAccount(int64) error
	CheckAccount(context.Context, int64) (*sdk.Account, error)
	CheckRefreshToken(context.Context, string) (*sdk.Account, error)
	ExportAccountRefreshToken(int64) (string, error)
	Refresh(context.Context) (*sdk.Account, error)
	StartLogin() (*sdk.LoginSession, error)
	CompleteLogin(context.Context, *sdk.LoginSession, string, sdk.LoginOptions) (*sdk.Account, error)
	CurrentUserID(context.Context) (int64, error)
	SearchIllust(context.Context, sdk.SearchIllustRequest) (*sdk.IllustListResult, error)
	SearchIllustOptions(context.Context, sdk.SearchIllustOptionsRequest) (*sdk.SearchIllustOptionsResult, error)
	IllustDetail(context.Context, int64) (*sdk.IllustDetail, error)
	IllustRelated(context.Context, sdk.IllustRelatedRequest) (*sdk.IllustListResult, error)
	IllustRanking(context.Context, sdk.IllustRankingRequest) (*sdk.IllustListResult, error)
	IllustRecommended(context.Context, sdk.IllustRecommendedRequest) (*sdk.IllustListResult, error)
	MangaRecommended(context.Context, sdk.IllustRecommendedRequest) (*sdk.IllustListResult, error)
	NovelRecommended(context.Context, sdk.NovelRecommendedRequest) (*sdk.NovelListResult, error)
	UserRecommended(context.Context, sdk.UserRecommendedRequest) (*sdk.UserRecommendedResult, error)
	UserDetail(context.Context, sdk.UserDetailRequest) (*sdk.UserDetailResult, error)
	UserArtworks(context.Context, sdk.UserArtworksRequest) (*sdk.IllustListResult, error)
	UserBookmarks(context.Context, sdk.UserBookmarksRequest) (*sdk.IllustListResult, error)
	UserBookmarksCursor(context.Context, sdk.UserBookmarksRequest, int64) (sdk.Cursor, error)
	UserFollowing(context.Context, sdk.UserFollowingRequest) (*sdk.UserListResult, error)
	FollowingIllusts(context.Context, sdk.FollowingIllustsRequest) (*sdk.IllustListResult, error)
	SearchUser(context.Context, sdk.SearchUserRequest) (*sdk.UserListResult, error)
	TrendingTagsIllust(context.Context) (*sdk.TrendingTagsIllustResult, error)
	UgoiraMetadata(context.Context, int64) (*sdk.UgoiraMetadataResult, error)
	ParseResourceRef(string) (sdk.ResourceRef, error)
	OpenResource(context.Context, sdk.OpenResourceRequest) (*sdk.ResourceResponse, error)
	Download(context.Context, sdk.ResourceRef, string) error
	AddBookmark(context.Context, sdk.AddBookmarkRequest) error
	RemoveBookmark(context.Context, sdk.RemoveBookmarkRequest) error
	FollowUser(context.Context, sdk.FollowUserRequest) error
	UnfollowUser(context.Context, sdk.UnfollowUserRequest) error
}

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) AuthBundleClient added in v0.4.0

func (s SDKService) AuthBundleClient(req SDKClientRequest) (AuthBundleSDKClient, 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 失效。

func (SDKService) Runtime added in v0.3.0

func (s SDKService) Runtime() (config.RuntimeConfig, error)

Runtime 返回当前本地运行配置,供下载路径这类 SDK 之外的本地输出策略使用。

type Services

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

Services 只组合应用层的本地适配与 public SDK facade。

Jump to

Keyboard shortcuts

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