reseed

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Nov 21, 2026 License: MIT Imports: 24 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package reseed 实现 IYUU 辅种:把下载器里已经下完的种子的 info hash 交给 IYUU 查询,找出其他站点上数据相同的种子, 从站点下载种子文件、核对 info hash 与文件列表后,暂停加入同一台下载器(保存路径用原种子的),校验到 100% 才开始做种。 加入、校验与回滚复用转移做种的任务(transfer 包,任务种类 reseed)。默认关闭;token 加密保存。

Index

Constants

View Source
const (
	// RecordActive 是任务还没结束(等待加入、加入中、校验中)
	RecordActive = "active"
	// RecordDone 是已辅种(校验通过、开始做种)
	RecordDone = "done"
	// RecordFailed 是失败:下载或核对没通过,或者任务失败
	RecordFailed = "failed"
	// RecordRolledBack 是已撤回(校验没到 100%,撤掉了加进去的种子)
	RecordRolledBack = "rolled_back"
	// RecordCanceled 是任务被取消
	RecordCanceled = "canceled"
	// RecordGone 是站点上已经没有这个种子
	RecordGone = "gone"
	// RecordMissing 是记录指向的任务已经不在了(被别的途径删掉,结果不知道)
	RecordMissing = "missing"
)

记录的结果(页面上的分组;列表按它筛选)。记录自己的状态说了算的(失败、站点已删除,以及清除任务时写进记录的结果)直接用; 建了任务的看任务现在的状态。

View Source
const (
	MaxRetryRecords  = 100
	MaxDeleteRecords = 500
)

一次最多重试、删除几条记录。

View Source
const (
	SkipRecordMissing = "记录已经不在了"
	SkipNotRetryable  = "结果已经变了,不用重试"
	SkipNoDownloader  = "下载器不可用"
)

重试时跳过的原因(另见 run.go 里的跳过原因)。

View Source
const (
	// EndStopped 是被停止(手动停止、暂停太久、运行中换了 token)
	EndStopped = "stopped"
	// EndLimited 是超时、IYUU 限流或到了每天的请求上限
	EndLimited = "limited"
	// EndShutdown 是 pt-tools 正在退出
	EndShutdown = "shutdown"
)

提前停下的种类。

View Source
const (
	SkipNotSelected = "站点不在辅种范围"
	SkipExists      = "下载器里已经有"
	SkipTried       = "已经尝试过"
	SkipDailyLimit  = "今天这个站点已经加满"
	SkipActive      = "已有进行中的任务"
	// SkipNoSource 是重试时原种子已经不在下载器里了(或者还没下完)
	SkipNoSource = "原种子不在下载器里"
)

跳过的原因。

Variables

View Source
var (
	// ErrRunStopped 是手动停止。
	ErrRunStopped = errors.New("这一轮被停止")
	// ErrRunTimeout 是这一轮用完了时限(暂停的时间不算)。
	ErrRunTimeout = errors.New("这一轮超过时限,已停下")
	// ErrPausedTooLong 是暂停太久,自动停止(免得忘了继续以后定时的轮次一直跑不了)。
	ErrPausedTooLong = errors.New("暂停太久,已自动停止")
)

一轮被提前停下的原因(这一轮 ctx 的 cause)。

View Source
var (
	// ErrRecordNotFound 表示辅种记录不存在。
	ErrRecordNotFound = errors.New("辅种记录不存在")
	// ErrNoPendingJob 表示记录没有还在等待加入下载器的任务(只有这种任务能取消)。
	ErrNoPendingJob = errors.New("这条记录没有等待加入下载器的任务")
	// ErrNothingToRetry 表示选中的记录都不能重试。
	ErrNothingToRetry = fmt.Errorf("%w: 选中的记录都不能重试:只有失败、站点已删除、已撤回、已取消和任务已删除的记录可以重试", ErrInvalid)
)
View Source
var (
	// ErrInvalid 表示设置有问题。
	ErrInvalid = errors.New("辅种设置无效")
	// ErrNoSites 表示没有可以辅种的站点。
	ErrNoSites = errors.New("没有可以辅种的站点:IYUU 支持的站点里,pt-tools 还没有配置或没有选中")
)
View Source
var (
	// ErrRunNotFound 表示轮次不存在。
	ErrRunNotFound = errors.New("辅种轮次不存在")
	// ErrNotContinuable 表示这一轮不能继续:只有最近一个不是重试的轮次、提前停下了(被停止、限流、超时或退出)才能继续。
	ErrNotContinuable = errors.New("这一轮不能继续:只有最近一个提前停下的轮次(重试的除外)可以继续")
)
View Source
var ErrIYUUDailyCap = errors.New("今天请求 IYUU 的次数到了设置的上限,明天再试(可以在设置里调高或改成不限)")

