Documentation
¶
Index ¶
- Constants
- Variables
- func ApplyPresetIfMissing(siteName string) (banThresholdDays, remindBeforeDays int, hasPreset bool)
- func BrushTaskTag(taskID uint) string
- func CanonicalFreeLevel(raw string) string
- func FreeLevelQueryValues(raw string) []string
- func GetLatestMigrationCompletedAt(db *gorm.DB) (time.Time, bool)
- func IsExampleURL(url string) bool
- func JobOwnerTag(kind string) string
- func JobTag(kind string, id uint) string
- func MapTransferPath(maps []DownloaderPathMap, src string) (string, bool)
- func MarkBroadcastSent(db *gorm.DB, schemaVersion int) error
- func MigrateExampleRSS(db *gorm.DB) error
- func SyncSitesFromRegistry(db *gorm.DB, registeredSites []RegisteredSite) error
- func TransferStateFinal(state string) bool
- func UpsertMigrationState(db *gorm.DB, schemaVersion int, completedAt time.Time) error
- type APIResponse
- type ActionAudit
- type AdminUser
- type BotToken
- type BrushDailyStat
- type BrushRepository
- func (r *BrushRepository) ActiveTorrents(taskID uint) ([]BrushTorrent, error)
- func (r *BrushRepository) CountActive(taskID uint) (int64, error)
- func (r *BrushRepository) DailyStats(taskID uint, fromDay, toDay string) ([]BrushDailyStat, error)
- func (r *BrushRepository) DeleteTask(id uint) error
- func (r *BrushRepository) GetTask(id uint) (*BrushTask, error)
- func (r *BrushRepository) ListTasks() ([]BrushTask, error)
- func (r *BrushRepository) ListTorrents(taskID uint, state string, page, pageSize int) ([]BrushTorrent, int64, error)
- func (r *BrushRepository) MarkEnded(bt *BrushTorrent, state, reason string, at time.Time, day string) error
- func (r *BrushRepository) MarkRun(id uint, at time.Time, result, lastErr string) error
- func (r *BrushRepository) PruneSamples(before time.Time) (int64, error)
- func (r *BrushRepository) RecordAdded(bt *BrushTorrent, day string) error
- func (r *BrushRepository) RecordSample(bt *BrushTorrent, sample BrushTorrentSample, progress, ratio float64, ...) error
- func (r *BrushRepository) SamplesSince(brushTorrentID uint, since time.Time) ([]BrushTorrentSample, error)
- func (r *BrushRepository) SaveTask(task *BrushTask) error
- func (r *BrushRepository) SeenSiteTorrentIDs(siteName string) (map[string]bool, error)
- func (r *BrushRepository) TaskTotals() (map[uint]BrushDailyStat, error)
- type BrushTask
- type BrushTorrent
- type BrushTorrentSample
- type ChannelBinding
- type CloakSettings
- type Config
- type CookieCloudSetting
- type DiscountType
- type DownloaderDirectory
- type DownloaderPathMap
- type DownloaderSetting
- type FaviconCache
- type FilterMode
- type FilterRule
- type FilterRuleDB
- func (f *FilterRuleDB) Create(rule *FilterRule) error
- func (f *FilterRuleDB) Delete(id uint) error
- func (f *FilterRuleDB) Exists(name string) (bool, error)
- func (f *FilterRuleDB) ExistsExcluding(name string, excludeID uint) (bool, error)
- func (f *FilterRuleDB) GetAll() ([]FilterRule, error)
- func (f *FilterRuleDB) GetByID(id uint) (*FilterRule, error)
- func (f *FilterRuleDB) GetByRSSID(rssID uint) ([]FilterRule, error)
- func (f *FilterRuleDB) GetBySiteID(siteID uint) ([]FilterRule, error)
- func (f *FilterRuleDB) GetEnabled() ([]FilterRule, error)
- func (f *FilterRuleDB) Update(rule *FilterRule) error
- type FreeDownChecker
- type MTTorrentDetail
- func (t MTTorrentDetail) CanbeFinished(logger *zap.SugaredLogger, enabled bool, speedLimit, sizeLimitGB int) bool
- func (t MTTorrentDetail) GetFreeEndTime() *time.Time
- func (t MTTorrentDetail) GetFreeLevel() string
- func (t MTTorrentDetail) GetName() string
- func (t MTTorrentDetail) GetSizeBytes() int64
- func (t MTTorrentDetail) GetSubTitle() string
- func (t MTTorrentDetail) IsFree() bool
- type MatchField
- type Migration
- type MigrationFunc
- type MigrationState
- type MonitorNotificationLog
- type NotificationConf
- type NotificationOutbox
- type PHPTorrentInfo
- func (p PHPTorrentInfo) CanbeFinished(logger *zap.SugaredLogger, enabled bool, speedLimit, sizeLimitGB int) bool
- func (p PHPTorrentInfo) GetFreeEndTime() *time.Time
- func (p PHPTorrentInfo) GetFreeLevel() string
- func (p PHPTorrentInfo) GetName() string
- func (p PHPTorrentInfo) GetSizeBytes() int64
- func (p PHPTorrentInfo) GetSubTitle() string
- func (p PHPTorrentInfo) IsFree() bool
- type PatternType
- type PromotionRule
- type QbitSettings
- type RSSConfig
- func (r *RSSConfig) GetEffectiveConcurrency(globalSettings *SettingsGlobal) int32
- func (r *RSSConfig) GetEffectiveDownloadPath() string
- func (r *RSSConfig) GetEffectiveFilterMode(globalSettings *SettingsGlobal) FilterMode
- func (r *RSSConfig) GetEffectiveIntervalMinutes(globalSettings *SettingsGlobal) int32
- func (r *RSSConfig) HasCustomDownloadPath() bool
- func (r *RSSConfig) ShouldSkip() bool
- type RSSFilterAssociation
- type RSSFilterAssociationDB
- func (r *RSSFilterAssociationDB) Create(assoc *RSSFilterAssociation) error
- func (r *RSSFilterAssociationDB) DeleteByFilterRuleID(filterRuleID uint) error
- func (r *RSSFilterAssociationDB) DeleteByRSSID(rssID uint) error
- func (r *RSSFilterAssociationDB) Exists(rssID, filterRuleID uint) (bool, error)
- func (r *RSSFilterAssociationDB) GetByFilterRuleID(filterRuleID uint) ([]uint, error)
- func (r *RSSFilterAssociationDB) GetByRSSID(rssID uint) ([]uint, error)
- func (r *RSSFilterAssociationDB) GetFilterRuleIDsForRSS(rssID uint) ([]uint, error)
- func (r *RSSFilterAssociationDB) GetFilterRulesForRSS(rssID uint) ([]FilterRule, error)
- func (r *RSSFilterAssociationDB) HasAssociations(rssID uint) (bool, error)
- func (r *RSSFilterAssociationDB) SetFilterRulesForRSS(rssID uint, filterRuleIDs []uint) error
- type RSSNotificationLog
- type RSSSubscription
- type RegisteredSite
- type ResType
- type ReseedRecord
- type ReseedSetting
- type SchemaManager
- type SchemaVersion
- type SettingsGlobal
- type Showcase
- type SiteAttendanceLog
- type SiteAttendanceRepository
- func (r *SiteAttendanceRepository) EnsureDay(row SiteAttendanceLog) error
- func (r *SiteAttendanceRepository) GetDay(siteName, day string) (*SiteAttendanceLog, error)
- func (r *SiteAttendanceRepository) ListDay(day string) ([]SiteAttendanceLog, error)
- func (r *SiteAttendanceRepository) UpdateDay(siteName, day string, columns map[string]any) error
- type SiteConfig
- type SiteData
- type SiteGroup
- type SiteLoginPreset
- type SiteLoginState
- type SiteLoginStateRepository
- func (r *SiteLoginStateRepository) ClampLastVisit(siteName string, ts, now time.Time) error
- func (r *SiteLoginStateRepository) EnsureLoginStateRow(defaults SiteLoginState) error
- func (r *SiteLoginStateRepository) GetLoginState(siteName string) (*SiteLoginState, error)
- func (r *SiteLoginStateRepository) IncrProbeFailures(siteName string) error
- func (r *SiteLoginStateRepository) ListLoginStates(enabledOnly bool) ([]SiteLoginState, error)
- func (r *SiteLoginStateRepository) ResetProbeFailures(siteName string) error
- func (r *SiteLoginStateRepository) UpdateColumns(siteName string, columns map[string]any) error
- func (r *SiteLoginStateRepository) UpdateProbeResult(siteName, status string, lastLogin, lastAccess *time.Time, probeErr error) error
- func (r *SiteLoginStateRepository) UpsertLoginState(siteName string, fields map[string]any) error
- type SiteRateLimit
- type SiteRepository
- func (r *SiteRepository) BatchUpdateSiteDownloader(siteIDs []uint, downloaderID uint) (int64, error)
- func (r *SiteRepository) CreateSite(data SiteData) (uint, error)
- func (r *SiteRepository) DeleteSite(name string) error
- func (r *SiteRepository) GetSiteByID(id uint) (*SiteSetting, error)
- func (r *SiteRepository) GetSiteByName(name string) (*SiteSetting, error)
- func (r *SiteRepository) ListEnabledSites() ([]SiteSetting, error)
- func (r *SiteRepository) ListSites() ([]SiteSetting, error)
- func (r *SiteRepository) SiteExistsByName(name string) (bool, error)
- func (r *SiteRepository) UpdateSiteCredentials(name string, enabled *bool, authMethod, cookie, apiKey, apiURL, passkey string) error
- func (r *SiteRepository) UpdateSiteDownloader(name string, downloaderID *uint) error
- func (r *SiteRepository) UpdateSiteDownloaderByID(siteID uint, downloaderID *uint) error
- type SiteSetting
- type SiteTemplate
- type SiteTemplateExport
- type Statistics
- type Status
- type TorrentDB
- func (t *TorrentDB) DeleteTorrent(torrentHash string) error
- func (t *TorrentDB) GetAllTorrents() ([]TorrentInfo, error)
- func (t *TorrentDB) GetTorrentBySiteAndHash(siteName, torrentHash string) (*TorrentInfo, error)
- func (t *TorrentDB) GetTorrentBySiteAndID(siteName, torrentID string) (*TorrentInfo, error)
- func (t *TorrentDB) UpdateTorrentStatus(torrentHash string, isDownloaded, isPushed bool, pushTime *time.Time) error
- func (t *TorrentDB) UpsertTorrent(torrent *TorrentInfo) error
- func (t *TorrentDB) WithTransaction(fn func(tx *gorm.DB) error) error
- func (t *TorrentDB) WithTransactionContext(ctx context.Context, fn func(tx *gorm.DB) error) error
- type TorrentInfo
- type TorrentInfoArchive
- type TorrentMetadata
- type TorrentTransferJob
- type TransferRule
Constants ¶
const ( BrushTorrentActive = "active" BrushTorrentRemoved = "removed" // BrushTorrentGone 表示种子已经不在下载器里了(被人手动删掉,或被低空间紧急清理删掉),不是刷流删的。 BrushTorrentGone = "gone" )
刷流种子的状态。active 之外都是终态。
const ( MinIntervalMinutes int32 = 5 // 最小间隔时间(分钟) DefaultIntervalMinutes int32 = 10 // 默认间隔时间(分钟) MaxIntervalMinutes int32 = 1440 // 最大间隔时间(分钟) )
间隔时间常量
const ( MinConcurrency int32 = 1 // 最小并发数 DefaultConcurrency int32 = 3 // 默认并发数 MaxConcurrency int32 = 10 // 最大并发数 )
并发数常量
const ( DefaultPeerRatioMaxSL = 30.0 MinPeerRatioMaxSL = 1.0 DefaultPeerRatioIntervalMin = 10 MinPeerRatioIntervalMin = 5 )
const ( CookieCloudDefaultIntervalHours = 24 CookieCloudMinIntervalHours = 1 CookieCloudMaxIntervalHours = 168 )
CookieCloud 同步的取值范围。
const ( DBFile = "torrents.db" WorkDir = ".pt-tools" )
const ( MonitorNotifyPending = "pending" MonitorNotifySent = "sent" MonitorNotifyFailed = "failed" )
const ( JobKindTransfer = "" JobKindReseed = "reseed" )
转移任务的种类:转移做种(从源移除)与辅种(源与目标是同一台下载器,不移除任何种子)。
const ( ReseedDefaultIntervalHours = 12 ReseedMinIntervalHours = 1 ReseedMaxIntervalHours = 168 ReseedDefaultMaxPerSitePerDay = 20 ReseedMaxPerSitePerDay = 500 // ReseedSidTTL 是 sid_sha1 的有效期。 ReseedSidTTL = 7 * 24 * time.Hour // ReseedRetryAfter 是暂时失败(下载不到种子等)之后多久再试。 ReseedRetryAfter = 7 * 24 * time.Hour )
辅种设置的默认值与范围。
const ( // ReseedQueued 是已经建成辅种任务,结果看任务的状态。 ReseedQueued = "queued" // ReseedFailed 是下载种子、核对 info hash 或文件列表失败;同一对不再尝试。 ReseedFailed = "failed" // 下面几个是清除已结束的辅种任务时,写进记录里的任务结果(任务失败的记为 ReseedFailed)。 ReseedDone = "done" ReseedRolledBack = "rolled_back" ReseedCanceled = "canceled" )
辅种记录的结果。
const ( AttendancePending = "pending" AttendanceSigned = "signed" AttendanceAlready = "already" AttendanceFailed = "failed" AttendanceUnsupported = "unsupported" )
每日签到的状态。pending 之外都是当天的最终结果,不再请求站点。
const ( DefaultBanThresholdDays = 30 DefaultRemindBeforeDays = 10 )
const ( // TransferPending 是刚建好、还没拿到种子文件的任务。 TransferPending = "pending" // TransferExported 是种子文件已经拿到,等着加入目标下载器。 TransferExported = "exported" // TransferAdding 是正在把种子暂停加入目标:先记下这个状态再推送,进程在推送途中退出时, // 重启后按目标里有没有这个种子决定继续还是重推。 TransferAdding = "adding" // TransferChecking 是已经暂停加入目标、正在校验数据。 TransferChecking = "checking" // TransferVerified 是目标校验到了 100%,接下来恢复目标、从源移除。 TransferVerified = "verified" // TransferDone 是目标已经开始做种、源里的种子已移除(数据保留)。 TransferDone = "source_removed" // TransferRolledBack 是校验没到 100% 或超时:目标里的种子已移除(数据保留),源不动。 TransferRolledBack = "rolled_back" // TransferFailed 是加入目标之前就失败了(拿不到种子文件、目标已有这个种子、闸门拒绝等),源不动。 TransferFailed = "failed" // TransferCanceled 是用户在加入目标之前取消的任务。 TransferCanceled = "canceled" )
转移做种任务的状态。TransferStateFinal 为真的是终态。
const ( TransferRuleDefaultMaxPerRun = 10 TransferRuleDefaultIntervalMin = 60 TransferRuleMinIntervalMin = 10 TransferRuleMaxPerRun = 100 )
定时规则的默认值与范围。
const BrushTagAll = "pt-tools-brush"
BrushTagAll 是所有刷流种子都带的标签;全局自动清理按它把刷流种子排除在常规规则之外。
const CurrentSchemaVersion = 11
当前数据库架构版本 每次添加新的迁移时递增此值
const DefaultFilterMode = FilterModeAutoFree
DefaultFilterMode is the fallback when neither RSS nor Global specifies one.
const ReseedTag = "pt-tools-reseed"
ReseedTag 是辅种加进下载器时带上的标签:恢复、回滚、收尾前确认目标里的种子带着它,证明是辅种加的。
const TransferTag = "pt-tools-transfer"
TransferTag 是转移做种加入目标时带上的标签:恢复、回滚、收尾前都要确认目标里的种子带着它, 证明是这次转移加的,不去动用户自己加的同一个种子。
Variables ¶
var ErrBrushTaskNotFound = errors.New("刷流任务不存在")
ErrBrushTaskNotFound 表示任务不存在。
var ErrBrushTorrentTaken = errors.New("这个种子已经由别的刷流任务加入")
ErrBrushTorrentTaken 表示这个站点种子已经由别的刷流任务加入过(site_name + torrent_id 唯一)。
var ExampleRSSPatterns = []string{
"springxxx.xxx",
"hdsky.xxx",
"rss.m-team.xxx",
"example.com",
"xxx.xxx",
}
ExampleRSSPatterns 示例 RSS URL 的特征模式 包含这些模式的 URL 被认为是示例配置
var FreeLevelAliases = map[string][]string{
"FREE": {"FREE"},
"2XFREE": {"2XFREE", "_2X_FREE", "2X FREE"},
"PERCENT_50": {"PERCENT_50", "50%"},
"PERCENT_30": {"PERCENT_30", "30%"},
"PERCENT_70": {"PERCENT_70", "70%"},
"2XUP": {"2XUP", "_2X_UP", "2X"},
"2X50": {"2X50", "_2X_PERCENT_50", "2X50%"},
"NONE": {"NONE", "NORMAL", ""},
}
FreeLevelAliases 把一个规范优惠档映射到库里可能出现过的全部拼法(大写形式)。
var SiteLoginPresets = map[string]SiteLoginPreset{ "mteam": { BanThresholdDays: DefaultBanThresholdDays, RemindBeforeDays: DefaultRemindBeforeDays, Notes: "M-Team default inactivity reminder policy; fallback 30/10 until site-specific source is confirmed.", }, }
var TransferActiveStates = []string{TransferPending, TransferExported, TransferAdding, TransferChecking, TransferVerified}
TransferActiveStates 是未结束的状态(同一个种子同一时间只能有一个这样的任务)。
Functions ¶
func ApplyPresetIfMissing ¶ added in v0.35.0
func BrushTaskTag ¶
BrushTaskTag 是某个刷流任务专属的标签,删种只处理带这个标签、且有 BrushTorrent 记录的种子。
func CanonicalFreeLevel ¶ added in v0.48.0
CanonicalFreeLevel 把任意一种拼法收敛到规范档名。 认不出来的原样返回(大写去空白),调用方据此仍能做等值匹配而不是静默放行。
func FreeLevelQueryValues ¶ added in v0.48.0
FreeLevelQueryValues 返回筛某一档时应当匹配的全部存库拼法(大写)。 未知档位返回它自己,查询照样成立,只是命中为空。
func GetLatestMigrationCompletedAt ¶ added in v0.35.0
GetLatestMigrationCompletedAt returns the newest recorded migration completion timestamp; ok=false if table or rows are absent.
func IsExampleURL ¶ added in v0.2.0
IsExampleURL 检查 URL 是否为示例 URL
func MapTransferPath ¶
func MapTransferPath(maps []DownloaderPathMap, src string) (string, bool)
MapTransferPath 把源下载器里的路径换算成目标下载器里的路径:取最长的匹配前缀(按路径分段匹配, /data 不匹配 /database);没有匹配时原样返回,第二个返回值为 false。 Windows 路径(盘符或 \\ 开头)不区分大小写,/ 与 \ 都认;Unix 路径区分大小写。 前缀两边一个是 Windows 路径、一个是 Unix 路径时,余下部分的分隔符换成目标的写法。
func MarkBroadcastSent ¶ added in v0.35.0
MarkBroadcastSent flips BroadcastSent=true for the given schema version.
func MigrateExampleRSS ¶ added in v0.2.0
MigrateExampleRSS 迁移旧版本的示例 RSS 配置 将 URL 包含示例模式的 RSS 订阅标记为 IsExample=true
func SyncSitesFromRegistry ¶ added in v0.2.0
func SyncSitesFromRegistry(db *gorm.DB, registeredSites []RegisteredSite) error
SyncSitesFromRegistry 从注册表同步站点到数据库 每次应用启动时调用,确保数据库中包含所有注册的站点 保留用户配置(cookie/api_key/enabled),不删除任何用户数据
Types ¶
type APIResponse ¶
type ActionAudit ¶ added in v0.31.0
type ActionAudit struct {
ID uint `gorm:"primaryKey" json:"id"`
NotificationConfID uint `gorm:"not null;index:idx_action_audit_conf_user_time,priority:1" json:"notification_conf_id"`
ChannelType string `gorm:"size:32;not null" json:"channel_type"`
ChannelUserID string `gorm:"size:128;not null;index:idx_action_audit_conf_user_time,priority:2" json:"channel_user_id"`
Command string `gorm:"size:64;not null;index:idx_action_audit_command" json:"command"`
ArgsJSON string `gorm:"type:text" json:"args_json"`
Result string `gorm:"size:32;not null" json:"result"`
LatencyMs int64 `gorm:"default:0" json:"latency_ms"`
CreatedAt time.Time `gorm:"index:idx_action_audit_conf_user_time,priority:3,sort:desc" json:"created_at"`
}
ActionAudit 命令执行审计日志,Result 取值如 "ok" / "denied" / "error"。 复合索引 (notification_conf_id, channel_user_id, created_at) 用于按用户分页倒序查询。
func (ActionAudit) TableName ¶ added in v0.31.0
func (ActionAudit) TableName() string
type AdminUser ¶ added in v0.1.0
type AdminUser struct {
ID uint `gorm:"primaryKey"`
Username string `gorm:"uniqueIndex;size:64"`
PasswordHash string `gorm:"size:255"`
CreatedAt time.Time
UpdatedAt time.Time
}
Admin 用户(单用户登录)
type BotToken ¶ added in v0.31.0
type BotToken struct {
ID uint `gorm:"primaryKey" json:"id"`
Kind string `gorm:"size:16;not null;index:idx_bot_token_kind" json:"kind"`
CodeOrTokenHash string `gorm:"size:255;not null;index:idx_bot_token_hash" json:"-"`
Scope string `gorm:"size:255;default:''" json:"scope"`
ExpiresAt *time.Time `gorm:"index:idx_bot_token_expires" json:"expires_at"`
UsedAt *time.Time `json:"used_at"`
CreatedBy string `gorm:"size:64" json:"created_by"`
CreatedAt time.Time `json:"created_at"`
}
BotToken 鉴权用 token / 8-char bind code 的持久化记录。 Kind 取值如 "bind_code" / "bearer";CodeOrTokenHash 为 bcrypt hash。
type BrushDailyStat ¶
type BrushDailyStat struct {
ID uint `gorm:"primaryKey" json:"id"`
TaskID uint `gorm:"not null;uniqueIndex:idx_brush_stat_task_day,priority:1" json:"task_id"`
Day string `gorm:"size:10;not null;uniqueIndex:idx_brush_stat_task_day,priority:2;index" json:"day"`
Uploaded int64 `gorm:"not null;default:0" json:"uploaded"`
Downloaded int64 `gorm:"not null;default:0" json:"downloaded"`
Added int `gorm:"not null;default:0" json:"added"`
AddedBytes int64 `gorm:"not null;default:0" json:"added_bytes"`
Removed int `gorm:"not null;default:0" json:"removed"`
LastUpdated time.Time
}
BrushDailyStat 是刷流任务每天的收益:(task_id, day) 唯一;上传、下载是当天采样差值的累加。
type BrushRepository ¶
type BrushRepository struct {
// contains filtered or unexported fields
}
BrushRepository 封装刷流相关表的读写。
func NewBrushRepository ¶
func NewBrushRepository(db *gorm.DB) *BrushRepository
func (*BrushRepository) ActiveTorrents ¶
func (r *BrushRepository) ActiveTorrents(taskID uint) ([]BrushTorrent, error)
ActiveTorrents 返回任务名下仍在做的种子。
func (*BrushRepository) CountActive ¶
func (r *BrushRepository) CountActive(taskID uint) (int64, error)
CountActive 返回任务名下仍在做的种子数。
func (*BrushRepository) DailyStats ¶
func (r *BrushRepository) DailyStats(taskID uint, fromDay, toDay string) ([]BrushDailyStat, error)
DailyStats 返回 [fromDay, toDay] 的每日统计;taskID 为 0 时返回全部任务。
func (*BrushRepository) DeleteTask ¶
func (r *BrushRepository) DeleteTask(id uint) error
DeleteTask 删除任务和它的统计、采样与种子记录。下载器里的种子不动。
func (*BrushRepository) ListTasks ¶
func (r *BrushRepository) ListTasks() ([]BrushTask, error)
func (*BrushRepository) ListTorrents ¶
func (r *BrushRepository) ListTorrents(taskID uint, state string, page, pageSize int) ([]BrushTorrent, int64, error)
ListTorrents 分页列出任务的种子;state 为空时列全部,新的在前。
func (*BrushRepository) MarkEnded ¶
func (r *BrushRepository) MarkEnded(bt *BrushTorrent, state, reason string, at time.Time, day string) error
MarkEnded 把种子记为终态(removed 或 gone);removed 时计入当天的删除数。
func (*BrushRepository) PruneSamples ¶
func (r *BrushRepository) PruneSamples(before time.Time) (int64, error)
PruneSamples 删掉 before 之前的采样;返回删掉的行数。
func (*BrushRepository) RecordAdded ¶
func (r *BrushRepository) RecordAdded(bt *BrushTorrent, day string) error
RecordAdded 记下一个推送成功的种子,并把当天的加入数与体积记进统计。同一任务同一 hash 已有记录时不重复记; 这个站点种子已经归别的任务时返回 ErrBrushTorrentTaken(调用方应撤回刚加的这一份)。
func (*BrushRepository) RecordSample ¶
func (r *BrushRepository) RecordSample(bt *BrushTorrent, sample BrushTorrentSample, progress, ratio float64, seedingSec int64, loc *time.Location) error
RecordSample 写一次采样,更新种子的最近状态,并把与上次采样的差值(只计正数)累加到每日统计里。 差值按时间比例分摊到它跨过的每一天(loc 是分天的时区):23:55 与次日 00:05 之间的量不会全记到次日。 第一次采样从加入时刻算起:推送前下载器里没有这个种子,累计值本身就是这段时间的量。
func (*BrushRepository) SamplesSince ¶
func (r *BrushRepository) SamplesSince(brushTorrentID uint, since time.Time) ([]BrushTorrentSample, error)
SamplesSince 返回种子在 since 及之后的采样(按时间升序),外加 since 之前最近的一条(作为窗口起点)。
func (*BrushRepository) SaveTask ¶
func (r *BrushRepository) SaveTask(task *BrushTask) error
SaveTask 新建(ID 为 0)或整行更新一个任务的配置;运行状态列(last_*)由 MarkRun 单独写,这里不覆盖。
func (*BrushRepository) SeenSiteTorrentIDs ¶
func (r *BrushRepository) SeenSiteTorrentIDs(siteName string) (map[string]bool, error)
SeenSiteTorrentIDs 返回所有刷流任务在这个站点推送过的种子 ID(不论哪个任务、现在什么状态): 同一个站点种子不会被两个任务各加一份(两份会争用同一条 TorrentInfo 记录)。
func (*BrushRepository) TaskTotals ¶
func (r *BrushRepository) TaskTotals() (map[uint]BrushDailyStat, error)
TaskTotals 返回每个任务累计的上传与下载(全部日期)。
type BrushTask ¶
type BrushTask struct {
ID uint `gorm:"primaryKey" json:"id"`
Name string `gorm:"size:64;not null;uniqueIndex" json:"name"`
Enabled bool `gorm:"not null;default:false" json:"enabled"`
SiteName string `gorm:"size:64;not null;index" json:"site_name"`
DownloaderID uint `gorm:"not null" json:"downloader_id"`
SavePath string `gorm:"size:512;default:''" json:"save_path"`
Category string `gorm:"size:128;default:''" json:"category"`
// Tags 是用户额外加的标签(逗号分隔);站点名、pt-tools-brush 和任务标签总会带上。
Tags string `gorm:"size:256;default:''" json:"tags"`
IntervalMin int `gorm:"not null;default:0" json:"interval_min"`
// 入场条件
// Discounts 是允许的优惠类型(逗号分隔的 DiscountLevel,如 FREE,2XFREE);为空时只收免费(FREE、2XFREE)。
Discounts string `gorm:"size:128;default:''" json:"discounts"`
MinFreeRemainMin int `gorm:"not null;default:0" json:"min_free_remain_min"`
MinSizeGB float64 `gorm:"not null;default:0" json:"min_size_gb"`
MaxSizeGB float64 `gorm:"not null;default:0" json:"max_size_gb"`
MaxSeeders int `gorm:"not null;default:0" json:"max_seeders"`
MinLeechers int `gorm:"not null;default:0" json:"min_leechers"`
MaxPublishAgeMin int `gorm:"not null;default:0" json:"max_publish_age_min"`
ExcludeHR bool `gorm:"not null;default:false" json:"exclude_hr"`
// IncludeKeywords / ExcludeKeywords 按行或逗号分隔,大小写不敏感地匹配标题与副标题。
IncludeKeywords string `gorm:"size:1024;default:''" json:"include_keywords"`
ExcludeKeywords string `gorm:"size:1024;default:''" json:"exclude_keywords"`
// 限额
MaxDownloading int `gorm:"not null;default:0" json:"max_downloading"`
MaxTotalSizeGB float64 `gorm:"not null;default:0" json:"max_total_size_gb"`
MaxDailyDownloadGB float64 `gorm:"not null;default:0" json:"max_daily_download_gb"`
// 删种规则(任一条满足即删)
RemoveSeedTimeH float64 `gorm:"not null;default:0" json:"remove_seed_time_h"`
RemoveRatio float64 `gorm:"not null;default:0" json:"remove_ratio"`
// RemoveLowSpeedKBs 与 RemoveLowSpeedWindowMin 一起用:已完成的种子最近 N 分钟的平均上传速度低于阈值时删。
RemoveLowSpeedKBs float64 `gorm:"not null;default:0" json:"remove_low_speed_kbs"`
RemoveLowSpeedWindowMin int `gorm:"not null;default:0" json:"remove_low_speed_window_min"`
RemoveInactiveH float64 `gorm:"not null;default:0" json:"remove_inactive_h"`
RemoveFreeExpiredIncomplete bool `gorm:"not null;default:false" json:"remove_free_expired_incomplete"`
RemoveWithData bool `gorm:"not null;default:false" json:"remove_with_data"`
LastRunAt *time.Time `json:"last_run_at,omitempty"`
LastError string `gorm:"size:1024;default:''" json:"last_error"`
LastResult string `gorm:"size:512;default:''" json:"last_result"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
}
BrushTask 是一个刷流任务:从一个站点的免费列表里按入场条件挑种子推给一个下载器,再按删种规则删掉。 默认关闭。时长、体积的 0 一律表示「不限」。 列的默认值一律是零值:GORM 新建时会把零值换成 default,非零的默认值会让关掉的开关(如删种不删文件)存成打开; 新任务的默认取值在前端表单里。
type BrushTorrent ¶
type BrushTorrent struct {
ID uint `gorm:"primaryKey" json:"id"`
TaskID uint `gorm:"not null;uniqueIndex:idx_brush_task_hash,priority:1;index" json:"task_id"`
InfoHash string `gorm:"size:64;not null;uniqueIndex:idx_brush_task_hash,priority:2" json:"info_hash"`
// (site_name, torrent_id) 唯一:同一个站点种子只由一个刷流任务加入一次(删掉之后也不再加回来)
SiteName string `gorm:"size:64;not null;uniqueIndex:idx_brush_site_torrent,priority:1" json:"site_name"`
TorrentID string `gorm:"size:128;not null;uniqueIndex:idx_brush_site_torrent,priority:2" json:"torrent_id"`
Title string `gorm:"size:512;default:''" json:"title"`
SizeBytes int64 `gorm:"not null;default:0" json:"size_bytes"`
// Discount 是推送时的优惠类型(DiscountLevel)。
Discount string `gorm:"size:16;default:''" json:"discount"`
FreeEndAt *time.Time `json:"free_end_at,omitempty"`
HasHR bool `gorm:"not null;default:false" json:"has_hr"`
HRSeedTimeH int `gorm:"not null;default:0" json:"hr_seed_time_h"`
DownloaderID uint `gorm:"not null" json:"downloader_id"`
State string `gorm:"size:16;not null;default:'active';index" json:"state"`
AddedAt time.Time `gorm:"not null" json:"added_at"`
RemovedAt *time.Time `json:"removed_at,omitempty"`
RemoveReason string `gorm:"size:256;default:''" json:"remove_reason"`
// 最近一次采样时下载器报告的累计值,用于算每天的增量。
Uploaded int64 `gorm:"not null;default:0" json:"uploaded"`
Downloaded int64 `gorm:"not null;default:0" json:"downloaded"`
Progress float64 `gorm:"not null;default:0" json:"progress"`
Ratio float64 `gorm:"not null;default:0" json:"ratio"`
SeedingTimeSec int64 `gorm:"not null;default:0" json:"seeding_time_sec"`
LastActivityAt *time.Time `json:"last_activity_at,omitempty"`
LastSampleAt *time.Time `json:"last_sample_at,omitempty"`
}
BrushTorrent 是刷流任务推送过的一个种子;(task_id, info_hash) 唯一。
type BrushTorrentSample ¶
type BrushTorrentSample struct {
ID uint `gorm:"primaryKey" json:"id"`
BrushTorrentID uint `gorm:"not null;index:idx_brush_sample_torrent_at,priority:1" json:"brush_torrent_id"`
At time.Time `gorm:"not null;index:idx_brush_sample_torrent_at,priority:2;index" json:"at"`
Uploaded int64 `gorm:"not null" json:"uploaded"`
Downloaded int64 `gorm:"not null" json:"downloaded"`
}
BrushTorrentSample 是一次采样:种子在下载器里的累计上传、下载量。只为算「最近 N 分钟的平均上传速度」保留, 超过最长窗口的旧行定期删掉。
type ChannelBinding ¶ added in v0.31.0
type ChannelBinding struct {
ID uint `gorm:"primaryKey" json:"id"`
NotificationConfID uint `gorm:"not null;index:idx_channel_binding_conf_user,priority:1" json:"notification_conf_id"`
ChannelType string `gorm:"size:32;not null;index:idx_channel_binding_type" json:"channel_type"`
ChannelUserID string `gorm:"size:128;not null;index:idx_channel_binding_conf_user,priority:2" json:"channel_user_id"`
PtAdmin bool `gorm:"default:false" json:"pt_admin"`
Allowed bool `gorm:"default:false" json:"allowed"`
Label string `gorm:"size:128" json:"label"`
ReplyLang string `gorm:"size:16;default:''" json:"reply_lang"`
CreatedAt time.Time `json:"created_at"`
LastActiveAt *time.Time `json:"last_active_at"`
}
ChannelBinding 渠道用户与 NotificationConf 的绑定关系。 PtAdmin 标记该用户是否为管理员;Allowed 表示是否在白名单内。
func (ChannelBinding) TableName ¶ added in v0.31.0
func (ChannelBinding) TableName() string
type CloakSettings ¶ added in v0.35.0
type CloakSettings struct {
ID uint `gorm:"primaryKey" json:"id"`
Endpoint string `gorm:"size:512" json:"endpoint"`
TokenEncrypted string `gorm:"size:1024" json:"-"` // 永远不出现在 JSON
// ProfileID 是登录探测后备使用的 CloakBrowser profile;与 Endpoint、Token 三项齐全才启用后备。
ProfileID string `gorm:"size:128" json:"profile_id"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
}
CloakSettings 持久化 CloakBrowser-Manager 接入信息(v2)。 单行表(约定 ID=1)。Token 仅以 AES-GCM 密文形式落库, 字段名 `TokenEncrypted` 与 SiteSetting.CookieEncrypted 保持一致。
type Config ¶ added in v0.1.0
type Config struct {
Global SettingsGlobal `json:"global"`
Qbit QbitSettings `json:"qbit"`
Sites map[SiteGroup]SiteConfig `json:"sites"`
}
type CookieCloudSetting ¶
type CookieCloudSetting struct {
ID uint `gorm:"primaryKey" json:"id"`
// ServerURL 是 CookieCloud 服务地址,UUID 是浏览器扩展里的用户 KEY。
ServerURL string `gorm:"size:512;default:''" json:"server_url"`
UUID string `gorm:"size:128;default:''" json:"uuid"`
// PasswordEncrypted 是加密后的端对端加密密码;接口只返回是否已设置。密码只在本机解密用,不发给 CookieCloud 服务。
PasswordEncrypted string `gorm:"type:text;default:''" json:"-"`
// AutoSync 打开后按间隔把有变化的 Cookie 写进已启用的站点。
AutoSync bool `gorm:"not null;default:false" json:"auto_sync"`
// IntervalHours 是定时同步的间隔(0 时按 CookieCloudDefaultIntervalHours)。
IntervalHours int `gorm:"not null;default:0" json:"interval_hours"`
LastSyncAt *time.Time `json:"last_sync_at,omitempty"`
// LastResult 是上一次同步的一句话结果(不含 Cookie 内容)。
LastResult string `gorm:"type:text;default:''" json:"last_result"`
UpdatedAt time.Time `json:"updated_at"`
}
CookieCloudSetting 是从自建 CookieCloud 服务导入站点 Cookie 的设置(只有一行,ID 为 1)。默认不定时同步;列的默认值一律是零值。
type DiscountType ¶
type DiscountType string
DiscountType 定义优惠类型
const ( DISCOUNT_NONE DiscountType = "none" DISCOUNT_FREE DiscountType = "free" DISCOUNT_TWO_X DiscountType = "2x" DISCOUNT_TWO_X_FREE DiscountType = "2xfree" DISCOUNT_THIRTY DiscountType = "30%" DISCOUNT_FIFTY DiscountType = "50%" DISCOUNT_TWO_X_FIFTY DiscountType = "2x50%" DISCOUNT_CUSTOM DiscountType = "custom" )
type DownloaderDirectory ¶ added in v0.2.0
type DownloaderDirectory struct {
ID uint `gorm:"primaryKey" json:"id"`
DownloaderID uint `gorm:"index;not null" json:"downloader_id"` // 关联的下载器ID
Path string `gorm:"size:512;not null" json:"path"` // 目录路径
Alias string `gorm:"size:128" json:"alias"` // 目录别名(用于显示)
IsDefault bool `json:"is_default"` // 是否为默认目录
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
}
DownloaderDirectory 下载器目录配置 用于设置下载器的多个下载目录及其别名
func (DownloaderDirectory) TableName ¶ added in v0.2.0
func (DownloaderDirectory) TableName() string
TableName 指定表名
type DownloaderPathMap ¶
type DownloaderPathMap struct {
ID uint `gorm:"primaryKey" json:"id"`
SourceDownloaderID uint `gorm:"not null;uniqueIndex:idx_downloader_path_map" json:"source_downloader_id"`
TargetDownloaderID uint `gorm:"not null;uniqueIndex:idx_downloader_path_map" json:"target_downloader_id"`
SourcePrefix string `gorm:"size:512;not null;uniqueIndex:idx_downloader_path_map" json:"source_prefix"`
TargetPrefix string `gorm:"size:512;not null" json:"target_prefix"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
}
DownloaderPathMap 是两个下载器之间的路径对应:源下载器看到的 SourcePrefix,在目标下载器里是 TargetPrefix。 换算时取最长的匹配前缀;没有匹配时路径不变。
type DownloaderSetting ¶ added in v0.2.0
type DownloaderSetting struct {
ID uint `gorm:"primaryKey" json:"id"`
Name string `gorm:"uniqueIndex;size:64;not null" json:"name"`
Type string `gorm:"size:32;not null" json:"type"` // qbittorrent, transmission
URL string `gorm:"size:512;not null" json:"url"`
Username string `gorm:"size:128" json:"username"`
Password string `gorm:"size:256" json:"password"`
IsDefault bool `json:"is_default"`
Enabled bool `json:"enabled"`
AutoStart bool `json:"auto_start"` // 推送种子后自动开始下载
ExtraConfig string `gorm:"type:text" json:"extra_config,omitempty"` // JSON格式的额外配置
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
}
DownloaderSetting 下载器设置
func (DownloaderSetting) TableName ¶ added in v0.2.0
func (DownloaderSetting) TableName() string
TableName 指定表名
type FaviconCache ¶ added in v0.2.0
type FaviconCache struct {
ID uint `gorm:"primaryKey" json:"id"`
SiteID string `gorm:"uniqueIndex;size:64;not null" json:"site_id"` // 站点标识,如 "hdsky", "mteam"
SiteName string `gorm:"size:128" json:"site_name"` // 站点名称
FaviconURL string `gorm:"size:512" json:"favicon_url"` // 原始 favicon URL
Data []byte `gorm:"type:blob" json:"-"` // 图标二进制数据
ContentType string `gorm:"size:64" json:"content_type"` // MIME 类型
ETag string `gorm:"size:128" json:"etag"` // 用于缓存验证
LastFetched time.Time `json:"last_fetched"` // 最后获取时间
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
}
FaviconCache 站点图标缓存(存储在数据库中)
type FilterMode ¶ added in v0.25.0
type FilterMode string
FilterMode controls which download channels are active for an RSS feed.
const ( // FilterModeAutoFree enables both the free auto-download channel and // the filter-rule channel. This preserves pre-v0.25 behavior and is the default. FilterModeAutoFree FilterMode = "auto_free" // FilterModeFilterOnly disables the free auto-download channel; only torrents // matching an associated filter rule are downloaded. FilterModeFilterOnly FilterMode = "filter_only" // FilterModeFreeOnly disables the filter-rule channel; only free torrents // that can be finished in time are downloaded (ignores associated rules). FilterModeFreeOnly FilterMode = "free_only" )
func NormalizeFilterMode ¶ added in v0.25.0
func NormalizeFilterMode(m FilterMode) FilterMode
NormalizeFilterMode returns a validated FilterMode, falling back to DefaultFilterMode when the input is empty or unrecognized.
type FilterRule ¶ added in v0.2.0
type FilterRule struct {
ID uint `gorm:"primaryKey" json:"id"`
Name string `gorm:"size:128;not null" json:"name"`
Pattern string `gorm:"size:512;not null" json:"pattern"`
PatternType PatternType `gorm:"size:16;not null;default:'keyword'" json:"pattern_type"`
MatchField MatchField `gorm:"size:16;not null;default:'both'" json:"match_field"`
RequireFree bool `gorm:"default:true" json:"require_free"`
MinSizeGB int `gorm:"default:0" json:"min_size_gb"`
MaxSizeGB int `gorm:"default:0" json:"max_size_gb"`
Enabled bool `gorm:"default:true" json:"enabled"`
SiteID *uint `gorm:"index" json:"site_id"`
RSSID *uint `gorm:"index" json:"rss_id"`
Priority int `gorm:"default:100" json:"priority"`
// Purpose 区分规则用途:
// "download" — 仅用于下载(默认,向后兼容空值)
// "notify" — 仅用于通知(filtered 模式)
// "both" — 下载与通知都使用
Purpose string `gorm:"column:purpose;not null;default:'download'" json:"purpose"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
}
FilterRule represents a user-defined filter rule for RSS items.
func (*FilterRule) MatchesSize ¶ added in v0.25.0
func (r *FilterRule) MatchesSize(sizeGB float64) bool
MatchesSize reports whether the torrent size (in GB) satisfies this rule's optional MinSizeGB / MaxSizeGB bounds. Zero on either side means "no bound". The rule's bounds can only narrow the global TorrentSizeGB; never widen it.
func (FilterRule) TableName ¶ added in v0.2.0
func (FilterRule) TableName() string
TableName returns the table name for FilterRule.
type FilterRuleDB ¶ added in v0.2.0
type FilterRuleDB struct {
// contains filtered or unexported fields
}
FilterRuleDB provides database operations for FilterRule.
func NewFilterRuleDB ¶ added in v0.2.0
func NewFilterRuleDB(db *TorrentDB) *FilterRuleDB
NewFilterRuleDB creates a new FilterRuleDB.
func (*FilterRuleDB) Create ¶ added in v0.2.0
func (f *FilterRuleDB) Create(rule *FilterRule) error
Create creates a new filter rule.
func (*FilterRuleDB) Delete ¶ added in v0.2.0
func (f *FilterRuleDB) Delete(id uint) error
Delete deletes a filter rule by ID.
func (*FilterRuleDB) Exists ¶ added in v0.2.0
func (f *FilterRuleDB) Exists(name string) (bool, error)
Exists checks if a filter rule with the given name exists.
func (*FilterRuleDB) ExistsExcluding ¶ added in v0.2.0
func (f *FilterRuleDB) ExistsExcluding(name string, excludeID uint) (bool, error)
ExistsExcluding checks if a filter rule with the given name exists, excluding a specific ID.
func (*FilterRuleDB) GetAll ¶ added in v0.2.0
func (f *FilterRuleDB) GetAll() ([]FilterRule, error)
GetAll retrieves all filter rules.
func (*FilterRuleDB) GetByID ¶ added in v0.2.0
func (f *FilterRuleDB) GetByID(id uint) (*FilterRule, error)
GetByID retrieves a filter rule by ID.
func (*FilterRuleDB) GetByRSSID ¶ added in v0.2.0
func (f *FilterRuleDB) GetByRSSID(rssID uint) ([]FilterRule, error)
GetByRSSID retrieves filter rules for a specific RSS subscription.
func (*FilterRuleDB) GetBySiteID ¶ added in v0.2.0
func (f *FilterRuleDB) GetBySiteID(siteID uint) ([]FilterRule, error)
GetBySiteID retrieves filter rules for a specific site.
func (*FilterRuleDB) GetEnabled ¶ added in v0.2.0
func (f *FilterRuleDB) GetEnabled() ([]FilterRule, error)
GetEnabled retrieves all enabled filter rules ordered by priority.
func (*FilterRuleDB) Update ¶ added in v0.2.0
func (f *FilterRuleDB) Update(rule *FilterRule) error
Update updates an existing filter rule.
type FreeDownChecker ¶
type MTTorrentDetail ¶
type MTTorrentDetail struct {
ID string `json:"id"`
CreatedDate string `json:"createdDate"`
LastModifiedDate string `json:"lastModifiedDate"`
Name string `json:"name"`
SmallDescr string `json:"smallDescr"`
IMDb string `json:"imdb"`
IMDbRating *string `json:"imdbRating"`
Douban string `json:"douban"`
DoubanRating *string `json:"doubanRating"`
DmmCode string `json:"dmmCode"`
Author any `json:"author"`
Category string `json:"category"`
Source string `json:"source"`
Medium any `json:"medium"`
Standard string `json:"standard"`
VideoCodec string `json:"videoCodec"`
AudioCodec string `json:"audioCodec"`
Team string `json:"team"`
Processing any `json:"processing"`
Countries []string `json:"countries"`
NumFiles string `json:"numfiles"`
Size string `json:"size"`
Tags string `json:"tags"`
Labels string `json:"labels"`
MsUp string `json:"msUp"`
Anonymous bool `json:"anonymous"`
InfoHash any `json:"infoHash"`
Status *Status `json:"status"`
EditedBy any `json:"editedBy"`
EditDate any `json:"editDate"`
Collection bool `json:"collection"`
InRss bool `json:"inRss"`
CanVote bool `json:"canVote"`
ImageList any `json:"imageList"`
ResetBox any `json:"resetBox"`
OriginFileName string `json:"originFileName"`
Descr string `json:"descr"`
Nfo any `json:"nfo"`
MediaInfo string `json:"mediainfo"`
CIDs any `json:"cids"`
AIDs any `json:"aids"`
ShowcaseList []Showcase `json:"showcaseList"`
TagList []any `json:"tagList"`
Scope string `json:"scope"`
ScopeTeams []any `json:"scopeTeams"`
Thanked bool `json:"thanked"`
Rewarded bool `json:"rewarded"`
}
func (MTTorrentDetail) CanbeFinished ¶
func (t MTTorrentDetail) CanbeFinished(logger *zap.SugaredLogger, enabled bool, speedLimit, sizeLimitGB int) bool
func (MTTorrentDetail) GetFreeEndTime ¶
func (t MTTorrentDetail) GetFreeEndTime() *time.Time
func (MTTorrentDetail) GetFreeLevel ¶ added in v0.0.6
func (t MTTorrentDetail) GetFreeLevel() string
func (MTTorrentDetail) GetName ¶ added in v0.2.0
func (t MTTorrentDetail) GetName() string
GetName 获取种子名称(返回中文名 Name)
func (MTTorrentDetail) GetSizeBytes ¶ added in v0.25.0
func (t MTTorrentDetail) GetSizeBytes() int64
GetSizeBytes 获取种子大小(字节);解析失败时返回 0。
func (MTTorrentDetail) GetSubTitle ¶ added in v0.2.0
func (t MTTorrentDetail) GetSubTitle() string
GetSubTitle 获取副标题(返回 SmallDescr)
func (MTTorrentDetail) IsFree ¶
func (t MTTorrentDetail) IsFree() bool
type MatchField ¶ added in v0.2.0
type MatchField string
MatchField represents which fields to match against.
const ( // MatchFieldTitle matches only against the title field. MatchFieldTitle MatchField = "title" // MatchFieldTag matches only against the tag field. MatchFieldTag MatchField = "tag" // MatchFieldBoth matches against both title and tag fields (default). MatchFieldBoth MatchField = "both" )
type Migration ¶ added in v0.2.0
type Migration struct {
Version int
Description string
Up MigrationFunc
}
Migration 迁移定义
type MigrationFunc ¶ added in v0.2.0
MigrationFunc 迁移函数类型
type MigrationState ¶ added in v0.35.0
type MigrationState struct {
ID uint `gorm:"primaryKey" json:"id"`
SchemaVersion int `gorm:"uniqueIndex;not null" json:"schema_version"`
CompletedAt time.Time `gorm:"not null;index" json:"completed_at"`
BroadcastSent bool `gorm:"not null;default:false" json:"broadcast_sent"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
}
MigrationState records post-migration runtime metadata. One row per schema version.
func GetMigrationState ¶ added in v0.35.0
func GetMigrationState(db *gorm.DB, schemaVersion int) (*MigrationState, bool)
GetMigrationState returns the row for schemaVersion, or (nil, false) if missing.
type MonitorNotificationLog ¶
type MonitorNotificationLog struct {
ID uint `gorm:"primaryKey;autoIncrement" json:"id"`
Source string `gorm:"size:32;not null;uniqueIndex:idx_monitor_notify_dedup,priority:1" json:"source"`
Subject string `gorm:"size:64;not null;uniqueIndex:idx_monitor_notify_dedup,priority:2" json:"subject"`
Kind string `gorm:"size:32;not null;uniqueIndex:idx_monitor_notify_dedup,priority:3" json:"kind"`
EventKey string `gorm:"size:128;not null;uniqueIndex:idx_monitor_notify_dedup,priority:4" json:"event_key"`
NotificationConfID uint `gorm:"not null;uniqueIndex:idx_monitor_notify_dedup,priority:5" json:"notification_conf_id"`
BypassQuiet bool `gorm:"not null;default:false" json:"bypass_quiet"`
Result string `gorm:"size:16;not null;default:'pending';index:idx_monitor_notify_pending,priority:1" json:"result"`
Attempts int `gorm:"not null;default:0" json:"attempts"`
NextRetryAt time.Time `gorm:"index:idx_monitor_notify_pending,priority:2" json:"next_retry_at"`
LastError string `gorm:"size:1024;default:''" json:"last_error,omitempty"`
PayloadJSON string `gorm:"type:text" json:"payload_json,omitempty"`
DeliveredAt *time.Time `json:"delivered_at,omitempty"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
}
MonitorNotificationLog 记录后台监控(登录提醒、战报等)的每条通知在每个通道上的投递。
决定发送时按目标通道各写一行,(source, subject, kind, event_key, notification_conf_id) 唯一, 同一决策重做不会重复发送。投递器按 next_retry_at 取到期的 pending 行,经 live 通道同步发送, 是这些通知唯一的重试者;通道处于静默时段时把 next_retry_at 顺延到静默结束。 时间一律以 UTC 写入,next_retry_at 的字符串比较才有序。
type NotificationConf ¶ added in v0.31.0
type NotificationConf struct {
ID uint `gorm:"primaryKey" json:"id"`
ChannelType string `gorm:"size:32;not null;index:idx_notification_conf_type" json:"channel_type"`
Name string `gorm:"size:128;not null" json:"name"`
ConfigJSON string `gorm:"type:text" json:"-"`
Enabled bool `gorm:"default:true;index:idx_notification_conf_enabled" json:"enabled"`
// QuietHoursStart / QuietHoursEnd 控制静默时段,格式 "HH:MM";空字符串表示无静默。
// 若 start > end(如 "22:00"–"08:00")表示窗口跨越午夜。
QuietHoursStart string `gorm:"column:quiet_hours_start;default:''" json:"quiet_hours_start"`
QuietHoursEnd string `gorm:"column:quiet_hours_end;default:''" json:"quiet_hours_end"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
}
NotificationConf 通知通道配置(Telegram / QQ / Webhook / WeCom 等)。 ConfigJSON 由 internal/crypto AES-GCM 加密后存入,本层仅原样存取字符串。
func (NotificationConf) TableName ¶ added in v0.31.0
func (NotificationConf) TableName() string
TableName 强制单数表名,避免 GORM 默认复数化与项目命名风格不一致。
type NotificationOutbox ¶ added in v0.31.0
type NotificationOutbox struct {
ID uint `gorm:"primaryKey" json:"id"`
NotificationConfID uint `gorm:"not null;index:idx_notification_outbox_conf" json:"notification_conf_id"`
PayloadJSON string `gorm:"type:text;not null" json:"payload_json"`
Status string `gorm:"size:16;not null;default:'pending';index:idx_notification_outbox_status_retry,priority:1" json:"status"`
RetryCount int `gorm:"default:0" json:"retry_count"`
NextRetryAt time.Time `gorm:"index:idx_notification_outbox_status_retry,priority:2" json:"next_retry_at"`
CreatedAt time.Time `json:"created_at"`
SentAt *time.Time `json:"sent_at"`
ErrorMsg string `gorm:"size:1024;default:''" json:"error_msg"`
}
NotificationOutbox 离线投递队列。Status 取值:pending / sent / failed / dead。 复合索引 (status, next_retry_at) 用于 worker 高效扫描待发送记录。
func (NotificationOutbox) TableName ¶ added in v0.31.0
func (NotificationOutbox) TableName() string
type PHPTorrentInfo ¶
type PHPTorrentInfo struct {
Title string // 种子标题
SubTitle string // 副标题/标签
TorrentID string // 种子 ID
Discount DiscountType // 优惠类型
EndTime time.Time // 优惠结束时间
SizeMB float64 // 种子大小,单位为 MB
Seeders int // 做种人数
Leechers int // 下载人数
Completed float64 // 最大完成百分比
HR bool // 是否为 HR(Hit & Run)
}
PHPTorrentInfo 定义种子信息结构
func (PHPTorrentInfo) CanbeFinished ¶
func (p PHPTorrentInfo) CanbeFinished(logger *zap.SugaredLogger, enabled bool, speedLimit, sizeLimitGB int) bool
func (PHPTorrentInfo) GetFreeEndTime ¶
func (p PHPTorrentInfo) GetFreeEndTime() *time.Time
func (PHPTorrentInfo) GetFreeLevel ¶ added in v0.0.6
func (p PHPTorrentInfo) GetFreeLevel() string
func (PHPTorrentInfo) GetName ¶ added in v0.2.0
func (p PHPTorrentInfo) GetName() string
GetName 获取种子名称
func (PHPTorrentInfo) GetSizeBytes ¶ added in v0.25.0
func (p PHPTorrentInfo) GetSizeBytes() int64
GetSizeBytes 获取种子大小(字节),由 SizeMB 换算得到。
func (PHPTorrentInfo) GetSubTitle ¶ added in v0.2.0
func (p PHPTorrentInfo) GetSubTitle() string
GetSubTitle 获取副标题
func (PHPTorrentInfo) IsFree ¶
func (p PHPTorrentInfo) IsFree() bool
type PatternType ¶ added in v0.2.0
type PatternType string
PatternType represents the type of pattern matching to use.
const ( // PatternKeyword matches if the title contains the keyword (case-insensitive). PatternKeyword PatternType = "keyword" // PatternWildcard uses * and ? wildcards for matching. PatternWildcard PatternType = "wildcard" // PatternRegex uses regular expressions for matching. PatternRegex PatternType = "regex" )
type PromotionRule ¶
type QbitSettings ¶ added in v0.1.0
type QbitSettings struct {
ID uint `gorm:"primaryKey" json:"id"`
Enabled bool `json:"enabled"`
URL string `gorm:"not null" json:"url"`
User string `gorm:"not null" json:"user"`
Password string `gorm:"not null" json:"password"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
}
qBittorrent 设置
type RSSConfig ¶ added in v0.1.0
type RSSConfig struct {
ID uint `json:"id"`
Name string `json:"name"`
URL string `json:"url"`
Category string `json:"category"`
Tag string `json:"tag"`
IntervalMinutes int32 `json:"interval_minutes"` // RSS 执行间隔(分钟),0 表示使用全局设置
Concurrency int32 `json:"concurrency"` // 并发数,0 表示使用全局设置
DownloadSubPath string `json:"download_sub_path"`
DownloadPath string `json:"download_path"` // 下载器中下载任务的目标下载路径(可选)
DownloaderID *uint `json:"downloader_id"` // 指定下载器,nil 表示使用默认下载器
FilterRuleIDs []uint `json:"filter_rule_ids"` // 关联的过滤规则 ID 列表
IsExample bool `json:"is_example"` // 是否为示例配置,示例配置不会被执行
PauseOnFreeEnd bool `json:"pause_on_free_end"`
FilterMode FilterMode `json:"filter_mode"` // 空字符串表示使用全局 DefaultFilterMode
NotifyMode string `json:"notify_mode"`
NotifyConfIDs string `json:"notify_conf_ids"`
MaxNotificationsPerHour int `json:"max_notifications_per_hour"`
}
Runtime-friendly structures for API usage and scheduler/config load
func (*RSSConfig) GetEffectiveConcurrency ¶ added in v0.2.0
func (r *RSSConfig) GetEffectiveConcurrency(globalSettings *SettingsGlobal) int32
GetEffectiveConcurrency 获取有效的并发数 优先级:RSS 配置 > 全局配置 > 默认值
func (*RSSConfig) GetEffectiveDownloadPath ¶ added in v0.2.0
GetEffectiveDownloadPath 获取有效的下载路径 如果 RSS 配置了 DownloadPath 则使用,否则返回空字符串(使用下载器默认路径)
func (*RSSConfig) GetEffectiveFilterMode ¶ added in v0.25.0
func (r *RSSConfig) GetEffectiveFilterMode(globalSettings *SettingsGlobal) FilterMode
GetEffectiveFilterMode resolves the filter mode using the RSS > Global > Default priority. RSS-level value takes precedence; empty falls through to the global default; unknown values also fall back to DefaultFilterMode via NormalizeFilterMode.
func (*RSSConfig) GetEffectiveIntervalMinutes ¶ added in v0.2.0
func (r *RSSConfig) GetEffectiveIntervalMinutes(globalSettings *SettingsGlobal) int32
GetEffectiveIntervalMinutes 获取有效的间隔时间 优先级:RSS 配置 > 全局配置 > 默认值
func (*RSSConfig) HasCustomDownloadPath ¶ added in v0.2.0
HasCustomDownloadPath 检查是否配置了自定义下载路径
func (*RSSConfig) ShouldSkip ¶ added in v0.2.0
ShouldSkip 判断是否应该跳过此 RSS 配置 示例配置或 URL 为空的配置应该被跳过
type RSSFilterAssociation ¶ added in v0.2.0
type RSSFilterAssociation struct {
ID uint `gorm:"primaryKey" json:"id"`
RSSID uint `gorm:"uniqueIndex:idx_rss_filter;not null" json:"rss_id"`
FilterRuleID uint `gorm:"uniqueIndex:idx_rss_filter;not null" json:"filter_rule_id"`
CreatedAt time.Time `json:"created_at"`
}
RSSFilterAssociation represents a many-to-many relationship between RSS subscriptions and filter rules.
func (RSSFilterAssociation) TableName ¶ added in v0.2.0
func (RSSFilterAssociation) TableName() string
TableName returns the table name for RSSFilterAssociation.
type RSSFilterAssociationDB ¶ added in v0.2.0
type RSSFilterAssociationDB struct {
// contains filtered or unexported fields
}
RSSFilterAssociationDB provides database operations for RSSFilterAssociation.
func NewRSSFilterAssociationDB ¶ added in v0.2.0
func NewRSSFilterAssociationDB(db *gorm.DB) *RSSFilterAssociationDB
NewRSSFilterAssociationDB creates a new RSSFilterAssociationDB.
func (*RSSFilterAssociationDB) Create ¶ added in v0.2.0
func (r *RSSFilterAssociationDB) Create(assoc *RSSFilterAssociation) error
Create creates a new RSS-filter association.
func (*RSSFilterAssociationDB) DeleteByFilterRuleID ¶ added in v0.2.0
func (r *RSSFilterAssociationDB) DeleteByFilterRuleID(filterRuleID uint) error
DeleteByFilterRuleID deletes all associations for a filter rule.
func (*RSSFilterAssociationDB) DeleteByRSSID ¶ added in v0.2.0
func (r *RSSFilterAssociationDB) DeleteByRSSID(rssID uint) error
DeleteByRSSID deletes all associations for an RSS subscription.
func (*RSSFilterAssociationDB) Exists ¶ added in v0.2.0
func (r *RSSFilterAssociationDB) Exists(rssID, filterRuleID uint) (bool, error)
Exists checks if an association exists.
func (*RSSFilterAssociationDB) GetByFilterRuleID ¶ added in v0.2.0
func (r *RSSFilterAssociationDB) GetByFilterRuleID(filterRuleID uint) ([]uint, error)
GetByFilterRuleID retrieves all RSS IDs associated with a filter rule.
func (*RSSFilterAssociationDB) GetByRSSID ¶ added in v0.2.0
func (r *RSSFilterAssociationDB) GetByRSSID(rssID uint) ([]uint, error)
GetByRSSID retrieves all filter rule IDs associated with an RSS subscription.
func (*RSSFilterAssociationDB) GetFilterRuleIDsForRSS ¶ added in v0.2.0
func (r *RSSFilterAssociationDB) GetFilterRuleIDsForRSS(rssID uint) ([]uint, error)
GetFilterRuleIDsForRSS is an alias for GetByRSSID for better readability.
func (*RSSFilterAssociationDB) GetFilterRulesForRSS ¶ added in v0.2.0
func (r *RSSFilterAssociationDB) GetFilterRulesForRSS(rssID uint) ([]FilterRule, error)
GetFilterRulesForRSS retrieves all filter rules associated with an RSS subscription.
func (*RSSFilterAssociationDB) HasAssociations ¶ added in v0.2.0
func (r *RSSFilterAssociationDB) HasAssociations(rssID uint) (bool, error)
HasAssociations checks if an RSS subscription has any filter rule associations.
func (*RSSFilterAssociationDB) SetFilterRulesForRSS ¶ added in v0.2.0
func (r *RSSFilterAssociationDB) SetFilterRulesForRSS(rssID uint, filterRuleIDs []uint) error
SetFilterRulesForRSS sets the filter rules for an RSS subscription (replaces all existing associations).
type RSSNotificationLog ¶ added in v0.31.0
type RSSNotificationLog struct {
ID uint `gorm:"primaryKey;autoIncrement" json:"id"`
RSSID uint `` /* 132-byte string literal not displayed */
SiteName string `gorm:"column:site_name;not null;uniqueIndex:idx_rss_notify_dedup,priority:2" json:"site_name"`
TorrentID string `gorm:"column:torrent_id;not null;uniqueIndex:idx_rss_notify_dedup,priority:3" json:"torrent_id"`
NotifyKind string `gorm:"column:notify_kind;not null;uniqueIndex:idx_rss_notify_dedup,priority:4" json:"notify_kind"`
NotificationConfID uint `gorm:"column:notification_conf_id;not null;uniqueIndex:idx_rss_notify_dedup,priority:5" json:"notification_conf_id"`
MatchedFilterRuleID *uint `gorm:"column:matched_filter_rule_id" json:"matched_filter_rule_id,omitempty"`
Result string `gorm:"not null;index:idx_rss_notify_pending,priority:1" json:"result"`
Attempts int `gorm:"default:0" json:"attempts"`
NextRetryAt *time.Time `gorm:"column:next_retry_at;index:idx_rss_notify_pending,priority:2" json:"next_retry_at,omitempty"`
LastError string `gorm:"default:''" json:"last_error,omitempty"`
PayloadJSON string `gorm:"column:payload_json" json:"payload_json,omitempty"`
DeliveredAt *time.Time `gorm:"column:delivered_at" json:"delivered_at,omitempty"`
CreatedAt time.Time `gorm:"index:idx_rss_notify_rss_throttle,priority:2" json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
}
RSSNotificationLog records every (rss_id, torrent_id, notify_kind, conf_id) notification attempt. Acts as the durable record AND the idempotency guard (via the unique index idx_rss_notify_dedup).
result values: 'sent' | 'failed' | 'suppressed' | 'pending' | 'throttled'
- 'sent' — accepted by NotificationService.Push (note: may have fallen back to outbox internally; not strictly equal to "delivered to user")
- 'failed' — Push returned an error
- 'suppressed' — overshadowed by a later 'filtered' notification for the same (rss_id, site_name, torrent_id)
- 'pending' — queued but not yet attempted (S3 retry worker uses this)
- 'throttled' — rejected because RSS hit max_notifications_per_hour
func (RSSNotificationLog) TableName ¶ added in v0.31.0
func (RSSNotificationLog) TableName() string
type RSSSubscription ¶ added in v0.1.0
type RSSSubscription struct {
ID uint `gorm:"primaryKey" json:"id"`
SiteID uint `gorm:"index" json:"site_id"`
Name string `gorm:"size:128;not null" json:"name"`
URL string `gorm:"size:1024;not null" json:"url"`
Category string `gorm:"size:128" json:"category"`
Tag string `gorm:"size:128" json:"tag"`
IntervalMinutes int32 `gorm:"check:interval_minutes >= 1" json:"interval_minutes"` // RSS 执行间隔(分钟),0 表示使用全局设置
Concurrency int32 `json:"concurrency"` // 并发数,0 表示使用全局设置
DownloadSubPath string `gorm:"size:256" json:"download_sub_path"`
DownloadPath string `gorm:"size:512" json:"download_path"` // 下载器中下载任务的目标下载路径(可选)
DownloaderID *uint `gorm:"index" json:"downloader_id"` // 指定下载器,nil 表示使用默认下载器
IsExample bool `json:"is_example"` // 是否为示例配置,示例配置不会被执行
PauseOnFreeEnd bool `gorm:"default:false" json:"pause_on_free_end"`
FilterMode FilterMode `gorm:"size:16;default:''" json:"filter_mode"` // 空字符串表示使用全局 DefaultFilterMode
NotifyMode string `gorm:"column:notify_mode;default:''" json:"notify_mode"`
NotifyConfIDs string `gorm:"column:notify_conf_ids;default:'[]'" json:"notify_conf_ids"`
MaxNotificationsPerHour int `gorm:"column:max_notifications_per_hour;default:100" json:"max_notifications_per_hour"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
}
RSS 订阅
type RegisteredSite ¶ added in v0.2.0
type RegisteredSite struct {
ID string
Name string
AuthMethod string // "cookie" 或 "api_key"
DefaultBaseURL string
APIUrls []string // API URL 列表,用于轮换(如 mTorrent 站点)
}
RegisteredSite 表示从注册表获取的站点信息
type ResType ¶
type ResType interface {
MTTorrentDetail | PHPTorrentInfo
FreeDownChecker
TorrentMetadata
}
type ReseedRecord ¶
type ReseedRecord struct {
ID uint `gorm:"primaryKey" json:"id"`
InfoHash string `gorm:"size:64;not null;uniqueIndex:idx_reseed_hash_site" json:"info_hash"`
SiteName string `gorm:"size:64;not null;uniqueIndex:idx_reseed_hash_site;index" json:"site_name"`
// TorrentID 是站内种子 ID;SourceHash 是下载器里那个数据相同的种子。
TorrentID string `gorm:"size:128;default:''" json:"torrent_id"`
SourceHash string `gorm:"size:64;default:''" json:"source_hash"`
DownloaderID uint `gorm:"not null;default:0" json:"downloader_id"`
Name string `gorm:"size:512;default:''" json:"name"`
State string `gorm:"size:32;not null;index" json:"state"`
Message string `gorm:"size:1024;default:''" json:"message"`
// Retryable 表示这次失败是暂时的(站点不可用、下载种子失败),过了 ReseedRetryAfter 可以再试;核对没通过的不再试。
Retryable bool `gorm:"not null;default:false" json:"retryable"`
JobID *uint `gorm:"index" json:"job_id,omitempty"`
CreatedAt time.Time `gorm:"index" json:"created_at"`
UpdatedAt time.Time `gorm:"index" json:"updated_at"`
}
ReseedRecord 记下对某个站点某个种子(info hash)的一次辅种尝试,同一对只尝试一次。
type ReseedSetting ¶
type ReseedSetting struct {
ID uint `gorm:"primaryKey" json:"id"`
Enabled bool `gorm:"not null;default:false" json:"enabled"`
// TokenEncrypted 是加密后的 IYUU token;接口只返回是否已设置。
TokenEncrypted string `gorm:"type:text;default:''" json:"-"`
// IntervalHours 是定时运行的间隔(0 时按 ReseedDefaultIntervalHours)。
IntervalHours int `gorm:"not null;default:0" json:"interval_hours"`
// DownloaderIDs 是参与辅种的下载器(JSON 数组,空表示全部启用的下载器)。
DownloaderIDs string `gorm:"type:text;default:''" json:"-"`
// SiteNames 是允许辅种的站点(JSON 数组,空表示全部已配置、IYUU 也支持的站点)。
SiteNames string `gorm:"type:text;default:''" json:"-"`
// MaxPerSitePerDay 是每个站点每天最多加几个辅种(0 时按 ReseedDefaultMaxPerSitePerDay)。
MaxPerSitePerDay int `gorm:"not null;default:0" json:"max_per_site_per_day"`
// SidSha1 是 IYUU 的 reportExisting 返回的站点哈希,SidKey 是当时报告的站点 sid 列表;7 天内站点没变时复用。
SidSha1 string `gorm:"size:128;default:''" json:"-"`
SidKey string `gorm:"type:text;default:''" json:"-"`
SidAt *time.Time `json:"-"`
LastRunAt *time.Time `json:"last_run_at,omitempty"`
// LastResult 是上一轮的一句话结果。
LastResult string `gorm:"type:text;default:''" json:"last_result"`
UpdatedAt time.Time `json:"updated_at"`
}
ReseedSetting 是 IYUU 辅种的设置(只有一行,ID 为 1)。默认关闭;列的默认值一律是零值。
type SchemaManager ¶ added in v0.2.0
type SchemaManager struct {
BackupTable func(db *gorm.DB, table string) (path string, err error)
EncryptCookie func(plain string) (cipher string, err error)
DecryptCookie func(cipher string) (plain string, err error)
// contains filtered or unexported fields
}
SchemaManager 架构版本管理器
func NewSchemaManager ¶ added in v0.2.0
func NewSchemaManager(db *gorm.DB, appVersion string) *SchemaManager
NewSchemaManager 创建架构版本管理器
func NewSchemaManagerWithHooks ¶ added in v0.35.0
func (*SchemaManager) EnsureSchemaVersionTable ¶ added in v0.2.0
func (sm *SchemaManager) EnsureSchemaVersionTable() error
EnsureSchemaVersionTable 确保版本表存在
func (*SchemaManager) GetCurrentVersion ¶ added in v0.2.0
func (sm *SchemaManager) GetCurrentVersion() (int, error)
GetCurrentVersion 获取当前数据库架构版本
func (*SchemaManager) RecordVersion ¶ added in v0.2.0
func (sm *SchemaManager) RecordVersion(version int, description string) error
RecordVersion 记录版本
func (*SchemaManager) RunMigrations ¶ added in v0.2.0
func (sm *SchemaManager) RunMigrations() error
RunMigrations 运行所有待执行的迁移
type SchemaVersion ¶ added in v0.2.0
type SchemaVersion struct {
ID uint `gorm:"primaryKey" json:"id"`
Version int `gorm:"uniqueIndex;not null" json:"version"` // 架构版本号
Description string `gorm:"size:255" json:"description"` // 版本描述
AppliedAt time.Time `gorm:"not null" json:"applied_at"` // 应用时间
AppVersion string `gorm:"size:64" json:"app_version"` // 应用版本
}
SchemaVersion 数据库架构版本表 用于跟踪数据库迁移状态
type SettingsGlobal ¶ added in v0.1.0
type SettingsGlobal struct {
ID uint `gorm:"primaryKey" json:"id"`
DefaultIntervalMinutes int32 `json:"default_interval_minutes" gorm:"default:10"` // 默认 RSS 执行间隔(分钟)
DefaultConcurrency int32 `json:"default_concurrency" gorm:"default:3"` // 默认并发数
DefaultEnabled bool `json:"default_enabled"`
DownloadDir string `gorm:"not null" json:"download_dir"`
DownloadLimitEnabled bool `json:"download_limit_enabled"`
DownloadSpeedLimit int `json:"download_speed_limit"`
TorrentSizeGB int `json:"torrent_size_gb"`
TorrentMinSizeGB int `json:"torrent_min_size_gb"` // 全局最小种子大小(GB),0 = 无下限
MinFreeMinutes int `json:"min_free_minutes" gorm:"default:30"`
AutoStart bool `json:"auto_start"`
RetainHours int `json:"retain_hours" gorm:"default:24"`
MaxRetry int `json:"max_retry" gorm:"default:3"`
// 自动删种
CleanupEnabled bool `json:"cleanup_enabled" gorm:"default:false"`
CleanupIntervalMin int `json:"cleanup_interval_min" gorm:"default:30"`
CleanupScope string `json:"cleanup_scope" gorm:"size:16;default:'database'"`
CleanupScopeTags string `json:"cleanup_scope_tags" gorm:"size:256"`
CleanupRemoveData bool `json:"cleanup_remove_data" gorm:"default:true"`
CleanupConditionMode string `json:"cleanup_condition_mode" gorm:"size:8;default:'or'"`
CleanupMaxSeedTimeH int `json:"cleanup_max_seed_time_h" gorm:"default:0"`
CleanupMinRatio float64 `json:"cleanup_min_ratio" gorm:"default:0"`
CleanupMaxInactiveH int `json:"cleanup_max_inactive_h" gorm:"default:0"`
CleanupSlowSeedTimeH int `json:"cleanup_slow_seed_time_h" gorm:"default:0"`
CleanupSlowMaxRatio float64 `json:"cleanup_slow_max_ratio" gorm:"default:0"`
CleanupDelFreeExpired bool `json:"cleanup_del_free_expired" gorm:"default:true"`
CleanupDiskProtect bool `json:"cleanup_disk_protect" gorm:"default:true"`
CleanupMinDiskSpaceGB float64 `json:"cleanup_min_disk_space_gb" gorm:"default:50"`
CleanupProtectDL bool `json:"cleanup_protect_dl" gorm:"default:false"`
CleanupProtectHR bool `json:"cleanup_protect_hr" gorm:"default:true"`
CleanupMinRetainH int `json:"cleanup_min_retain_h" gorm:"default:24"`
CleanupProtectTags string `json:"cleanup_protect_tags" gorm:"size:256"`
// 免费结束自动删除
AutoDeleteOnFreeEnd bool `json:"auto_delete_on_free_end" gorm:"default:false"` // 免费期结束时自动删除未完成的种子及数据
// 免费期结束前提前处理的安全余量(分钟)。>0 时暂停/删除提前 N 分钟触发,规避删除延迟与
// tracker 汇报滞后导致的超额下载量;0 = 到点处理(旧行为)。生效范围 [0,60]。
FreeEndAdvanceMinutes int `json:"free_end_advance_minutes" gorm:"default:0"`
// 默认下载模式(RSS 级别可 override)
DefaultFilterMode FilterMode `json:"default_filter_mode" gorm:"size:16;default:'auto_free'"`
// 做种竞争度监控(Peer Ratio Monitor)
PeerRatioEnabled bool `json:"peer_ratio_enabled" gorm:"default:false"` // 是否启用做种竞争度监控
PeerRatioMaxSL float64 `json:"peer_ratio_max_sl" gorm:"default:30.0"` // Seeder/Leecher 比值上限
PeerRatioIntervalMin int `json:"peer_ratio_interval_min" gorm:"default:10"` // 检查间隔(分钟)
PeerRatioRemoveData bool `json:"peer_ratio_remove_data" gorm:"default:false"` // 超标时删除种子及数据(否则仅暂停)
// 每日签到时间窗(HH:MM,进程时区):各站每天在窗口内随机取一个时刻签到。
// 只经 ConfigStore.SaveAttendanceWindow 写;SaveGlobalSettings 不改这两列。
AttendanceWindowStart string `json:"attendance_window_start" gorm:"size:5;default:'08:00'"`
AttendanceWindowEnd string `json:"attendance_window_end" gorm:"size:5;default:'10:00'"`
// 每日战报:每天在设定时刻(HH:MM,进程时区)加上本安装固定的偏移后,把当天的数据增量发到选定的通道。
// 只经 ConfigStore.SaveDailyReportSettings 写;SaveGlobalSettings 不改这几列。
DailyReportEnabled bool `json:"daily_report_enabled" gorm:"default:false"`
DailyReportTime string `json:"daily_report_time" gorm:"size:5;default:'22:00'"`
DailyReportChannelIDs string `json:"daily_report_channel_ids" gorm:"size:512;default:'[]'"`
// DailyReportOffsetSeconds 是本安装固定的 1–600 秒偏移,首次用到时随机分配;0 表示还没分配。
// 各安装错开发送时刻,不在同一分钟一起打通知接口。
DailyReportOffsetSeconds int `json:"-" gorm:"default:0"`
// 下载器助手的失效种子定时扫描:只通知、不删种。只经 ConfigStore.SaveDeadTorrentScanSettings 写。
// 间隔为 0 时按 24 小时。列的默认值都是零值(GORM 新建时会把零值换成 default)。
DeadTorrentScanEnabled bool `json:"dead_torrent_scan_enabled" gorm:"default:false"`
DeadTorrentScanIntervalH int `json:"dead_torrent_scan_interval_h" gorm:"default:0"`
DeadTorrentScanChannelIDs string `json:"dead_torrent_scan_channel_ids" gorm:"size:512;default:''"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
}
全局设置
func (*SettingsGlobal) GetEffectiveConcurrency ¶ added in v0.2.0
func (s *SettingsGlobal) GetEffectiveConcurrency() int32
GetEffectiveConcurrency 获取有效的并发数(带默认值和边界检查)
func (*SettingsGlobal) GetEffectiveIntervalMinutes ¶ added in v0.2.0
func (s *SettingsGlobal) GetEffectiveIntervalMinutes() int32
GetEffectiveIntervalMinutes 获取有效的间隔时间(带默认值和边界检查)
func (*SettingsGlobal) GetEffectivePeerRatioIntervalMin ¶ added in v0.23.0
func (s *SettingsGlobal) GetEffectivePeerRatioIntervalMin() int
func (*SettingsGlobal) GetEffectivePeerRatioMaxSL ¶ added in v0.23.0
func (s *SettingsGlobal) GetEffectivePeerRatioMaxSL() float64
type Showcase ¶
type Showcase struct {
CreatedDate string `json:"createdDate"`
LastModifiedDate string `json:"lastModifiedDate"`
ID string `json:"id"`
Collection bool `json:"collection"`
UserID string `json:"userid"`
Username string `json:"username"`
CnTitle string `json:"cntitle"`
EnTitle string `json:"entitle"`
Note string `json:"note"`
Pic string `json:"pic"`
Pic1 string `json:"pic1"`
Pic2 string `json:"pic2"`
Count string `json:"count"`
Size string `json:"size"`
View string `json:"view"`
Statistics Statistics `json:"statistics"`
}
type SiteAttendanceLog ¶
type SiteAttendanceLog struct {
ID uint `gorm:"primaryKey;autoIncrement" json:"id"`
SiteName string `gorm:"size:64;not null;uniqueIndex:idx_site_attendance_day,priority:1" json:"site_name"`
Day string `gorm:"size:10;not null;uniqueIndex:idx_site_attendance_day,priority:2" json:"day"`
Status string `gorm:"size:16;not null;default:'pending'" json:"status"`
Attempts int `gorm:"not null;default:0" json:"attempts"`
ScheduledAt time.Time `json:"scheduled_at"`
NextAttemptAt *time.Time `json:"next_attempt_at,omitempty"`
LastAttemptAt *time.Time `json:"last_attempt_at,omitempty"`
Message string `gorm:"size:512;default:''" json:"message,omitempty"`
LastError string `gorm:"size:1024;default:''" json:"last_error,omitempty"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
}
SiteAttendanceLog 记录每个站点每天的签到,(site_name, day) 唯一,一天一行。 Day 是进程时区(Docker 的 TZ)的日期 YYYY-MM-DD;时间列一律以 UTC 写入。
type SiteAttendanceRepository ¶
type SiteAttendanceRepository struct {
// contains filtered or unexported fields
}
func NewSiteAttendanceRepository ¶
func NewSiteAttendanceRepository(db *gorm.DB) *SiteAttendanceRepository
func (*SiteAttendanceRepository) EnsureDay ¶
func (r *SiteAttendanceRepository) EnsureDay(row SiteAttendanceLog) error
EnsureDay 在当天还没有记录时按 row 建行;已有行时什么也不改,所以一天的计划时间只定一次。
func (*SiteAttendanceRepository) GetDay ¶
func (r *SiteAttendanceRepository) GetDay(siteName, day string) (*SiteAttendanceLog, error)
GetDay 返回某站某天的签到记录,没有时返回 gorm.ErrRecordNotFound。
func (*SiteAttendanceRepository) ListDay ¶
func (r *SiteAttendanceRepository) ListDay(day string) ([]SiteAttendanceLog, error)
ListDay 返回某天所有站点的签到记录,按站点名排序。
type SiteConfig ¶ added in v0.1.0
type SiteConfig struct {
Enabled *bool `json:"enabled"`
AuthMethod string `json:"auth_method"`
Cookie string `json:"cookie"`
APIKey string `json:"api_key"`
APIUrl string `json:"api_url"`
Passkey string `json:"passkey"`
UploadLimitKBs int `json:"upload_limit_kbs"`
DownloadLimitKBs int `json:"download_limit_kbs"`
SeedingCapacityGB float64 `json:"seeding_capacity_gb"`
RSS []RSSConfig `json:"rss"`
}
type SiteData ¶ added in v0.6.0
type SiteData struct {
Name string
DisplayName string
BaseURL string
Enabled bool
AuthMethod string
Cookie string
CookieEncrypted string
APIKey string
APIURL string
Passkey string
DownloaderID *uint
ParserConfig string
IsBuiltin bool
TemplateID *uint
}
SiteData 站点数据(用于创建/更新)
type SiteLoginPreset ¶ added in v0.35.0
type SiteLoginState ¶ added in v0.35.0
type SiteLoginState struct {
ID uint `gorm:"primaryKey" json:"id"`
SiteName string `gorm:"uniqueIndex;size:64;not null" json:"site_name"`
LastLoginAt *time.Time `json:"last_login_at"`
LastAccessAt *time.Time `json:"last_access_at"`
LastVisitAt *time.Time `json:"last_visit_at"`
LastProbeAt *time.Time `json:"last_probe_at"`
LastProbeStatus string `gorm:"size:32" json:"last_probe_status"`
LastProbeError string `gorm:"type:text" json:"last_probe_error"`
ConsecutiveProbeFailures int `json:"consecutive_probe_failures"`
ProbeJitterSeconds int `json:"probe_jitter_seconds"`
BanThresholdDays int `gorm:"default:30" json:"ban_threshold_days"`
RemindBeforeDays int `gorm:"default:10" json:"remind_before_days"`
ReminderCron string `gorm:"size:64;default:'0 10,22 * * *'" json:"reminder_cron"`
NotificationChannelIDs string `gorm:"type:text" json:"notification_channel_ids"`
LastReminderTier string `gorm:"size:16;default:'none'" json:"last_reminder_tier"`
LastReminderSentAt *time.Time `json:"last_reminder_sent_at"`
ApiLastLoginAt *time.Time `json:"api_last_login_at,omitempty"`
CookieLastLoginAt *time.Time `json:"cookie_last_login_at,omitempty"`
ProbeMode string `gorm:"size:16;default:'auto'" json:"probe_mode"`
LastConsistencyCheck string `gorm:"size:32;default:''" json:"last_consistency_check"`
// 以下列由各自唯一的写者维护(见 scheduler/login_reminder_monitor.go 顶部的写者表)。
// NextProbeAt 是下一次定时探测的时间;LastProbeStartedAt 是最近一次探测开始(取锁并重读配置之前)的时间,
// 与 ProbeRequestedAt 一起判断「凭证更新后是否还欠一次探测」。
NextProbeAt *time.Time `json:"next_probe_at,omitempty"`
LastProbeStartedAt *time.Time `json:"last_probe_started_at,omitempty"`
ProbeRequestedAt *time.Time `json:"probe_requested_at,omitempty"`
// FirstFailureAt 是当前失败连续段的开始时间,探测成功时清空;LastSuccessAt 是最近一次成功探测的时间。
FirstFailureAt *time.Time `json:"first_failure_at,omitempty"`
LastSuccessAt *time.Time `json:"last_success_at,omitempty"`
// LastFailureNotifiedAt 是当前失败连续段最近一次发出失败提醒的时间,恢复提醒发出后清空。
LastFailureNotifiedAt *time.Time `json:"last_failure_notified_at,omitempty"`
// AccessStaleSince:探测成功但站点返回的 last_access 超过 48 小时没有前进时写入,前进后清空。
AccessStaleSince *time.Time `json:"access_stale_since,omitempty"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
}
func DefaultSiteLoginState ¶
func DefaultSiteLoginState(siteName string) SiteLoginState
DefaultSiteLoginState 返回新站点登录状态行的默认值。
type SiteLoginStateRepository ¶ added in v0.35.0
type SiteLoginStateRepository struct {
// contains filtered or unexported fields
}
func NewSiteLoginStateRepository ¶ added in v0.35.0
func NewSiteLoginStateRepository(db *gorm.DB) *SiteLoginStateRepository
func (*SiteLoginStateRepository) ClampLastVisit ¶ added in v0.35.0
func (r *SiteLoginStateRepository) ClampLastVisit(siteName string, ts, now time.Time) error
ClampLastVisit 记录浏览器扩展上报的访问时间:晚于 now 的按 now 记,早于已记录值的忽略(只前进不后退)。 比较在 Go 里做:历史数据可能以本地时区存储,SQLite 按字符串比较时间会排错序。
func (*SiteLoginStateRepository) EnsureLoginStateRow ¶
func (r *SiteLoginStateRepository) EnsureLoginStateRow(defaults SiteLoginState) error
EnsureLoginStateRow 在缺行时按 defaults 建行,已有行时什么也不改。 用 ON CONFLICT DO NOTHING,两个写者同时建行也不会报唯一约束冲突。
func (*SiteLoginStateRepository) GetLoginState ¶ added in v0.35.0
func (r *SiteLoginStateRepository) GetLoginState(siteName string) (*SiteLoginState, error)
func (*SiteLoginStateRepository) IncrProbeFailures ¶ added in v0.35.0
func (r *SiteLoginStateRepository) IncrProbeFailures(siteName string) error
func (*SiteLoginStateRepository) ListLoginStates ¶ added in v0.35.0
func (r *SiteLoginStateRepository) ListLoginStates(enabledOnly bool) ([]SiteLoginState, error)
func (*SiteLoginStateRepository) ResetProbeFailures ¶ added in v0.35.0
func (r *SiteLoginStateRepository) ResetProbeFailures(siteName string) error
func (*SiteLoginStateRepository) UpdateColumns ¶
func (r *SiteLoginStateRepository) UpdateColumns(siteName string, columns map[string]any) error
UpdateColumns 只写给出的列(键为列名),不读不改其他列。
func (*SiteLoginStateRepository) UpdateProbeResult ¶ added in v0.35.0
func (*SiteLoginStateRepository) UpsertLoginState ¶ added in v0.35.0
func (r *SiteLoginStateRepository) UpsertLoginState(siteName string, fields map[string]any) error
UpsertLoginState 只更新 fields 里给出的列(键为字段名,见 loginStateFieldColumns),缺行时先按默认值建行。 不整行写回,所以不会覆盖探测、提醒循环在此期间写入的列。
type SiteRateLimit ¶ added in v0.8.0
type SiteRateLimit struct {
SiteID string `gorm:"primaryKey;size:64" json:"site_id"`
WindowStart time.Time `gorm:"not null" json:"window_start"` // 当前窗口开始时间
RequestCount int `gorm:"default:0" json:"request_count"` // 当前窗口内请求数
UpdatedAt time.Time `gorm:"autoUpdateTime" json:"updated_at"`
}
SiteRateLimit 站点速率限制记录 每个站点一行,使用滑动窗口算法持久化请求计数
func (SiteRateLimit) TableName ¶ added in v0.8.0
func (SiteRateLimit) TableName() string
TableName 指定表名
type SiteRepository ¶ added in v0.6.0
type SiteRepository struct {
// contains filtered or unexported fields
}
SiteRepository 站点数据库操作封装
func NewSiteRepository ¶ added in v0.6.0
func NewSiteRepository(db *gorm.DB) *SiteRepository
func (*SiteRepository) BatchUpdateSiteDownloader ¶ added in v0.6.0
func (r *SiteRepository) BatchUpdateSiteDownloader(siteIDs []uint, downloaderID uint) (int64, error)
func (*SiteRepository) CreateSite ¶ added in v0.6.0
func (r *SiteRepository) CreateSite(data SiteData) (uint, error)
func (*SiteRepository) DeleteSite ¶ added in v0.6.0
func (r *SiteRepository) DeleteSite(name string) error
func (*SiteRepository) GetSiteByID ¶ added in v0.6.0
func (r *SiteRepository) GetSiteByID(id uint) (*SiteSetting, error)
func (*SiteRepository) GetSiteByName ¶ added in v0.6.0
func (r *SiteRepository) GetSiteByName(name string) (*SiteSetting, error)
func (*SiteRepository) ListEnabledSites ¶ added in v0.6.0
func (r *SiteRepository) ListEnabledSites() ([]SiteSetting, error)
func (*SiteRepository) ListSites ¶ added in v0.6.0
func (r *SiteRepository) ListSites() ([]SiteSetting, error)
func (*SiteRepository) SiteExistsByName ¶ added in v0.6.0
func (r *SiteRepository) SiteExistsByName(name string) (bool, error)
func (*SiteRepository) UpdateSiteCredentials ¶ added in v0.6.0
func (r *SiteRepository) UpdateSiteCredentials(name string, enabled *bool, authMethod, cookie, apiKey, apiURL, passkey string) error
func (*SiteRepository) UpdateSiteDownloader ¶ added in v0.6.0
func (r *SiteRepository) UpdateSiteDownloader(name string, downloaderID *uint) error
func (*SiteRepository) UpdateSiteDownloaderByID ¶ added in v0.6.0
func (r *SiteRepository) UpdateSiteDownloaderByID(siteID uint, downloaderID *uint) error
type SiteSetting ¶ added in v0.1.0
type SiteSetting struct {
ID uint `gorm:"primaryKey" json:"id"`
Name string `gorm:"uniqueIndex;size:64;not null" json:"name"`
DisplayName string `gorm:"size:128" json:"display_name"`
BaseURL string `gorm:"size:512" json:"base_url"`
Enabled bool `json:"enabled"`
AuthMethod string `gorm:"size:16;not null" json:"auth_method"`
Cookie string `gorm:"size:2048" json:"cookie,omitempty"`
CookieEncrypted string `gorm:"type:text" json:"cookie_encrypted,omitempty"`
APIKey string `gorm:"size:512" json:"api_key,omitempty"`
APIUrl string `gorm:"size:512" json:"api_url,omitempty"`
APIUrls string `gorm:"size:2048" json:"api_urls,omitempty"`
Passkey string `gorm:"size:512" json:"passkey,omitempty"`
DownloaderID *uint `gorm:"index" json:"downloader_id,omitempty"`
ParserConfig string `gorm:"type:text" json:"parser_config,omitempty"`
UploadLimitKBs int `gorm:"default:0" json:"upload_limit_kbs"`
DownloadLimitKBs int `gorm:"default:0" json:"download_limit_kbs"`
SeedingCapacityGB float64 `gorm:"default:0" json:"seeding_capacity_gb"` // 单站点刷流容量上限(GB),0=不限制 (#405)
AttendanceEnabled bool `gorm:"default:false" json:"attendance_enabled"` // 每日自动签到,默认关闭;只经 ConfigStore.SetSiteAttendanceEnabled 写
IsBuiltin bool `json:"is_builtin"`
TemplateID *uint `gorm:"index" json:"template_id,omitempty"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
}
SiteSetting 站点设置(统一表,合并原 DynamicSiteSetting)
type SiteTemplate ¶ added in v0.2.0
type SiteTemplate struct {
ID uint `gorm:"primaryKey" json:"id"`
Name string `gorm:"uniqueIndex;size:64;not null" json:"name"`
DisplayName string `gorm:"size:128" json:"display_name"`
BaseURL string `gorm:"size:512;not null" json:"base_url"`
AuthMethod string `gorm:"size:16;not null" json:"auth_method"` // cookie, api_key
ParserConfig string `gorm:"type:text" json:"parser_config"` // JSON格式的解析器配置
Description string `gorm:"size:1024" json:"description"`
Version string `gorm:"size:32" json:"version"`
Author string `gorm:"size:64" json:"author"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
}
SiteTemplate 站点模板 用于导入/导出站点配置(不包含敏感信息)
func (*SiteTemplate) FromExport ¶ added in v0.2.0
func (t *SiteTemplate) FromExport(export *SiteTemplateExport) error
FromExport 从导出格式创建
func (SiteTemplate) TableName ¶ added in v0.2.0
func (SiteTemplate) TableName() string
TableName 指定表名
func (*SiteTemplate) ToExport ¶ added in v0.2.0
func (t *SiteTemplate) ToExport() *SiteTemplateExport
ToExport 转换为导出格式
type SiteTemplateExport ¶ added in v0.2.0
type SiteTemplateExport struct {
Name string `json:"name"`
DisplayName string `json:"display_name"`
BaseURL string `json:"base_url"`
AuthMethod string `json:"auth_method"`
ParserConfig json.RawMessage `json:"parser_config,omitempty"`
Description string `json:"description,omitempty"`
Version string `json:"version,omitempty"`
Author string `json:"author,omitempty"`
}
SiteTemplateExport 导出格式(不包含数据库字段)
type Statistics ¶
type Statistics struct {
CreatedDate string `json:"createdDate"`
LastModifiedDate string `json:"lastModifiedDate"`
ID string `json:"id"`
Day string `json:"day"`
Week string `json:"week"`
Month string `json:"month"`
Year string `json:"year"`
DayClick string `json:"dayClick"`
WeekClick string `json:"weekClick"`
MonthClick string `json:"monthClick"`
YearClick string `json:"yearClick"`
}
type Status ¶
type Status struct {
ID string `json:"id"`
CreatedDate string `json:"createdDate"`
LastModifiedDate string `json:"lastModifiedDate"`
PickType string `json:"pickType"`
ToppingLevel string `json:"toppingLevel"`
ToppingEndTime string `json:"toppingEndTime"`
Discount string `json:"discount"`
DiscountEndTime string `json:"discountEndTime"`
TimesCompleted string `json:"timesCompleted"`
Comments string `json:"comments"`
LastAction string `json:"lastAction"`
LastSeederAction string `json:"lastSeederAction"`
Views string `json:"views"`
Hits string `json:"hits"`
Support string `json:"support"`
Oppose string `json:"oppose"`
Status string `json:"status"`
Seeders string `json:"seeders"`
Leechers string `json:"leechers"`
Banned bool `json:"banned"`
Visible bool `json:"visible"`
PromotionRule *PromotionRule `json:"promotionRule"`
MallSingleFree any `json:"mallSingleFree"`
}
type TorrentDB ¶
TorrentDB 封装数据库操作
func NewDBWithVersion ¶ added in v0.2.0
NewDBWithVersion 初始化并返回 TorrentDB(带应用版本)
func NewDBWithVersionAndHooks ¶ added in v0.35.0
func (*TorrentDB) DeleteTorrent ¶
DeleteTorrent 删除种子信息
func (*TorrentDB) GetAllTorrents ¶
func (t *TorrentDB) GetAllTorrents() ([]TorrentInfo, error)
GetAllTorrents 查询所有种子信息
func (*TorrentDB) GetTorrentBySiteAndHash ¶
func (t *TorrentDB) GetTorrentBySiteAndHash(siteName, torrentHash string) (*TorrentInfo, error)
GetTorrentBySiteAndHash 根据 SiteName 和 TorrentHash 查询种子信息
func (*TorrentDB) GetTorrentBySiteAndID ¶
func (t *TorrentDB) GetTorrentBySiteAndID(siteName, torrentID string) (*TorrentInfo, error)
GetTorrentBySiteAndID 根据 SiteName 和 TorrentID 查询种子信息
func (*TorrentDB) UpdateTorrentStatus ¶
func (t *TorrentDB) UpdateTorrentStatus(torrentHash string, isDownloaded, isPushed bool, pushTime *time.Time) error
UpdateTorrentStatus 更新种子状态
func (*TorrentDB) UpsertTorrent ¶
func (t *TorrentDB) UpsertTorrent(torrent *TorrentInfo) error
UpsertTorrent 插入或更新种子信息
func (*TorrentDB) WithTransaction ¶
WithTransaction 使用事务
type TorrentInfo ¶
type TorrentInfo struct {
ID uint `gorm:"primaryKey" json:"id"`
SiteName string `gorm:"uniqueIndex:idx_site_torrent" json:"siteName"`
TorrentID string `gorm:"uniqueIndex:idx_site_torrent" json:"torrentId"`
TorrentHash *string `gorm:"index" json:"torrentHash"`
IsFree bool `gorm:"default:false" json:"isFree"`
IsDownloaded bool `gorm:"default:false" json:"isDownloaded"`
IsPushed *bool `gorm:"default:null" json:"isPushed"`
IsSkipped bool `gorm:"default:false" json:"isSkipped"`
FreeLevel string `gorm:"default:'normal'" json:"freeLevel"`
FreeEndTime *time.Time `gorm:"default:null" json:"freeEndTime"`
PushTime *time.Time `gorm:"default:null" json:"pushTime"`
Title string `gorm:"default:''" json:"title"`
Category string `gorm:"default:''" json:"category"`
Tag string `gorm:"default:''" json:"tag"`
CreatedAt time.Time `json:"createdAt"`
UpdatedAt time.Time `json:"updatedAt"`
IsExpired bool `gorm:"default:false" json:"isExpired"`
LastCheckTime *time.Time `gorm:"default:null" json:"lastCheckTime"`
RetryCount int `gorm:"default:0" json:"retryCount"`
LastError string `gorm:"default:''" json:"lastError"`
DownloadSource string `gorm:"size:32;default:'free_download'" json:"downloadSource"` // free_download or filter_rule
FilterRuleID *uint `gorm:"index" json:"filterRuleId"` // ID of the matched filter rule
// 免费结束管理相关字段
DownloaderID *uint `gorm:"index" json:"downloaderId"` // 推送到的下载器 ID
DownloaderName string `gorm:"size:64;default:''" json:"downloaderName"` // 下载器名称(冗余存储便于查询)
CompletedAt *time.Time `gorm:"default:null" json:"completedAt"` // 下载完成时间
IsPausedBySystem bool `gorm:"default:false" json:"isPausedBySystem"` // 是否被系统自动暂停
PauseOnFreeEnd bool `gorm:"default:false" json:"pauseOnFreeEnd"` // 免费结束时是否暂停(来自 RSS 配置)
PausedAt *time.Time `gorm:"default:null" json:"pausedAt"` // 系统暂停时间
PauseReason string `gorm:"size:256;default:''" json:"pauseReason"` // 暂停原因
IsCompleted bool `gorm:"default:false;index" json:"isCompleted"` // 下载是否已完成
Progress float64 `gorm:"default:0" json:"progress"` // 下载进度 (0-100)
TorrentSize int64 `gorm:"default:0" json:"torrentSize"` // 种子大小(字节)
DownloaderTaskID string `gorm:"size:128;default:''" json:"downloaderTaskId"`
HasHR bool `gorm:"default:false" json:"hasHR"`
HRSeedTimeH int `gorm:"default:0" json:"hrSeedTimeH"` // 下载器中的任务 ID(用于暂停/删除操作)
CheckCount int `gorm:"default:0" json:"checkCount"` // 进度检查次数
Seeders int `gorm:"default:0" json:"seeders"`
Leechers int `gorm:"default:0" json:"leechers"`
}
TorrentInfo 表示种子信息
func (*TorrentInfo) GetExpired ¶ added in v0.0.10
func (t *TorrentInfo) GetExpired() bool
type TorrentInfoArchive ¶ added in v0.3.0
type TorrentInfoArchive struct {
ID uint `gorm:"primaryKey" json:"id"`
OriginalID uint `gorm:"index" json:"originalId"`
SiteName string `gorm:"index" json:"siteName"`
TorrentID string `gorm:"index" json:"torrentId"`
TorrentHash *string `gorm:"index" json:"torrentHash"`
IsFree bool `json:"isFree"`
IsDownloaded bool `json:"isDownloaded"`
IsPushed *bool `json:"isPushed"`
IsSkipped bool `json:"isSkipped"`
FreeLevel string `json:"freeLevel"`
FreeEndTime *time.Time `json:"freeEndTime"`
PushTime *time.Time `json:"pushTime"`
Title string `json:"title"`
Category string `json:"category"`
Tag string `json:"tag"`
OriginalCreatedAt time.Time `json:"originalCreatedAt"`
OriginalUpdatedAt time.Time `json:"originalUpdatedAt"`
IsExpired bool `json:"isExpired"`
LastCheckTime *time.Time `json:"lastCheckTime"`
RetryCount int `json:"retryCount"`
LastError string `json:"lastError"`
DownloadSource string `json:"downloadSource"`
FilterRuleID *uint `json:"filterRuleId"`
DownloaderID *uint `json:"downloaderId"`
DownloaderName string `json:"downloaderName"`
CompletedAt *time.Time `json:"completedAt"`
IsPausedBySystem bool `json:"isPausedBySystem"`
PauseOnFreeEnd bool `json:"pauseOnFreeEnd"`
PausedAt *time.Time `json:"pausedAt"`
PauseReason string `json:"pauseReason"`
IsCompleted bool `json:"isCompleted"`
Progress float64 `json:"progress"`
TorrentSize int64 `json:"torrentSize"`
DownloaderTaskID string `json:"downloaderTaskId"`
HasHR bool `json:"hasHR"`
HRSeedTimeH int `json:"hrSeedTimeH"`
CheckCount int `json:"checkCount"`
ArchivedAt time.Time `gorm:"autoCreateTime" json:"archivedAt"`
}
TorrentInfoArchive 种子信息归档表(存储超过保留期的记录)
type TorrentMetadata ¶ added in v0.2.0
type TorrentMetadata interface {
// GetName 获取种子名称(优先返回中文名)
GetName() string
// GetSubTitle 获取副标题/标签信息
GetSubTitle() string
// GetSizeBytes 获取种子大小(字节),用于过滤规则的大小匹配
GetSizeBytes() int64
}
TorrentMetadata 统一的种子元数据接口 用于获取种子的标题、副标题等信息,便于过滤规则匹配
type TorrentTransferJob ¶
type TorrentTransferJob struct {
ID uint `gorm:"primaryKey" json:"id"`
// Kind 是任务种类:空串是转移做种,reseed 是辅种(源与目标是同一台下载器,不移除任何种子)。
Kind string `gorm:"size:16;not null;default:'';index" json:"kind"`
SourceDownloaderID uint `gorm:"not null;index" json:"source_downloader_id"`
TargetDownloaderID uint `gorm:"not null;index" json:"target_downloader_id"`
InfoHash string `gorm:"size:64;not null;index" json:"info_hash"`
Name string `gorm:"size:512;default:''" json:"name"`
TotalSize int64 `gorm:"not null;default:0" json:"total_size"`
// SiteName 与 TorrentID 来自 pt-tools 的种子记录;没有记录时 SiteName 按 tracker 认出,TorrentID 为空。
SiteName string `gorm:"size:64;default:''" json:"site_name"`
TorrentID string `gorm:"size:128;default:''" json:"torrent_id"`
SourceSavePath string `gorm:"size:1024;default:''" json:"source_save_path"`
TargetSavePath string `gorm:"size:1024;default:''" json:"target_save_path"`
Category string `gorm:"size:128;default:''" json:"category"`
Tags string `gorm:"size:512;default:''" json:"tags"`
// OwnerTag 是加入目标时带上的这个任务独有的标签(JobTag),恢复、校验、回滚、收尾前用它确认目标里的种子是这个任务加的;
// 加入之前写进库,任务结束后从下载器里去掉。空串是早期版本建的任务,按这一种任务的通用标签认。
OwnerTag string `gorm:"size:64;not null;default:''" json:"-"`
State string `gorm:"size:32;not null;index" json:"state"`
Message string `gorm:"size:1024;default:''" json:"message"`
// Progress 是最近一次看到的目标校验进度(0–1)。
Progress float64 `gorm:"not null;default:0" json:"progress"`
// RecheckIssued 表示已经让目标下载器开始校验。
RecheckIssued bool `gorm:"not null;default:false" json:"recheck_issued"`
// TorrentData 是导出的种子文件;任务结束时清空。
TorrentData []byte `gorm:"type:blob" json:"-"`
RuleID *uint `gorm:"index" json:"rule_id,omitempty"`
// CheckStartedAt 是加入目标的时间;Deadline 是校验时限。
CheckStartedAt *time.Time `json:"check_started_at,omitempty"`
Deadline *time.Time `json:"deadline,omitempty"`
FinishedAt *time.Time `json:"finished_at,omitempty"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
}
TorrentTransferJob 是把一个种子从源下载器转移到目标下载器的任务:导出种子 → 暂停加入目标(数据路径按映射换算) → 校验到 100% → 恢复目标 → 从源移除(不删数据)。状态持久化,进程重启后接着做。 列的默认值一律是零值(GORM 新建时会把零值换成 default)。
type TransferRule ¶
type TransferRule struct {
ID uint `gorm:"primaryKey" json:"id"`
Name string `gorm:"size:64;not null;uniqueIndex" json:"name"`
Enabled bool `gorm:"not null;default:false" json:"enabled"`
SourceDownloaderID uint `gorm:"not null" json:"source_downloader_id"`
TargetDownloaderID uint `gorm:"not null" json:"target_downloader_id"`
// Category 是分类等于;Tag 是标签里含有(大小写不敏感);SiteName 是 pt-tools 记录的站点或按 tracker 认出的站点。
Category string `gorm:"size:128;default:''" json:"category"`
Tag string `gorm:"size:128;default:''" json:"tag"`
SiteName string `gorm:"size:64;default:''" json:"site_name"`
MinSeedingHours int `gorm:"not null;default:0" json:"min_seeding_hours"`
// MaxPerRun 是每一轮最多建几个任务(0 时按 TransferRuleDefaultMaxPerRun)。
MaxPerRun int `gorm:"not null;default:0" json:"max_per_run"`
// IntervalMin 是运行间隔(分钟,0 时按 TransferRuleDefaultIntervalMin)。
IntervalMin int `gorm:"not null;default:0" json:"interval_min"`
LastRunAt *time.Time `json:"last_run_at,omitempty"`
LastResult string `gorm:"size:512;default:''" json:"last_result"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
}
TransferRule 是定时转移规则:按间隔把源下载器里符合条件、已经做完种的种子建成转移任务。默认关闭。 条件为空或 0 表示不限。
Source Files
¶
- brush.go
- chatops_models.go
- config_models.go
- cookiecloud.go
- enter.go
- filter_rule.go
- free_level.go
- init.go
- migration_state.go
- monitor_notification_log.go
- php_torrent.go
- presets.go
- rate_limit.go
- reseed.go
- resp.go
- rss_filter_association.go
- rss_notification_log.go
- schema_version.go
- site_attendance_log.go
- site_login_presets.go
- site_login_state.go
- site_repository.go
- site_template.go
- transfer.go