Documentation
¶
Index ¶
- Constants
- Variables
- func ParseUID(raw string) (int64, error)
- func SearchQuickDateRange(value string, now time.Time) (startDate, endDate string, ok bool)
- type AccountBundleImportResult
- type AccountCheckRequest
- type AccountExportRequest
- type AccountExportResult
- type AccountImportRequest
- type AccountImportResult
- type AccountListResult
- type AccountRefreshRequest
- type AccountResult
- type AccountService
- func (s AccountService) Check(ctx context.Context, userID int64) (AccountResult, error)
- func (s AccountService) CheckWithRequest(ctx context.Context, request AccountCheckRequest) (AccountResult, error)
- func (s AccountService) Export(request AccountExportRequest) (AccountExportResult, error)
- func (s AccountService) Import(ctx context.Context, request AccountImportRequest) (AccountImportResult, error)
- func (s AccountService) ImportBundle(body []byte) (AccountBundleImportResult, error)
- func (s AccountService) List() (AccountListResult, error)
- func (s AccountService) RefreshWithRequest(ctx context.Context, request AccountRefreshRequest) (AccountResult, error)
- func (s AccountService) Remove(userID int64) (AccountResult, int64, error)
- func (s AccountService) Use(userID int64) (int64, error)
- type AuthBundleSDKClient
- type ClientRequest
- type ConfigMutationResult
- type ConfigService
- type ConfigStore
- type DownloadClient
- type DownloadFailure
- type DownloadManager
- type DownloadManagerFactory
- type DownloadQuality
- type DownloadReport
- type DownloadRequest
- type DownloadService
- type DownloadTargetClient
- type DownloadedArtwork
- type DownloadedFile
- type LoginCompleteRequest
- type LoginService
- type LoginStart
- type PagePlan
- type PageResult
- type SDKClient
- type SDKClientFactory
- type SDKClientRequest
- type SDKService
- func (s SDKService) AuthBundleClient(req SDKClientRequest) (AuthBundleSDKClient, error)
- func (s SDKService) Client(req SDKClientRequest) (SDKClient, error)
- func (s SDKService) CurrentUserID(ctx context.Context, req SDKClientRequest) (SDKClient, int64, error)
- func (s SDKService) JSONOut(override *bool) (bool, error)
- func (s SDKService) OpenOperation(ctx context.Context, req SDKClientRequest) (SDKClient, error)
- func (s SDKService) Runtime() (config.RuntimeConfig, error)
- type Services
Constants ¶
const ( AccountImportStatusAdded = "added" AccountImportStatusUpdated = "updated" )
const ( DownloadQualityOriginal = sdk.DownloadQualityOriginal DownloadQualityRegular = sdk.DownloadQualityRegular DownloadQualitySmall = sdk.DownloadQualitySmall DownloadQualityThumb = sdk.DownloadQualityThumb DownloadQualityMini = sdk.DownloadQualityMini )
Variables ¶
var ( ParsePageSpec = sdk.ParsePageSpec ValidateDownloadQuality = sdk.ValidateDownloadQuality )
Functions ¶
Types ¶
type AccountBundleImportResult ¶ added in v0.4.0
type AccountBundleImportResult struct {
Accounts []AccountImportResult `json:"accounts"`
DefaultUserID int64 `json:"default_user_id"`
}
type AccountCheckRequest ¶
type AccountExportRequest ¶ added in v0.4.0
type AccountExportResult ¶ added in v0.4.0
type AccountImportRequest ¶ added in v0.4.0
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 AccountRefreshRequest ¶ added in v0.7.1
AccountRefreshRequest 指定要刷新凭据与账号状态的已保存账号;UID 为零时使用默认账号。 OpenOperation 负责刷新 OAuth access token 及可能轮换的 refresh token,随后强制更新 profile。
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"`
PremiumStatus *bool `json:"premium_status,omitempty"`
PremiumStatusCheckedAt *time.Time `json:"premium_status_checked_at,omitempty"`
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
func (s AccountService) Export(request AccountExportRequest) (AccountExportResult, error)
Export 只通过 public SDK 读取本地认证快照;它不应用环境 token 或运行时 UID 覆写。
func (AccountService) Import ¶ added in v0.4.0
func (s AccountService) Import(ctx context.Context, request AccountImportRequest) (AccountImportResult, error)
func (AccountService) ImportBundle ¶ added in v0.4.0
func (s AccountService) ImportBundle(body []byte) (AccountBundleImportResult, error)
ImportBundle 解码并离线恢复 bundle;身份验证和 transport 均不参与此路径。
func (AccountService) List ¶
func (s AccountService) List() (AccountListResult, error)
func (AccountService) RefreshWithRequest ¶ added in v0.7.1
func (s AccountService) RefreshWithRequest(ctx context.Context, request AccountRefreshRequest) (AccountResult, error)
RefreshWithRequest 先建立一次稳定的已认证 SDK 操作快照,以刷新 access token 和可能 轮换的 refresh token;再强制读取个人 profile,将 Premium 资格与检查时间写回 auth store。
func (AccountService) Remove ¶
func (s AccountService) Remove(userID int64) (AccountResult, 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
JSONOverride *bool
NeedsAuth bool
}
ClientRequest 是 CLI 解析 flags 后的本地请求值。内容与下载命令会进一步转换为 SDKClientRequest;本类型不持有 Pixiv client,也不建立第二条认证或内容调用链。
type ConfigMutationResult ¶
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 DownloadFailure ¶ added in v0.7.0
DownloadFailure 是一次无状态批量下载中单个作品或作者列表读取的可展示失败。 Message 仅承接 SDK/下载器的安全错误文本,不保存用户输入的原始 URL。
type DownloadManager ¶ added in v0.4.0
type DownloadManager interface {
Download(context.Context, DownloadRequest) ([]DownloadedArtwork, error)
}
DownloadManager 接收完整 DownloadRequest,避免 CLI/MCP 与实现各自解析 pages/quality。
type DownloadManagerFactory ¶ added in v0.4.0
type DownloadManagerFactory func(client DownloadClient, downloadPath, filenameTemplate string) (DownloadManager, error)
type DownloadQuality ¶ added in v0.5.0
type DownloadQuality = sdk.DownloadQuality
质量与页选择契约由 public SDK 拥有,application 仅 alias 以便 CLI/MCP 共用。
type DownloadReport ¶ added in v0.7.0
type DownloadReport struct {
Items []DownloadedArtwork
Failures []DownloadFailure
}
DownloadReport 同时保留成功产物和独立失败,使作者全量下载无需持久化 job 状态也能说明结果。
type DownloadRequest ¶ added in v0.4.0
type DownloadRequest struct {
IllustIDs []int64
DownloadPath string
FilenameTemplate string
// Pages 为 1-based 页码列表;空表示全部页。由 ParsePageSpec 生成。
Pages []int
// Quality 默认 original。
Quality DownloadQuality
}
type DownloadService ¶
type DownloadService struct {
NewManager DownloadManagerFactory
}
func (DownloadService) Download ¶
func (s DownloadService) Download(ctx context.Context, client DownloadClient, request DownloadRequest) ([]DownloadedArtwork, error)
Download 把 operation snapshot 与本次运行配置交给 composition root 注入的下载器。
func (DownloadService) DownloadTargets ¶ added in v0.7.0
func (s DownloadService) DownloadTargets(ctx context.Context, client DownloadTargetClient, targets []sdk.Reference, request DownloadRequest) (DownloadReport, error)
DownloadTargets 依输入顺序下载作品,或展开作者的全部 illust、manga、ugoira。 单件失败会进入 report 并继续;用户取消则立即返回 context 错误,不伪装成普通部分失败。
type DownloadTargetClient ¶ added in v0.7.0
type DownloadTargetClient interface {
DownloadClient
UserArtworks(context.Context, sdk.UserArtworksRequest) (*sdk.IllustListResult, error)
}
DownloadTargetClient 在下载资源能力之外提供作者作品列表,用于把用户 URL 展开为视觉作品。 该接口仍只依赖顶层 public SDK 的规范化能力。
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 LoginCompleteRequest ¶
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 PageResult ¶ added in v0.4.0
PageResult 描述逻辑分页实际返回的条数以及上游是否仍有内容。
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)
SearchNovel(context.Context, sdk.SearchNovelRequest) (*sdk.NovelListResult, 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。