ErrIYUUDailyCap 表示今天请求 IYUU 的次数到了设置的上限。

Functions

func IYUULimited

func IYUULimited(err error) bool

IYUULimited 报告 err 是不是 IYUU 的限流(429、冷却中或到了每天的上限)。

func RecordRetryable

func RecordRetryable(result string) bool

RecordRetryable 报告这个结果的记录能不能重试。

func RoundChanged

func RoundChanged(res RunResult, status string) bool

RoundChanged 报告这一轮算不算「有变化」:加入了辅种、有失败,或者没跑完(部分出错、提前停下、被停止、未能开始)。

func SameFiles

func SameFiles(a, b []FileEntry) (bool, string)

SameFiles 报告两份文件列表是否完全一样(路径与大小逐个相同,顺序无关)。不一样时第二个返回值写明第一处差别。 辅种只有在文件完全一样时才加:同一份数据才能被新种子校验到 100%。

Types

type AttemptView

type AttemptView struct {
	models.ReseedAttempt
	JobMessage string `json:"job_message,omitempty"`
	JobMissing bool   `json:"job_missing,omitempty"`
}

AttemptView 是轮次里的一次尝试。任务还在时 JobState 是任务现在的状态;JobMissing 表示任务已经不在了、结果不知道。

type Config

type Config struct {
	DB          *gorm.DB
	Cipher      TokenCipher
	Transfer    *transfer.Service
	Downloaders transfer.Downloaders
	// Sites 按站点名取共享的站点实例;SiteIDs 返回 pt-tools 里已配置(注册了实例)的站点。
	Sites    func(name string) (v2.Site, bool)
	SiteIDs  func() []string
	Resolver *v2.TrackerResolver
	// NewClient 按 token 建 IYUU 客户端,测试里换成假服务。
	NewClient func(token string) *iyuu.Client
	Now       func() time.Time
	// Sleep 是限流时的等待,测试里不真等。
	Sleep  func(ctx context.Context, d time.Duration) error
	Logger *zap.SugaredLogger
}

Config 是 Service 的依赖。

type Control

type Control struct {
	// contains filtered or unexported fields
}

Control 暂停、继续一轮辅种,并管这一轮的时限(暂停的时间不算)与一次暂停的最长时间。 这一轮在检查点(每次查询 IYUU、每个候选之前)调用 Wait:暂停时停在那里,继续以后接着跑。

func NewControl

func NewControl(cfg ControlConfig) *Control

NewControl 构造控制器;调用 Start 以后才开始计时。

func (*Control) Pause

func (c *Control) Pause() bool

Pause 暂停(正在下载的那一个做完以后,在下一个检查点停下);已经暂停时返回 false。

func (*Control) Resume

func (c *Control) Resume() (time.Duration, bool)

Resume 继续,返回这一次暂停了多久;没在暂停时返回 false。

func (*Control) Start

func (c *Control) Start(ctx context.Context)

Start 开始计时,直到 ctx 结束。

func (*Control) State

func (c *Control) State() (paused bool, since time.Time, total time.Duration)

State 报告是不是在暂停、这一次暂停从什么时候开始,以及一共暂停过多久(含正在进行的这一次)。

func (*Control) Wait

func (c *Control) Wait(ctx context.Context) (time.Duration, error)

