Documentation
¶
Overview ¶
Package reseed 实现 IYUU 辅种:把下载器里已经下完的种子的 info hash 交给 IYUU 查询,找出其他站点上数据相同的种子, 从站点下载种子文件、核对 info hash 与文件列表后,暂停加入同一台下载器(保存路径用原种子的),校验到 100% 才开始做种。 加入、校验与回滚复用转移做种的任务(transfer 包,任务种类 reseed)。默认关闭;token 加密保存。
Index ¶
- Constants
- Variables
- func SameFiles(a, b []FileEntry) (bool, string)
- type Config
- type FileEntry
- type RecordView
- type RunResult
- type Service
- func (s *Service) ClearFinishedJobs(ctx context.Context) (int64, error)
- func (s *Service) Due(ctx context.Context) bool
- func (s *Service) RecordRun(ctx context.Context, at time.Time, summary string) error
- func (s *Service) Records(ctx context.Context) ([]RecordView, error)
- func (s *Service) Run(ctx context.Context) (RunResult, error)
- func (s *Service) SaveSettings(ctx context.Context, u SettingsUpdate) (Settings, error)
- func (s *Service) Settings(ctx context.Context) (Settings, error)
- func (s *Service) SiteMap(ctx context.Context) ([]SiteMapItem, error)
- type Settings
- type SettingsUpdate
- type SiteMapItem
- type TokenCipher
Constants ¶
const ( SkipNotSelected = "站点不在辅种范围" SkipExists = "下载器里已经有" SkipTried = "已经尝试过" SkipDailyLimit = "今天这个站点已经加满" SkipActive = "已有进行中的任务" )
跳过的原因。
Variables ¶
var ( // ErrInvalid 表示设置有问题。 ErrInvalid = errors.New("辅种设置无效") // ErrNoSites 表示没有可以辅种的站点。 ErrNoSites = errors.New("没有可以辅种的站点:IYUU 支持的站点里,pt-tools 还没有配置或没有选中") )
Functions ¶
Types ¶
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 FileEntry ¶
FileEntry 是种子里的一个文件:相对保存路径的路径(用 / 分隔)与大小。
func DownloaderFiles ¶
func DownloaderFiles(files []downloader.TorrentFile) []FileEntry
DownloaderFiles 把下载器的文件列表换成 FileEntry(分隔符统一成 /)。
func TorrentFiles ¶
TorrentFiles 列出 .torrent 文件里的文件:单文件种子是 name;多文件种子是 name/path...(与下载器的文件列表同一写法)。
type RecordView ¶
type RecordView struct {
models.ReseedRecord
JobState string `json:"job_state,omitempty"`
JobMessage string `json:"job_message,omitempty"`
JobMissing bool `json:"job_missing,omitempty"`
}
RecordView 是记录列表里的一项:记录加上任务的状态。JobMissing 表示记录指向的任务已经不在了(结果不知道)。
type RunResult ¶
type RunResult struct {
Downloaders int `json:"downloaders"`
Hashes int `json:"hashes"`
Candidates int `json:"candidates"`
Created int `json:"created"`
Failed int `json:"failed"`
Skipped map[string]int `json:"skipped,omitempty"`
Errors []string `json:"errors,omitempty"`
// Stopped 说明这一轮为什么提前停下(限流等)。
Stopped string `json:"stopped,omitempty"`
}
RunResult 是一轮辅种的结果。
type Service ¶
type Service struct {
// contains filtered or unexported fields
}
Service 管理辅种设置并运行辅种。
func (*Service) ClearFinishedJobs ¶
ClearFinishedJobs 删除已经结束的辅种任务,返回删除的条数。删除前把任务的结果写进引用它的辅种记录, 记录不再指向任务;不改记录的更新时间(重试间隔和每天的上限按它算)。
func (*Service) Records ¶
func (s *Service) Records(ctx context.Context) ([]RecordView, error)
Records 返回最近尝试的辅种记录(重试过的按最后一次尝试的时间排)。
func (*Service) SaveSettings ¶
SaveSettings 校验并保存设置(token 以外的项全量保存)。开启时必须有 token;换 token 时作废缓存的站点列表与 sid_sha1。 只写配置列:运行中的一轮会写上次运行结果和 sid_sha1 缓存,整行写回会把它们改回旧值。
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"`
MaxPerSitePerDay int `json:"max_per_site_per_day"`
LastRunAt *time.Time `json:"last_run_at,omitempty"`
LastResult string `json:"last_result"`
}
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"`
MaxPerSitePerDay int `json:"max_per_site_per_day"`
}
SettingsUpdate 是保存设置的请求。Token 为 nil 时保留原来的;为空串时清除。
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 里对应哪个站点。