Documentation
¶
Overview ¶
Package record 持有 CLI 与 MCP 共用的 Pixiv 实体 JSON 记录投影,以及 CLI 的记录流与 列表输出。
记录保留源对象与未知字段,只固定顶层 id、type、url;解析时会拒绝额外的 JSON 值并 删除版本类元数据键。
包的组成:Record 是记录值,ParseRecordJSON 解析一行 NDJSON, ConsumeNDJSONRecords 逐行消费管道并写诊断;RunSDKList 与 RunPages 输出 CLI 列表, JSONArraySpool 暂存完整 JSON 文档。
Index ¶
- Constants
- func AppendJSONArray[T any](s *JSONArraySpool, items []T) error
- func ConsumeNDJSONRecords(ctx context.Context, in io.Reader, errOut io.Writer, operation string, ...) error
- func FanboxCreatorSummary(creator *fanbox.Creator) any
- func FanboxPost(post *fanbox.Post) any
- func FanboxPostText(post *fanbox.Post) string
- func FatalRecordPipeline(err error) error
- func ListValues[T any](items []T) ([]map[string]any, error)
- func NewRecordActionError(code string, err error) error
- func PageMetadata(plan pagination.PagePlan, result pagination.PageResult) pagination.PaginationOut
- func RecordFailureStrategy(value string) (bool, error)
- func RequiredRecordID(value Record) (int64, error)
- func RunPages[T any](ctx context.Context, out, errOut io.Writer, plan pagination.PagePlan, ...) error
- func RunSDKList[T, R any](ctx context.Context, out, errOut io.Writer, ...) error
- func WriteJSONLine(out io.Writer, value any) error
- func WriteJSONValue(out io.Writer, value any) error
- type Artwork
- type ArtworkPage
- type ArtworkSeriesSummary
- type BookmarkDetail
- type Comment
- type FanboxAssetOut
- type FanboxResourceIdentity
- type FanboxResourceRole
- type Format
- type ImageResource
- type JSONArraySpool
- type List
- type ListOutput
- type Novel
- type NovelSeries
- type PipelineDiagnosticError
- type Record
- func FromArtworks(items []Artwork) ([]Record, error)
- func FromNovels(items []Novel) ([]Record, error)
- func FromSDKArtworks(items []*pixiv.Artwork) ([]Record, error)
- func FromSDKNovels(items []*pixiv.Novel) ([]Record, error)
- func FromSDKRecommendations(items []pixiv.UserRecommendation) ([]Record, error)
- func FromSDKUsers(items []*pixiv.User) ([]Record, error)
- func FromUserPreviews(items []UserPreview) ([]Record, error)
- func NewIdentityRecord(id int64, recordType string) (Record, error)
- func ParseRecordJSON(line []byte) (Record, error)
- func RecordFromArtwork(artwork Artwork) (Record, error)
- func RecordFromMediaArtwork(artwork *pixiv.Artwork, originalPages []int) (Record, error)
- func RecordFromNovel(novel Novel) (Record, error)
- func RecordFromSDKArtwork(a *pixiv.Artwork, detail bool) (Record, error)
- func RecordFromSDKProfile(p *pixiv.Profile) (Record, error)
- func RecordFromUserDetail(detail UserDetail) (Record, error)
- func RecordFromUserPreview(preview UserPreview) (Record, error)
- type Resource
- type ResourceRef
- type Spool
- type Stamp
- type Tag
- type TrendingTag
- type User
- type UserDetail
- type UserPreview
- type UserProfile
- type UserProfilePublicity
- type UserWorkspace
Constants ¶
const ( // RecordFailureSkip 让失败记录只写诊断,然后继续处理后续记录。 RecordFailureSkip = "skip" // RecordFailureFailFast 遇到第一条失败记录就停止并返回非零退出状态。 RecordFailureFailFast = "fail-fast" )
Variables ¶
This section is empty.
Functions ¶
func AppendJSONArray ¶
func AppendJSONArray[T any](s *JSONArraySpool, items []T) error
AppendJSONArray 编码并追加一批数组元素。
func ConsumeNDJSONRecords ¶
func ConsumeNDJSONRecords(ctx context.Context, in io.Reader, errOut io.Writer, operation string, failFast bool, consume func(context.Context, Record) error) error
ConsumeNDJSONRecords 逐行解析 NDJSON 并顺序处理记录。它不使用 Scanner,避免 合法的大记录受隐藏 token 限制;每次回调结束后才读取下一行,以便取消后不启动新任务。
func FanboxCreatorSummary ¶ added in v1.4.0
FanboxCreatorSummary 保留列表的 ID 摘要;上游列表附带的资料不改变既有输出。
func FanboxPost ¶ added in v1.4.0
FanboxPost 保留 CLI 列表的完整外部形状;SDK 正文 Payload 与 URL 留在绑定对象内。
func FanboxPostText ¶ added in v1.4.0
FanboxPostText 按正文顺序保留纯文本、段落和说明文字。
func FatalRecordPipeline ¶
FatalRecordPipeline 标记无法继续读取记录流的失败,例如 stdout/stderr I/O 错误。 这类错误由调用方原样返回,不会被写成一条记录动作失败。
func ListValues ¶
ListValues 把非实体列表投影为 JSON 对象;有 id 时归一为字符串,保留其余字段。
func NewRecordActionError ¶
NewRecordActionError 给一条记录动作失败附上稳定 code;err 为 nil 时返回 nil。
func PageMetadata ¶
func PageMetadata(plan pagination.PagePlan, result pagination.PageResult) pagination.PaginationOut
PageMetadata 根据分页计划保留显式 limit 与实际返回条数。
func RecordFailureStrategy ¶
RecordFailureStrategy 把 --on-error 取值转换成是否遇错即停;非法取值返回错误。
func RequiredRecordID ¶
RequiredRecordID 取出记录的正整数 ID;缺失、非数字或非正数都返回错误。
func RunPages ¶
func RunPages[T any](ctx context.Context, out, errOut io.Writer, plan pagination.PagePlan, jsonOut, ndjson bool, printText func([]T) error, toJSON func(T) any, fetch func(context.Context, sdk.Cursor) (sdk.Page[T], error)) error
RunPages 统一 FANBOX 列表命令的 JSON / NDJSON / 文本输出与分页。JSON 只有完整文档 写入临时文件成功后才交给 stdout。
func RunSDKList ¶ added in v1.4.0
func RunSDKList[T, R any](ctx context.Context, out, errOut io.Writer, execute func(context.Context, R, func(context.Context, int64, *pixiv.Client) (bool, error)) error, request R, plan pagination.PagePlan, format Format, list List[T], fetch func(context.Context, int64, *pixiv.Client, sdk.Cursor) ([]T, sdk.Cursor, error)) error
RunSDKList 让新 SDK 共用列表输出与提交边界;每次尝试使用自己的已选 UID。
func WriteJSONLine ¶
WriteJSONLine 输出一个紧凑 JSON 值并追加换行。
Types ¶
type Artwork ¶ added in v1.4.0
type Artwork struct {
ID int64 `json:"id"`
Title string `json:"title"`
Caption string `json:"caption"`
ContentType pixiv.ContentType `json:"content_type"`
Tags []Tag `json:"tags"`
User User `json:"user"`
PublishedAt time.Time `json:"published_at"`
UpdatedAt *time.Time `json:"updated_at,omitempty"`
TotalBookmarks int `json:"total_bookmarks"`
TotalViews int `json:"total_views"`
Width int `json:"width"`
Height int `json:"height"`
PageCount int `json:"page_count"`
XRestrict int `json:"x_restrict"`
AIType int `json:"ai_type"`
Tools []string `json:"tools,omitempty"`
Cover ImageResource `json:"cover,omitzero"`
Pages []ArtworkPage `json:"pages,omitempty"`
IsBookmarked *bool `json:"is_bookmarked,omitempty"`
IsMuted *bool `json:"is_muted,omitempty"`
Visible *bool `json:"visible,omitempty"`
SanityLevel *int `json:"sanity_level,omitempty"`
RestrictionAttributes *[]string `json:"restriction_attributes,omitempty"`
Series *ArtworkSeriesSummary `json:"series,omitempty"`
TotalComments *int `json:"total_comments,omitempty"`
}
Artwork 保存作品输出快照;列表省略 Pages,详情按上游页序填充。
type ArtworkPage ¶ added in v1.4.0
type ArtworkPage struct {
PageIndex int `json:"page_index"`
Image ImageResource `json:"image"`
Width int `json:"width"`
Height int `json:"height"`
}
ArtworkPage 保留作品页序;PageIndex 从零开始。
type ArtworkSeriesSummary ¶ added in v1.4.0
ArtworkSeriesSummary 交付作品所属系列的 ID 与标题。
type BookmarkDetail ¶ added in v1.4.0
type BookmarkDetail struct {
Restrict pixiv.Restrict `json:"restrict"`
Tags []string `json:"tags"`
}
BookmarkDetail 保留 CLI 收藏详情字段与空标签的 null 输出。
func (BookmarkDetail) MarshalJSON ¶ added in v1.4.0
func (value BookmarkDetail) MarshalJSON() ([]byte, error)
MarshalJSON 保留空标签的既有输出。
type Comment ¶ added in v1.4.0
type Comment struct {
ID int64 `json:"id"`
User User `json:"user"`
Comment string `json:"comment"`
CreatedAt time.Time `json:"created_at"`
ParentComment *Comment `json:"parent_comment"`
}
Comment 保存评论及父评论链;缺失的 ParentComment 输出为 null。
type FanboxAssetOut ¶ added in v1.4.0
type FanboxAssetOut struct {
ID string `json:"id"`
Kind string `json:"kind"`
Name string `json:"name"`
Resource Resource `json:"resource"`
Thumbnail fanboxImageResource `json:"thumbnail"`
}
FanboxAssetOut 保留公开资源引用和资产字段,省略下载 URL。
func FanboxAssets ¶ added in v1.4.0
func FanboxAssets(post *fanbox.Post) []FanboxAssetOut
FanboxAssets 保持图片先于附件的顺序;资源身份与正文下载地址分离。
type FanboxResourceIdentity ¶ added in v1.4.0
type FanboxResourceIdentity struct {
Role FanboxResourceRole `json:"k"`
Creator string `json:"c,omitempty"`
Post string `json:"p,omitempty"`
Asset string `json:"a,omitempty"`
}
FanboxResourceIdentity 保持已有资源引用载荷;地址、签名与凭据不进入载荷。
type FanboxResourceRole ¶ added in v1.4.0
type FanboxResourceRole string
FanboxResourceRole 标识公开资源引用的媒体角色。
const ( // FanboxCreatorIcon 标识创作者头像。 FanboxCreatorIcon FanboxResourceRole = "creator_icon" // FanboxCreatorCover 标识创作者封面。 FanboxCreatorCover FanboxResourceRole = "creator_cover" // FanboxPostImage 标识帖子图片。 FanboxPostImage FanboxResourceRole = "post_image" // FanboxPostFile 标识帖子附件。 FanboxPostFile FanboxResourceRole = "post_file" )
type ImageResource ¶ added in v1.4.0
type ImageResource struct {
Resource Resource `json:"resource"`
Variant string `json:"variant"`
Width int `json:"width"`
Height int `json:"height"`
}
ImageResource 交付图片的稳定资源引用、尺寸与角色。
func (ImageResource) IsZero ¶ added in v1.4.0
func (image ImageResource) IsZero() bool
IsZero 报告图片是否缺少稳定资源引用。
type JSONArraySpool ¶
type JSONArraySpool struct {
*Spool
// contains filtered or unexported fields
}
JSONArraySpool 逐条暂存数组,避免把全部详情或列表保存在内存中。
func NewJSONArraySpool ¶
func NewJSONArraySpool() (*JSONArraySpool, error)
NewJSONArraySpool 创建一个尚未结束的 JSON 数组。
func (*JSONArraySpool) Commit ¶
func (s *JSONArraySpool) Commit(out io.Writer) error
Commit 结束数组后复制到 out。
func (*JSONArraySpool) CommitList ¶
func (s *JSONArraySpool) CommitList(out io.Writer, page pagination.PaginationOut) error
CommitList 结束数组,并写出与 NDJSON 共用元素的 records/pagination 文档。
type List ¶
type List[T any] struct { // PostFilter 只筛选已经解析的分页窗口,不额外获取上游结果。 PostFilter func([]T) []T // Print 输出一批文本结果;offset 是本批在整体结果中的起点。 Print func(items []T, offset int) error // RecordValue 把一项转成 JSON/NDJSON 共用记录。 RecordValue func(T) (any, error) }
List 描述一次分页列表的输出方式;JSON 与 NDJSON 共用记录投影。
type ListOutput ¶
type ListOutput[T any] struct { Records []T `json:"records"` Pagination pagination.PaginationOut `json:"pagination"` }
ListOutput 写出列表文档;空列表编码为 []。
func NewListOutput ¶
func NewListOutput[T any](items []T, plan pagination.PagePlan, result pagination.PageResult) ListOutput[T]
NewListOutput 把分页结果和已投影的记录组成列表文档。
type Novel ¶ added in v1.4.0
type Novel struct {
ID int64 `json:"id"`
Title string `json:"title"`
Caption string `json:"caption"`
User User `json:"user"`
Tags []Tag `json:"tags"`
PublishedAt time.Time `json:"published_at"`
UpdatedAt *time.Time `json:"updated_at"`
XRestrict int `json:"x_restrict"`
TextLength int `json:"text_length"`
IsOriginal bool `json:"is_original"`
TotalBookmarks int `json:"total_bookmarks"`
TotalViews int `json:"total_views"`
Cover ImageResource `json:"cover,omitzero"`
}
Novel 保存小说元数据;缺失的 UpdatedAt 输出为 null。
type NovelSeries ¶ added in v1.4.0
type NovelSeries struct {
ID int64 `json:"id"`
Title string `json:"title"`
Caption string `json:"caption"`
User User `json:"user"`
IsConcluded bool `json:"is_concluded"`
}
NovelSeries 保存小说系列元数据,作者使用 user 字段。
func NovelSeriesOutput ¶ added in v1.4.0
func NovelSeriesOutput(series *pixiv.NovelSeries) (NovelSeries, error)
NovelSeriesOutput 保留系列元数据的 user 字段,不序列化绑定对象与分页状态。
type PipelineDiagnosticError ¶
type PipelineDiagnosticError struct{}
PipelineDiagnosticError 表示错误已经按管道契约写入 stderr。它让根命令保留 非零退出状态,同时不再附加普通的 "error:" 文本破坏逐行诊断。
func (*PipelineDiagnosticError) Error ¶
func (*PipelineDiagnosticError) Error() string
Error 返回固定文本;逐行诊断已经写入 stderr。
type Record ¶
type Record struct {
// contains filtered or unexported fields
}
Record 保留可在 CLI 管道和 MCP 之间共享的 Pixiv 实体 JSON 记录。 它保留源对象和外部程序提供的未知字段,同时固定顶层 id、type、url。 零值尚未初始化;读取身份字段前应通过构造或 JSON 解析入口建立记录。
func FromArtworks ¶
FromArtworks 批量构造 artwork records。
func FromSDKArtworks ¶ added in v1.4.0
FromSDKArtworks 保留列表记录省略 pages 的契约。
func FromSDKNovels ¶ added in v1.4.0
FromSDKNovels 为新 SDK 聚合列表构造小说记录。
func FromSDKRecommendations ¶ added in v1.4.0
func FromSDKRecommendations(items []pixiv.UserRecommendation) ([]Record, error)
FromSDKRecommendations 保留推荐用户及其样例作品的记录形状。
func FromSDKUsers ¶ added in v1.4.0
FromSDKUsers 将普通用户列表投影为既有预览记录。
func FromUserPreviews ¶
func FromUserPreviews(items []UserPreview) ([]Record, error)
FromUserPreviews 批量构造 user records。
func NewIdentityRecord ¶
NewIdentityRecord 构造只包含 Pixiv canonical identity 的管道记录。 artwork 表示尚无法可靠判断 illust/manga/ugoira 子类型的作品身份。
func ParseRecordJSON ¶
ParseRecordJSON 解析一行 NDJSON 中的单个对象,并保留未知字段。
func RecordFromArtwork ¶
RecordFromArtwork 将作品输出快照映射为管道记录。
func RecordFromMediaArtwork ¶ added in v1.4.0
RecordFromMediaArtwork 保留画廊元数据的记录字段,只把图片引用投影为可读的对象身份。 originalPages 来自可信元数据中的原图角色,缓存不依赖 SDK 的运行时标记。 定位 URL 与账号绑定留在 SDK 内;调用方用作品 ID 和页号调用媒体工具。
func RecordFromNovel ¶
RecordFromNovel 将小说输出快照映射为管道记录。
func RecordFromSDKArtwork ¶ added in v1.4.0
RecordFromSDKArtwork 将新 SDK 作品投影为既有管道记录。
func RecordFromSDKProfile ¶ added in v1.4.0
RecordFromSDKProfile 把新 SDK 的完整用户详情投影为管道记录。
func RecordFromUserDetail ¶
func RecordFromUserDetail(detail UserDetail) (Record, error)
RecordFromUserDetail 将用户详情映射为管道记录。
func RecordFromUserPreview ¶
func RecordFromUserPreview(preview UserPreview) (Record, error)
RecordFromUserPreview 将用户预览映射为管道记录。
func (Record) MarshalJSON ¶
MarshalJSON 保留记录中的未知字段,并始终输出一个 JSON 对象。
func (*Record) UnmarshalJSON ¶
UnmarshalJSON 让 MCP structured content 等 JSON 消费者可以把 records 重新解码为 Record,同时复用 NDJSON 输入的完整校验、ID 归一与版本元数据清理规则。
type Resource ¶ added in v1.4.0
type Resource struct {
Ref ResourceRef `json:"ref"`
RequiresCredentials bool `json:"requires_credentials,omitempty"`
}
Resource 只交付稳定引用与凭据需求,资源地址保留在 SDK 绑定对象内。
func FanboxImageResource ¶ added in v1.4.0
func FanboxImageResource(role FanboxResourceRole, creator, post, asset, locator string) Resource
FanboxImageResource 将已验证的图片地址投影为稳定资源身份;URL 不进入输出。
func (Resource) MarshalJSON ¶ added in v1.4.0
MarshalJSON 保留缺失资源的 null 输出。
type ResourceRef ¶ added in v1.4.0
type ResourceRef struct {
// contains filtered or unexported fields
}
ResourceRef 保留 CLI/MCP 的版本化媒体身份编码。
func ParseResourceRef ¶ added in v1.4.0
func ParseResourceRef(text string) (ResourceRef, error)
ParseResourceRef 在媒体输入边界校验版本与必要身份字段。
func (ResourceRef) MarshalJSON ¶ added in v1.4.0
func (r ResourceRef) MarshalJSON() ([]byte, error)
MarshalJSON 把资源引用编码为字符串。
func (ResourceRef) Payload ¶ added in v1.4.0
func (r ResourceRef) Payload() []byte
Payload 返回已经解析的产品身份载荷。
func (ResourceRef) Product ¶ added in v1.4.0
func (r ResourceRef) Product() string
Product 返回已经解析的产品命名空间。
func (ResourceRef) String ¶ added in v1.4.0
func (r ResourceRef) String() string
String 返回可放在路由中的稳定引用。
type Stamp ¶ added in v1.4.0
type Stamp struct {
ID int64 `json:"id"`
Image ImageResource `json:"image"`
}
Stamp 交付评论贴纸 ID 与图片引用。
type Tag ¶ added in v1.4.0
type Tag struct {
Name string `json:"name"`
TranslatedName string `json:"translated_name,omitempty"`
}
Tag 作品和小说共用标签,缺少翻译时省略 translated_name。
type TrendingTag ¶ added in v1.4.0
type TrendingTag struct {
Tag string `json:"tag"`
TranslatedName string `json:"translated_name"`
Artwork Artwork `json:"artwork"`
}
TrendingTag 保存趋势标签与样例作品。
type User ¶ added in v1.4.0
type User struct {
ID int64 `json:"id"`
Name string `json:"name"`
Account string `json:"account"`
Comment string `json:"comment"`
IsFollowed bool `json:"is_followed"`
ProfileImage ImageResource `json:"profile_image,omitzero"`
}
User 保存用户摘要,头像仅交付稳定引用。
type UserDetail ¶ added in v1.4.0
type UserDetail struct {
User User `json:"user"`
Profile UserProfile `json:"profile"`
ProfilePublicity UserProfilePublicity `json:"profile_publicity"`
Workspace UserWorkspace `json:"workspace"`
}
UserDetail 保留用户详情的 profile/profile_publicity/workspace 布局。
func UserDetailOutput ¶ added in v1.4.0
func UserDetailOutput(p *pixiv.Profile) (UserDetail, error)
UserDetailOutput 保留用户详情的 profile/profile_publicity/workspace 布局。
type UserPreview ¶ added in v1.4.0
type UserPreview struct {
User User `json:"user"`
Illusts []Artwork `json:"illusts"`
Novels []Novel `json:"novels"`
}
UserPreview 保存用户及样例作品;列表投影保留空的 illusts/novels 数组。
func RecommendationOutput ¶ added in v1.4.0
func RecommendationOutput(r pixiv.UserRecommendation) (UserPreview, error)
RecommendationOutput 保留推荐用户及其作品、小说样例的输出形状。
func UserPreviewOutput ¶ added in v1.4.0
func UserPreviewOutput(u *pixiv.User) (UserPreview, error)
UserPreviewOutput 为用户列表保留空的 illusts/novels 数组。
type UserProfile ¶ added in v1.4.0
type UserProfile struct {
Webpage string `json:"webpage"`
Gender string `json:"gender"`
BirthDay string `json:"birth_day"`
BirthYear int `json:"birth_year"`
Region string `json:"region"`
CountryCode string `json:"country_code"`
Job string `json:"job"`
TotalFollowUsers int `json:"total_follow_users"`
TotalMyPixivUsers int `json:"total_my_pixiv_users"`
TotalIllusts int `json:"total_illusts"`
TotalManga int `json:"total_manga"`
TotalNovels int `json:"total_novels"`
TotalIllustBookmarks int `json:"total_illust_bookmarks"`
TotalIllustSeries int `json:"total_illust_series"`
TotalNovelSeries int `json:"total_novel_series"`
BackgroundImageURL string `json:"background_image_url"`
TwitterAccount string `json:"twitter_account"`
TwitterURL string `json:"twitter_url"`
PawooURL string `json:"pawoo_url"`
IsPremium bool `json:"is_premium"`
IsUsingCustomProfileImage bool `json:"is_using_custom_profile_image"`
}
UserProfile 保存用户公开资料的计数与链接。
type UserProfilePublicity ¶ added in v1.4.0
type UserProfilePublicity struct {
Gender bool `json:"gender"`
Region bool `json:"region"`
BirthDay bool `json:"birth_day"`
BirthYear bool `json:"birth_year"`
Job bool `json:"job"`
Pawoo bool `json:"pawoo"`
}
UserProfilePublicity 记录用户资料字段的公开状态。
type UserWorkspace ¶ added in v1.4.0
type UserWorkspace struct {
PC string `json:"pc"`
Monitor string `json:"monitor"`
Tool string `json:"tool"`
Scanner string `json:"scanner"`
Tablet string `json:"tablet"`
Mouse string `json:"mouse"`
Printer string `json:"printer"`
Desktop string `json:"desktop"`
Music string `json:"music"`
Desk string `json:"desk"`
Chair string `json:"chair"`
Comment string `json:"comment"`
WorkspaceImageURL string `json:"workspace_image_url"`
}
UserWorkspace 保存用户声明的工作环境与工具。
Source Files
¶
- fanbox_output.go
- fanbox_resource.go
- identity.go
- json.go
- list.go
- media.go
- pixiv.go
- pixiv_artwork.go
- pixiv_bookmark.go
- pixiv_comment.go
- pixiv_comment_output.go
- pixiv_novel.go
- pixiv_output.go
- pixiv_resource.go
- pixiv_trending.go
- pixiv_user.go
- pixiv_user_output.go
- record.go
- resource.go
- sdk_list.go
- spool.go
- stream.go
- values.go