Wait 是检查点:暂停时等到继续或者这一轮被取消。返回在这里等了多久,以及 ctx 的错误(被取消时)。

type ControlConfig

type ControlConfig struct {
	// Budget 是这一轮的时限,暂停的时间不算;0 表示不限。
	Budget time.Duration
	// MaxPause 是一次暂停最长多久,超过就停下这一轮;0 表示不限。
	MaxPause time.Duration
	// Cancel 在超时(ErrRunTimeout)或暂停太久(ErrPausedTooLong)时取消这一轮。
	Cancel context.CancelCauseFunc
	Now    func() time.Time
	// NewTimer 建计时器,默认用 time.NewTimer。
	NewTimer func(d time.Duration) Timer
}

ControlConfig 是 Control 的设置。

type CoolingError

type CoolingError struct {
	Until time.Time
}

CoolingError 表示 IYUU 限流以后还在冷却:Until 之前不发请求。

func (*CoolingError) Error

func (e *CoolingError) Error() string

type DeleteResult

type DeleteResult struct {
	Deleted int64 `json:"deleted"`
	Active  int64 `json:"active"`
}

DeleteResult 是删除记录的结果:Active 是任务还没结束、没有删的条数。

type FileEntry

type FileEntry struct {
	Path string
	Size int64
}

FileEntry 是种子里的一个文件:相对保存路径的路径(用 / 分隔)与大小。

func DownloaderFiles

func DownloaderFiles(files []downloader.TorrentFile) []FileEntry

DownloaderFiles 把下载器的文件列表换成 FileEntry(分隔符统一成 /)。

func TorrentFiles

func TorrentFiles(data []byte) ([]FileEntry, error)

TorrentFiles 列出 .torrent 文件里的文件:单文件种子是 name;多文件种子是 name/path...(与下载器的文件列表同一写法)。

type IYUULimit

type IYUULimit struct {
	At       time.Time `json:"at"`
	Endpoint string    `json:"endpoint"`
	Message  string    `json:"message"`
	// RetryAfter 是 IYUU 给的 Retry-After(秒);ResetAt、Limit 是 X-RateLimit-Reset 与 X-RateLimit-Limit(没给时不写)
	RetryAfter int        `json:"retry_after"`
	ResetAt    *time.Time `json:"reset_at,omitempty"`
	Limit      int        `json:"limit,omitempty"`
	// Until 是冷却到什么时候
	Until time.Time `json:"until"`
}

IYUULimit 是最近一次限流的情况。

type RecordFilter

type RecordFilter struct {
	Result string
	Site   string
	Query  string
}

RecordFilter 是记录列表的筛选,都可以为空:Result 是上面的结果之一,Query 匹配种子名或 info hash。

type RecordPage

type RecordPage struct {
	Items    []RecordView `json:"items"`
	Total    int64        `json:"total"`
	Page     int          `json:"page"`
	PageSize int          `json:"page_size"`
	Sites    []string     `json:"sites"`
}

RecordPage 是一页记录。Sites 是记录里出现过的站点(筛选用)。

type RecordView

type RecordView struct {
	models.ReseedRecord
	Result     string `json:"result"`
	JobState   string `json:"job_state,omitempty"`
	JobMessage string `json:"job_message,omitempty"`
	JobMissing bool   `json:"job_missing,omitempty"`
}

RecordView 是记录列表里的一项:记录加上结果与任务现在的状态。JobMissing 表示记录指向的任务已经不在了(结果不知道)。

type Round

type Round struct {
	ID      uint
	Trigger string
	Status  string
	Reason  string
	Summary string
	Took    time.Duration
	Result  RunResult
}

Round 是推送需要的这一轮的情况:Took 是用了多久(不含暂停的时间),Reason 是没跑完的原因。

type RoundNotice

type RoundNotice struct {
	Title string
	Text  string
	// Fields 是事件 reseed.round 的变量
	Fields map[string]any
}

RoundNotice 是一轮结束以后推送的内容。

func NewRoundNotice

func NewRoundNotice(r Round) RoundNotice

NewRoundNotice 写这一轮的推送:正文只有计数与状态,不列种子名。

type RunDetail

type RunDetail struct {
	RunView
	Steps []models.ReseedRunStep `json:"steps"`
}

RunDetail 是一轮的详情:加上步骤。

type RunOptions

type RunOptions struct {
	// RunID 是这一轮的轮次记录:尝试记在它名下、每查完一批写一次进度;0 时不记(单测直接调 Run)。
	RunID uint
	// After 是从哪个 info hash 之后开始查(接着上一轮查);空串是从头。
	After string
	// Control 在检查点上暂停这一轮;nil 时不暂停。
	Control *Control
	// Progress 在每查完一批、每个尝试以后收到结果的副本(页面上的实时进度)。
	Progress func(RunResult)
}

RunOptions 是一轮的选项。

type RunResult

type RunResult struct {
	Downloaders int `json:"downloaders"`
	// Hashes 是这一轮要查询的种子数(接着上一轮查时只算后面的那些;重试轮次是选中的记录数)
	Hashes int `json:"hashes"`
	// Batches 是要查询 IYUU 的批数,BatchesDone 是查完并处理完的批数(重试轮次没有批)
	Batches     int `json:"batches"`
	BatchesDone int `json:"batches_done"`
	Candidates  int `json:"candidates"`
	Created     int `json:"created"`
	Failed      int `json:"failed"`
	// Gone 是站点上已经没有的种子(不算失败,以后不再试)
	Gone int `json:"gone"`
	// Interrupted 是被停止、超时或退出打断的尝试(不记失败,以后照常再试)
	Interrupted int `json:"interrupted"`
	// IYUUCalls 是这一轮请求 IYUU 的次数
	IYUUCalls int            `json:"iyuu_calls"`
	Skipped   map[string]int `json:"skipped,omitempty"`
	Errors    []string       `json:"errors,omitempty"`
	// Stopped 说明这一轮为什么提前停下(限流、被停止等)。
	Stopped string `json:"stopped,omitempty"`
	// End 是提前停下的种类(EndStopped、EndLimited、EndShutdown),跑完时为空。
	End string `json:"end,omitempty"`
	// Cursor 是最后一个完整处理完的批的最后一个 info hash(接着查时从它之后开始)。
	Cursor string `json:"-"`
	// Retry 表示这是重试轮次(汇总的写法不同)。
	Retry bool `json:"-"`
	// contains filtered or unexported fields
}

RunResult 是一轮辅种的结果。

func (RunResult) SkippedTotal

func (r RunResult) SkippedTotal() int

SkippedTotal 是跳过的总数。

func (RunResult) Summary

func (r RunResult) Summary() string

Summary 是写进设置 last_result 与轮次记录的一句话。

type RunView

type RunView struct {
	models.ReseedRun
	// SkippedDetail 是跳过的原因与个数
	SkippedDetail map[string]int `json:"skipped_detail,omitempty"`
	// Continuable 表示可以「继续」:最近一个不是重试的轮次,而且提前停下了
	Continuable bool `json:"continuable,omitempty"`
}

RunView 是轮次列表里的一行。

type Service

type Service struct {
	// contains filtered or unexported fields
}

Service 管理辅种设置并运行辅种。

func New

func New(cfg Config) *Service

New 构造 Service。

func (*Service) CanContinue

func (s *Service) CanContinue(ctx context.Context, id uint) (string, error)

CanContinue 报告能不能继续 id 这一轮,能的话返回起点。

func (*Service) CancelJobs

func (s *Service) CancelJobs(ctx context.Context, ids []uint) int

CancelJobs 取消还没加入下载器的任务,返回取消了几个;已经加入的跳过。

func (*Service) CancelRecordJob

func (s *Service) CancelRecordJob(ctx context.Context, id uint) error

CancelRecordJob 取消记录对应的、还在等待加入下载器的任务;已经加入的不能取消(transfer.ErrNotCancelable)。

func (*Service) CheckRetry

func (s *Service) CheckRetry(ctx context.Context, ids []uint) error

CheckRetry 检查选中的记录里有没有能重试的(重试轮次开始以前调用)。

func (*Service) ClearFinishedJobs

func (s *Service) ClearFinishedJobs(ctx context.Context) (int64, error)

ClearFinishedJobs 删除已经结束的辅种任务,返回删除的条数。删除前把任务的结果写进引用它的辅种记录 (记录不再指向任务;不改记录的更新时间,重试间隔按它算),并把结果与完成时间抄进建成它的尝试行(统计按它算)。 都在同一个事务里:不会出现任务删了、结果没抄上。

func (*Service) ContinuePoint

func (s *Service) ContinuePoint(ctx context.Context) (string, *uint, error)

ContinuePoint 是定时轮次的起点:最近一个不是重试的轮次提前停下时接着它往下查(返回它的编号),否则从头开始。

func (*Service) DailyReportLine

func (s *Service) DailyReportLine(ctx context.Context, day, label string) (string, error)

DailyReportLine 是每日战报里辅种那一行:设置里没开「每日战报」、或者这天没有建成、成功、失败与站点已删除时为空串。 day 是战报统计的日期(YYYY-MM-DD,进程时区),label 是写在行首的「今日」「昨日」(空串按「今日」); 数字与统计面板同一套算法。不写跳过:每一轮都会把同一个种子再算一次。

func (*Service) DeleteRecords

func (s *Service) DeleteRecords(ctx context.Context, ids []uint) (DeleteResult, error)

DeleteRecords 删除记录;任务还没结束的不删。删除以后这个站点的这个种子在以后的轮次里会再试一次; 尝试行不动(今天的名额、统计都不变)。判断与删除在同一条语句里,不会删掉刚建了任务的记录。

func (*Service) Due

func (s *Service) Due(ctx context.Context) bool

Due 报告这一刻该不该定时运行:开启了、有 token、距上次运行满了间隔。

func (*Service) FinishRun

func (s *Service) FinishRun(ctx context.Context, id uint, res RunResult, status, errText string, paused time.Duration) error

FinishRun 补上这一轮的结果、计数与步骤。

func (*Service) GetRun

func (s *Service) GetRun(ctx context.Context, id uint) (RunDetail, error)

GetRun 是一轮的详情。

func (*Service) IYUUCallsToday

func (s *Service) IYUUCallsToday(ctx context.Context) ([]models.ReseedIYUUDaily, error)

IYUUCallsToday 是今天各接口的请求计数(按接口名排)。

func (*Service) IYUUReady

func (s *Service) IYUUReady(ctx context.Context) error

IYUUReady 报告现在能不能请求 IYUU:冷却中返回 *CoolingError,今天到了上限返回 ErrIYUUDailyCap。 「立即运行」「继续」开始以前、定时轮次到点时用它判断,免得开始一轮马上又停下。

func (*Service) MarkInterrupted

func (s *Service) MarkInterrupted(ctx context.Context, before time.Time) (int64, int64, error)

MarkInterrupted 把 before 以前开始、还写着进行中或暂停的轮次,以及还写着 running 的尝试,记成被打断 (启动时调用:上一个进程在一轮中途退出了)。建成任务的尝试与任务在同一个事务里写,留下 running 的一定没建成任务。

func (*Service) NotifyTarget

func (s *Service) NotifyTarget(ctx context.Context) (mode string, channels []uint, err error)

NotifyTarget 是每轮结果推送的设置:mode 是生效的推送方式(off 时不推送),channels 是接收的通道。

func (*Service) PruneRuns

func (s *Service) PruneRuns(ctx context.Context) error

PruneRuns 清理旧的轮次(只留最近 ReseedRunKeep 条、不超过 ReseedRunKeepFor)与过了 ReseedAttemptKeepFor 的尝试。 时间按时刻比较(julianday),不按文本。

func (*Service) RecordRun

func (s *Service) RecordRun(ctx context.Context, at time.Time, summary string) error

RecordRun 记下这一轮的时间和结果。

func (*Service) Records

func (s *Service) Records(ctx context.Context, f RecordFilter, page, size int) (RecordPage, error)

Records 按最后一次尝试的时间从新到旧列出辅种记录(重试过的按最后一次尝试的时间排)。

func (*Service) Retry

func (s *Service) Retry(ctx context.Context, opts RunOptions, ids []uint) (RunResult, error)

Retry 是重试轮次:重试选中的记录。不查 IYUU,用记录里的站点、站内 ID 与 info hash;在记录的下载器里找原种子, 目标里已经有这个种子或者站点今天的名额用完时跳过,其余走与普通轮次同一个尝试(写尝试行、占名额、更新记录)。 不看站点开关与「已经尝试过」:重试是在记录里点名要试的。

func (*Service) Run

func (s *Service) Run(ctx context.Context, opts RunOptions) (RunResult, error)

Run 运行一轮辅种。返回的错误是这一轮根本没法开始(没有 token、没有站点等);单个下载器或站点的问题记在结果里。

func (*Service) RunAttempts

func (s *Service) RunAttempts(ctx context.Context, id uint, page, size int) ([]AttemptView, int64, error)

RunAttempts 列出一轮里的尝试(按尝试的先后),带上对应任务现在的状态。

func (*Service) RunJobsWaiting

func (s *Service) RunJobsWaiting(ctx context.Context, id uint) ([]uint, error)

RunJobsWaiting 是 id 这一轮建的、还在等待加入下载器的任务(停止时可以一起取消)。

func (*Service) Runs

func (s *Service) Runs(ctx context.Context, page, size int) ([]RunView, int64, error)

Runs 按开始时间从新到旧列出轮次(不带步骤)。

func (*Service) SaveSettings

func (s *Service) SaveSettings(ctx context.Context, u SettingsUpdate) (Settings, error)

SaveSettings 校验并保存设置(token 以外的项全量保存)。开启时必须有 token;换 token 时作废缓存的站点列表与 sid_sha1。 只写配置列:运行中的一轮会写上次运行结果和 sid_sha1 缓存,整行写回会把它们改回旧值。

func (*Service) SetAllSitesSelected

func (s *Service) SetAllSitesSelected(ctx context.Context, selected bool) (SiteSelection, error)

SetAllSitesSelected 全部打开(以后新配置的站点也自动参与)或全部关掉。

func (*Service) SetRunPaused

func (s *Service) SetRunPaused(ctx context.Context, id uint, paused bool, since time.Time, total time.Duration) error

SetRunPaused 记下这一轮暂停(从 since 开始)或继续(total 是一共暂停过多久)。

func (*Service) SetSiteSelected

func (s *Service) SetSiteSelected(ctx context.Context, site string, selected bool) (SiteSelection, error)

SetSiteSelected 打开或关掉一个站点。从「全部站点」关掉一个时,名单换成现在已配置的站点去掉它(以后新配置的站点默认不参与); 打开的站点必须已经在 pt-tools 里配置。只写站点范围的两列,与保存设置互斥。

func (*Service) Settings

func (s *Service) Settings(ctx context.Context) (Settings, error)

Settings 返回当前设置(0 的间隔与上限换成默认值)。

func (*Service) SiteMap

func (s *Service) SiteMap(ctx context.Context) ([]SiteMapItem, error)

SiteMap 列出 IYUU 支持的站点和它们在 pt-tools 里对应的站点(按站点地址的主机名与可注册域识别)。

func (*Service) StartRun

func (s *Service) StartRun(ctx context.Context, trigger, after string, from *uint) (models.ReseedRun, error)

StartRun 写一条进行中的轮次记录。

func (*Service) Stats

func (s *Service) Stats(ctx context.Context, q StatsQuery) (Stats, error)

Stats 算一个范围的辅种统计。

type Settings

type Settings struct {
	Enabled       bool     `json:"enabled"`
	HasToken      bool     `json:"has_token"`
	IntervalHours int      `json:"interval_hours"`
	DownloaderIDs []uint   `json:"downloader_ids"`
	SiteNames     []string `json:"site_names"`
	// SiteMode 是站点范围:all(全部已配置、IYUU 也支持的站点)或 selected(只算 SiteNames)
	SiteMode         string     `json:"site_mode"`
	MaxPerSitePerDay int        `json:"max_per_site_per_day"`
	LastRunAt        *time.Time `json:"last_run_at,omitempty"`
	LastResult       string     `json:"last_result"`
	// NextRunAt 是下一轮大约什么时候(开着、有 token 时才有;到点以后在下一次检查时跑)
	NextRunAt *time.Time `json:"next_run_at,omitempty"`
	// IYUUMinIntervalSeconds 是两次请求 IYUU 之间至少隔几秒(没设置时是默认的 3);IYUUMaxCallsPerDay 是每天最多请求几次,0 是不限
	IYUUMinIntervalSeconds int `json:"iyuu_min_interval_seconds"`
	IYUUMaxCallsPerDay     int `json:"iyuu_max_calls_per_day"`
	// IYUUCooldownUntil 是限流冷却到什么时候(冷却中才有);IYUULastLimit 是最近一次限流的情况
	IYUUCooldownUntil *time.Time `json:"iyuu_cooldown_until,omitempty"`
	IYUULastLimit     *IYUULimit `json:"iyuu_last_limit,omitempty"`
	// IYUUToday 是今天各接口的请求计数
	IYUUToday []models.ReseedIYUUDaily `json:"iyuu_today"`
	// NotifyMode 是每轮结果推送(off、always、changes),NotifyChannelIDs 是接收的通知通道;DailyReport 是每日战报里带不带辅种
	NotifyMode       string `json:"notify_mode"`
	NotifyChannelIDs []uint `json:"notify_channel_ids"`
	DailyReport      bool   `json:"daily_report"`
}

Settings 是接口里的辅种设置:token 只说有没有设置,不返回内容。

type SettingsUpdate

type SettingsUpdate struct {
	Enabled          bool      `json:"enabled"`
	Token            *string   `json:"token,omitempty"`
	IntervalHours    int       `json:"interval_hours"`
	DownloaderIDs    []uint    `json:"downloader_ids"`
	SiteNames        *[]string `json:"site_names,omitempty"`
	MaxPerSitePerDay int       `json:"max_per_site_per_day"`
	// IYUUMinIntervalSeconds 为 nil 时保留原来的(没设置过就是默认的 3 秒);0 是不隔
	IYUUMinIntervalSeconds *int `json:"iyuu_min_interval_seconds,omitempty"`
	IYUUMaxCallsPerDay     int  `json:"iyuu_max_calls_per_day"`
	// NotifyMode、NotifyChannelIDs、DailyReport 为 nil 时保留原来的(旧页面保存时不会把推送关掉)
	NotifyMode       *string `json:"notify_mode,omitempty"`
	NotifyChannelIDs *[]uint `json:"notify_channel_ids,omitempty"`
	DailyReport      *bool   `json:"daily_report,omitempty"`
}

SettingsUpdate 是保存设置的请求。Token 为 nil 时保留原来的;为空串时清除。 SiteNames 为 nil 时保留原来的站点范围(网页在「站点」页用开关改,见 SetSiteSelected);给了就按名单保存,空名单是全部站点。

type SiteMapItem

type SiteMapItem struct {
	SID        int    `json:"sid"`
	IYUUSite   string `json:"iyuu_site"`
	Nickname   string `json:"nickname"`
	Host       string `json:"host"`
	SiteName   string `json:"site_name,omitempty"`
	Configured bool   `json:"configured"`
	Selected   bool   `json:"selected"`
}

SiteMapItem 是 IYUU 的一个站点,以及它在 pt-tools 里对应哪个站点。

type SiteSelection

type SiteSelection struct {
	Mode      string   `json:"site_mode"`
	SiteNames []string `json:"site_names"`
}

SiteSelection 是站点范围:Mode 为 all 时全部已配置、IYUU 也支持的站点都参与(以后新配置的也算),为 selected 时只算 SiteNames。

type Stats

type Stats struct {
	Granularity string       `json:"granularity"`
	Custom      bool         `json:"custom"`
	From        string       `json:"from"`
	To          string       `json:"to"`
	Series      []StatsPoint `json:"series"`
	Totals      StatsCounts  `json:"totals"`
	Sites       []StatsSite  `json:"sites"`
	IYUU        []StatsIYUU  `json:"iyuu"`
	// LastIYUUAt 是最近一次请求 IYUU 的时间(不限范围)
	LastIYUUAt *time.Time `json:"last_iyuu_at,omitempty"`
	// FirstDay 是最早有数据的那天(尝试、跳过或 IYUU 请求);没有数据时为空
	FirstDay string `json:"first_day,omitempty"`
}

Stats 是一个范围的辅种统计。

type StatsCounts

type StatsCounts struct {
	// Created 是建成的辅种任务,Failed 是下载或核对没通过,Gone 是站点上已经删了,
	// Active 是种子已经下载、核对过,但这个种子已有进行中的任务(算跳过)。按开始尝试的那一天。
	Created int `json:"created"`
	Failed  int `json:"failed"`
	Gone    int `json:"gone"`
	Active  int `json:"active"`
	// Succeeded 是校验通过、开始做种,RolledBack 是校验没到 100% 撤回了,JobFailed 是任务失败,Canceled 是任务被取消。
	// 按任务完成的那一天。
	Succeeded  int `json:"succeeded"`
	RolledBack int `json:"rolled_back"`
	JobFailed  int `json:"job_failed"`
	Canceled   int `json:"canceled"`
	// 下载以前就跳过的:下载器里已经有、已经尝试过、今天这个站点已经加满、站点不在辅种范围。每一轮都算一次。
	SkipPresent     int `json:"skip_present"`
	SkipTried       int `json:"skip_tried"`
	SkipDailyLimit  int `json:"skip_daily_limit"`
	SkipNotSelected int `json:"skip_not_selected"`
	// IYUU 请求(站点的合计里没有)
	IYUUCalls       int `json:"iyuu_calls"`
	IYUURateLimited int `json:"iyuu_rate_limited"`
	IYUUFailed      int `json:"iyuu_failed"`
	IYUUHashes      int `json:"iyuu_hashes"`
}

StatsCounts 是一段时间里的各项计数。

type StatsIYUU

type StatsIYUU struct {
	Endpoint    string `json:"endpoint"`
	Calls       int    `json:"calls"`
	OK          int    `json:"ok"`
	RateLimited int    `json:"rate_limited"`
	Failed      int    `json:"failed"`
	Hashes      int    `json:"hashes"`
}

StatsIYUU 是范围内一个 IYUU 接口的请求合计。

type StatsPoint

type StatsPoint struct {
	Date string `json:"date"`
	End  string `json:"end"`
	StatsCounts
}

StatsPoint 是一段:Date 是第一天,End 是最后一天(自定义范围时裁到范围以内)。

type StatsQuery

type StatsQuery struct {
	Granularity string
	Periods     int
	From, To    string
}

StatsQuery 是统计的范围:Granularity(day、week、month、quarter、year,默认 day)加最近 Periods 段 (0 是默认段数,最后一段是当前这一段、只算到今天),或者自定义 From、To(YYYY-MM-DD,含两头)。

type StatsSite

type StatsSite struct {
	SiteName string `json:"site_name"`
	StatsCounts
}

StatsSite 是一个站点在范围内的合计(SiteName 为空串的是不在辅种范围的 IYUU 站点)。

type Timer

type Timer interface {
	C() <-chan time.Time
	Stop() bool
}

Timer 是 Control 用的计时器(测试里换成可控的)。

type TokenCipher

type TokenCipher interface {
	Encrypt(plain string) (string, error)
	Decrypt(cipherText string) (string, error)
}

TokenCipher 加解密 IYUU token(生产环境是 ConfigStore 的 EncryptCookie / DecryptCookie)。

Jump to

Keyboard shortcuts

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