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 APIToken
- type ActionAudit
- type AdminUser
- type AssistantConfirmation
- type AssistantConversation
- type AssistantMessage
- type AssistantSetting
- 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 MediaCache
- type MediaDoubanItem
- type MediaDoubanSource
- type MediaLibrary
- type MediaOrganizeSetting
- type MediaOverride
- type MediaPathMap
- type MediaQualityProfile
- type MediaReplaceJournal
- type MediaServer
- type MediaSetting
- type MediaSubscribeSetting
- type MediaSubscription
- type MediaSubscriptionTorrent
- type MediaTransferHistory
- type MediaWatchDir
- type MediaWordRule
- type Migration
- type MigrationFunc
- type MigrationState
- type MonitorNotificationLog
- type NotificationConf
- type NotificationOutbox
- type NotificationTemplate
- 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 QbitCompatSetting
- type QbitCompatTorrent
- 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 RemoteDevice
- type RemoteSetting
- 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 ( AssistantEntryWeb = "web" AssistantEntryApp = "app" AssistantEntryChatOps = "chatops" )
AI 助手(路线图 M19)会话的入口。
const ( AssistantRoleUser = "user" AssistantRoleAssistant = "assistant" AssistantRoleTool = "tool" AssistantRoleNotice = "notice" )
AI 助手消息的角色。notice 是 pt-tools 自己写的提示(出错、已停止),不交给模型。
const ( AssistantConfirmPending = "pending" AssistantConfirmApproved = "approved" AssistantConfirmDenied = "denied" AssistantConfirmExpired = "expired" )
AI 助手待确认操作的状态:pending 只能经条件更新变成后面三种之一,变了就不再改。
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 ( MediaWordBlock = "block" // 屏蔽:从标题与副标题里去掉 MediaWordReplace = "replace" // 替换:换成另一段文字 MediaWordOffset = "offset" // 集数偏移:标题或副标题匹配时,集数加上偏移量(可为负) )
识别词的种类。
const ( MediaKindMovie = "movie" MediaKindTV = "tv" )
媒体库的种类。
const ( MediaModeHardlink = "hardlink" MediaModeCopy = "copy" MediaModeSymlink = "symlink" MediaModeMove = "move" )
整理方式。空串当作硬链接。
const ( MediaServerEmby = "emby" MediaServerJellyfin = "jellyfin" MediaServerPlex = "plex" // MediaRefreshPath 只通知整理到的目录(空串也是这个);MediaRefreshLibrary 刷新整个媒体库。 MediaRefreshPath = "path" MediaRefreshLibrary = "library" )
媒体服务器的种类与刷新方式。
const ( MediaTransferDone = "done" MediaTransferFailed = "failed" MediaTransferSkipped = "skipped" // MediaTransferRemoved 是库里的文件已经删掉的记录(删除记录时连文件一起删,或种子连数据删掉后清理了入库链接) MediaTransferRemoved = "removed" MediaTriggerAuto = "auto" MediaTriggerScan = "scan" MediaTriggerManual = "manual" // MediaTriggerWatch 是目录监控发现的(不是下载器里的种子) MediaTriggerWatch = "watch" )
整理记录的状态与触发方式。
const ( // MediaSubActive 在找资源:主动搜索,RSS 里的种子也会拿来对。 MediaSubActive = "active" // MediaSubPaused 暂停:不搜索,也不接 RSS。 MediaSubPaused = "paused" // MediaSubPending 待确认:豆瓣想看建的、设成要先确认的订阅,确认后才开始找。 MediaSubPending = "pending" // MediaSubDone 完成:电影入了库,或剧集这一季都入了库(开着洗版时要达到目标质量)。 MediaSubDone = "done" )
订阅的状态。
const ( MediaSubFromManual = "manual" MediaSubFromExplore = "explore" MediaSubFromDouban = "douban" MediaSubFromChatOps = "chatops" // MediaSubFromApp 是经 App API(M12)建的订阅 MediaSubFromApp = "app" )
订阅从哪里建的。
const ( MediaPrefPrefer = "prefer" MediaPrefRequire = "require" MediaPrefAvoid = "avoid" )
质量档案里「要不要」的取值:空串不限,prefer 优先,require 必须有,avoid 尽量不要(只用于 HDR)。
const ( MediaSubTorrentDownloading = "downloading" MediaSubTorrentDone = "done" MediaSubTorrentFailed = "failed" // MediaSubTorrentReplaced 是洗版换成更好的版本以后,旧的那个 MediaSubTorrentReplaced = "replaced" )
订阅下载的种子的状态。
const ( MediaUpgradeKeep = "keep" MediaUpgradeDelete = "delete" )
洗版以后旧种子怎么办。
const ( MediaDoubanSubscribed = "subscribed" MediaDoubanUnmatched = "unmatched" // MediaDoubanRemoved 是建的订阅被用户删掉了(不会再建回来) MediaDoubanRemoved = "removed" )
豆瓣想看里条目的处理结果。
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 = 14
当前数据库架构版本 每次添加新的迁移时递增此值
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 APIToken ¶
type APIToken struct {
ID uint `gorm:"primaryKey" json:"id"`
Name string `gorm:"size:64;not null;default:''" json:"name"`
// SecretHash 是 secret 的 SHA-256(十六进制)
SecretHash string `gorm:"size:64;not null;default:''" json:"-"`
// Scopes 是空格分隔的权限范围(app:read app:write 等)
Scopes string `gorm:"size:255;not null;default:''" json:"-"`
ExpiresAt *time.Time `json:"expires_at,omitempty"`
LastUsedAt *time.Time `json:"last_used_at,omitempty"`
CreatedBy string `gorm:"size:64;not null;default:''" json:"created_by"`
CreatedAt time.Time `json:"created_at"`
}
APIToken 是给 App、MCP 与 qB 兼容入口用的 API 令牌(路线图 M12)。令牌是 `ptt_<id>_<secret>`:明文只在新建时给一次, 库里只存 secret 的 SHA-256。撤销就是删掉这一行,立即生效。
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 AssistantConfirmation ¶
type AssistantConfirmation struct {
ID uint `gorm:"primaryKey"`
ConversationID uint `gorm:"not null;default:0;index"`
RunID string `gorm:"size:32;not null;default:''"`
ToolCallID string `gorm:"size:128;not null;default:''"`
ToolName string `gorm:"size:64;not null;default:''"`
// Arguments 是规范化脱敏以后的参数(JSON),确认后按它调用工具
Arguments string `gorm:"type:text;not null;default:''"`
Status string `gorm:"size:16;not null;default:'';index"`
// DecidedBy 是谁定的:属主,或者 timeout、cancel、restart、shutdown
DecidedBy string `gorm:"size:64;not null;default:''"`
DecidedAt *time.Time
ExpiresAt time.Time
CreatedAt time.Time
}
AssistantConfirmation 是一个等人确认的写操作。结论只经 WHERE status='pending' 的条件更新得出,改到一行的才算数。
func (AssistantConfirmation) TableName ¶
func (AssistantConfirmation) TableName() string
TableName 指定表名。
type AssistantConversation ¶
type AssistantConversation struct {
ID uint `gorm:"primaryKey"`
Owner string `gorm:"size:64;not null;default:'';index"`
Entry string `gorm:"size:16;not null;default:''"`
Title string `gorm:"size:128;not null;default:''"`
CreatedAt time.Time
UpdatedAt time.Time `gorm:"index"`
}
AssistantConversation 是一个会话。Owner 是带命名空间的属主(web:<用户名>、token:<编号>、device:<编号>、chatops:<绑定编号>), 查询一律按属主过滤。
func (AssistantConversation) TableName ¶
func (AssistantConversation) TableName() string
TableName 指定表名。
type AssistantMessage ¶
type AssistantMessage struct {
ID uint `gorm:"primaryKey"`
ConversationID uint `gorm:"not null;default:0;index"`
RunID string `gorm:"size:32;not null;default:''"`
Role string `gorm:"size:16;not null;default:''"`
Content string `gorm:"type:text;not null;default:''"`
// Reasoning 是模型的推理内容:只回传给模型(DeepSeek 等的思考模式带工具时要求回传),不给任何入口看
Reasoning string `gorm:"type:text;not null;default:''"`
// ToolCalls 是助手消息里的工具调用(JSON 数组:编号、工具名、规范化脱敏以后的参数)
ToolCalls string `gorm:"type:text;not null;default:''"`
ToolName string `gorm:"size:64;not null;default:''"`
ToolCallID string `gorm:"size:128;not null;default:''"`
IsError bool `gorm:"not null;default:false"`
CreatedAt time.Time
}
AssistantMessage 是会话里的一条消息,按 ID 排序。文字与工具参数都是脱敏以后的;工具结果来自 App API(本来就不带凭证)。
type AssistantSetting ¶
type AssistantSetting struct {
ID uint `gorm:"primaryKey"`
Enabled bool `gorm:"not null;default:false"`
// Provider 是界面上选的服务商预设(deepseek、openai、custom 等),只给界面用
Provider string `gorm:"size:32;not null;default:''"`
// BaseURL 是 OpenAI 兼容接口的地址(到 /chat/completions 之前)
BaseURL string `gorm:"size:512;not null;default:''"`
Model string `gorm:"size:128;not null;default:''"`
APIKeyEncrypted string `gorm:"type:text;not null;default:''"`
ProxyEncrypted string `gorm:"type:text;not null;default:''"`
// ChatOps 为真时,通知渠道里的非命令消息交给助手
ChatOps bool `gorm:"column:chat_ops;not null;default:false"`
MaxSteps int `gorm:"not null;default:0"`
// ConfirmMinutes 是待确认操作等几分钟
ConfirmMinutes int `gorm:"not null;default:0"`
// RetentionDays 是会话保留几天,0 表示不清理
RetentionDays int `gorm:"not null;default:0"`
UpdatedAt time.Time
}
AssistantSetting 是 AI 助手的设置,只有一行(ID 为 1);没有这一行时按默认值(关闭)。列的默认值一律是零值。
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 MediaCache ¶
type MediaCache struct {
Key string `gorm:"primaryKey;size:255" json:"key"`
Value string `gorm:"type:text;not null;default:''" json:"value"`
ExpiresAt time.Time `gorm:"index" json:"expires_at"`
}
MediaCache 是 TMDB 响应的缓存,到期后不再使用。
func (MediaCache) TableName ¶
func (MediaCache) TableName() string
type MediaDoubanItem ¶
type MediaDoubanItem struct {
ID uint `gorm:"primaryKey" json:"id"`
SourceID uint `gorm:"not null;uniqueIndex:idx_media_douban_item" json:"source_id"`
DoubanID string `gorm:"column:douban_id;size:16;not null;uniqueIndex:idx_media_douban_item" json:"douban_id"`
Title string `gorm:"size:255;not null;default:''" json:"title"`
Year int `gorm:"not null;default:0" json:"year"`
MediaType string `gorm:"size:8;not null;default:''" json:"media_type"`
TMDBID int `gorm:"column:tmdb_id;not null;default:0" json:"tmdb_id"`
SubscriptionID uint `gorm:"not null;default:0" json:"subscription_id"`
Status string `gorm:"size:16;not null;default:''" json:"status"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
}
MediaDoubanItem 是豆瓣想看里见过的条目:建过订阅的不再建(用户删掉订阅也不会再建回来), 没找到对应 TMDB 条目的也记下,不每次都去搜。
func (MediaDoubanItem) TableName ¶
func (MediaDoubanItem) TableName() string
type MediaDoubanSource ¶
type MediaDoubanSource struct {
ID uint `gorm:"primaryKey" json:"id"`
UserID string `gorm:"size:64;not null;default:'';uniqueIndex" json:"user_id"`
// Name 是界面上显示的名字(可以不填)
Name string `gorm:"size:64;not null;default:''" json:"name"`
Enabled bool `gorm:"not null;default:false" json:"enabled"`
// Confirm 为真时建出的订阅先是待确认
Confirm bool `gorm:"not null;default:false" json:"confirm"`
ProfileID uint `gorm:"not null;default:0" json:"profile_id"`
LastFetchAt *time.Time `json:"last_fetch_at,omitempty"`
NextFetchAt *time.Time `gorm:"index" json:"next_fetch_at,omitempty"`
// Failures 是连续失败的次数;到 3 次标成异常,并发一次通知(Notified 记下发过了)
Failures int `gorm:"not null;default:0" json:"failures"`
LastError string `gorm:"size:1024;not null;default:''" json:"last_error"`
Abnormal bool `gorm:"not null;default:false" json:"abnormal"`
Notified bool `gorm:"not null;default:false" json:"-"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
}
MediaDoubanSource 是一个豆瓣用户的想看:定时拉取公开的 RSS,给「想看」的电影与剧集建订阅。
func (MediaDoubanSource) TableName ¶
func (MediaDoubanSource) TableName() string
type MediaLibrary ¶
type MediaLibrary struct {
ID uint `gorm:"primaryKey" json:"id"`
Name string `gorm:"size:64;not null;default:'';uniqueIndex" json:"name"`
Kind string `gorm:"size:8;not null;default:''" json:"kind"`
// Anime 为真时只收 TMDB 类型里有「动画」的条目;同类型里没有这种库时,动画也进普通的库
Anime bool `gorm:"not null;default:false" json:"anime"`
// Path 是 pt-tools 里看到的库目录(绝对路径)
Path string `gorm:"size:1024;not null;default:''" json:"path"`
// Template 是命名模板(text/template,不写扩展名);空串用默认模板
Template string `gorm:"size:1024;not null;default:''" json:"template"`
Mode string `gorm:"size:16;not null;default:''" json:"mode"`
Scrape bool `gorm:"not null;default:false" json:"scrape"`
ScrapeOverwrite bool `gorm:"not null;default:false" json:"scrape_overwrite"`
// ScrapeItems 是刮削要写的内容(逗号分隔,见 scrape.AllItems);空串是默认的那几项(Logo 以外都写)
ScrapeItems string `gorm:"size:128;not null;default:''" json:"-"`
// ScrapeImageLang 是海报与 Logo 优先用的语言:空串用 TMDB 给的那张;zh、en、ja;none 是没有文字的
ScrapeImageLang string `gorm:"size:8;not null;default:''" json:"scrape_image_lang"`
// ScrapeSource 是 NFO 里简介与评分的来源:空串用 TMDB 的;douban 用豆瓣的(找不到时用 TMDB 的)
ScrapeSource string `gorm:"size:16;not null;default:''" json:"scrape_source"`
// ClassifyDir 为真时按二级分类(MediaOrganizeSetting.ClassifyRules)放进库目录下的分类目录
ClassifyDir bool `gorm:"not null;default:false" json:"classify_dir"`
// OverwriteMode 是目标位置已经有 pt-tools 之前放进库的同一部(同一集)的旧版本时怎么办:空串不替换,larger 新文件更大时替换
OverwriteMode string `gorm:"size:16;not null;default:''" json:"overwrite_mode"`
Enabled bool `gorm:"not null;default:false" json:"enabled"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
}
MediaLibrary 是一个媒体库:一类条目(电影或剧集,可以只收动画)整理到哪个目录、怎么命名、怎么整理、要不要刮削。 列的默认值一律是零值(GORM 新建时会把零值换成 default)。
func (MediaLibrary) TableName ¶
func (MediaLibrary) TableName() string
type MediaOrganizeSetting ¶
type MediaOrganizeSetting struct {
ID uint `gorm:"primaryKey" json:"id"`
// AutoEnabled:pt-tools 推送的种子下载完成后自动整理。AutoSince 是打开的时间,只整理之后完成的种子
AutoEnabled bool `gorm:"not null;default:false" json:"auto_enabled"`
AutoSince *time.Time `json:"auto_since,omitempty"`
// ScanEnabled:按范围定期扫描下载器里已完成的种子(不是 pt-tools 推送的也整理)
ScanEnabled bool `gorm:"not null;default:false" json:"scan_enabled"`
ScanIntervalMin int `gorm:"not null;default:0" json:"scan_interval_min"`
// 范围:下载器 ID(JSON 数组)、分类与标签(逗号分隔)、保存路径前缀(换行分隔);空的一项不限制
ScopeDownloaders string `gorm:"type:text;not null;default:''" json:"-"`
ScopeCategories string `gorm:"size:1024;not null;default:''" json:"-"`
ScopeTags string `gorm:"size:1024;not null;default:''" json:"-"`
ScopeSavePaths string `gorm:"type:text;not null;default:''" json:"-"`
// MinVideoMB 是视频文件的最小体积(MB),更小的当作样片跳过;0 用默认值
MinVideoMB int `gorm:"not null;default:0" json:"min_video_mb"`
// NotifyChannels 是入库通知发往的通道 ID(JSON 数组);空的不通知
NotifyChannels string `gorm:"type:text;not null;default:''" json:"-"`
// DeleteLinksOnRemove:种子连数据一起删掉后,把从它整理出的硬链接与软链接也删掉(复制的文件不删)
DeleteLinksOnRemove bool `gorm:"not null;default:false" json:"delete_links_on_remove"`
// WatchIntervalMin 是目录监控扫描的间隔(分钟);0 用默认值
WatchIntervalMin int `gorm:"not null;default:0" json:"watch_interval_min"`
// ClassifyRules 是二级分类的规则(JSON,见 organize.ClassifyRules);空串是没有规则
ClassifyRules string `gorm:"type:text;not null;default:''" json:"-"`
UpdatedAt time.Time `json:"updated_at"`
}
MediaOrganizeSetting 是整理入库的设置(只有一行,ID 为 1)。
func (MediaOrganizeSetting) TableName ¶
func (MediaOrganizeSetting) TableName() string
type MediaOverride ¶
type MediaOverride struct {
ID uint `gorm:"primaryKey" json:"id"`
Key string `gorm:"size:255;not null;uniqueIndex" json:"key"`
// AltKey 是用中文名算出的别名(有英文名时 Key 用英文名):副标题里有没有中文名都能命中
AltKey string `gorm:"size:255;not null;default:'';index" json:"alt_key"`
Label string `gorm:"size:255;not null;default:''" json:"label"`
TMDBID int `gorm:"column:tmdb_id;not null;default:0" json:"tmdb_id"`
MediaType string `gorm:"size:8;not null;default:''" json:"media_type"`
Title string `gorm:"size:255;not null;default:''" json:"title"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
}
MediaOverride 是手动纠正:解析结果相同(类型、名字,电影另加年份)的标题固定识别成这个 TMDB 条目。
func (MediaOverride) TableName ¶
func (MediaOverride) TableName() string
type MediaPathMap ¶
type MediaPathMap struct {
ID uint `gorm:"primaryKey" json:"id"`
DownloaderID uint `gorm:"not null;uniqueIndex:idx_media_path_map" json:"downloader_id"`
DownloaderPrefix string `gorm:"size:512;not null;uniqueIndex:idx_media_path_map" json:"downloader_prefix"`
LocalPrefix string `gorm:"size:512;not null;default:''" json:"local_prefix"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
}
MediaPathMap 把下载器里看到的路径换成 pt-tools 里看到的路径(pt-tools 在容器里时两边的挂载点不同)。 换算时取最长的匹配前缀;没有匹配时路径不变。
func (MediaPathMap) TableName ¶
func (MediaPathMap) TableName() string
type MediaQualityProfile ¶
type MediaQualityProfile struct {
ID uint `gorm:"primaryKey" json:"id"`
Name string `gorm:"size:64;not null;default:'';uniqueIndex" json:"name"`
Resolutions string `gorm:"type:text;not null;default:''" json:"-"`
Sources string `gorm:"type:text;not null;default:''" json:"-"`
Codecs string `gorm:"type:text;not null;default:''" json:"-"`
// Remux、HDR、ChineseSubs、Free 是空串 / prefer / require(HDR 还有 avoid)
Remux string `gorm:"size:16;not null;default:''" json:"remux"`
HDR string `gorm:"column:hdr;size:16;not null;default:''" json:"hdr"`
ChineseSubs string `gorm:"size:16;not null;default:''" json:"chinese_subs"`
Free string `gorm:"size:16;not null;default:''" json:"free"`
// Groups 是偏好的制作组(JSON 数组)
Groups string `gorm:"type:text;not null;default:''" json:"-"`
// MinSizeGB、MaxSizeGB 是体积区间(0 不限):电影按整部算,剧集按每集算
MinSizeGB float64 `gorm:"not null;default:0" json:"min_size_gb"`
MaxSizeGB float64 `gorm:"not null;default:0" json:"max_size_gb"`
MinSeeders int `gorm:"not null;default:0" json:"min_seeders"`
ExcludeHR bool `gorm:"column:exclude_hr;not null;default:false" json:"exclude_hr"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
}
MediaQualityProfile 是质量档案:订阅按它挑资源、打分。列表字段是 JSON 数组,按偏好从高到低排,空数组不限; 取值用 internal/media/meta 解析出的写法(2160p、BluRay、WEB-DL、H.265 等)。
func (MediaQualityProfile) TableName ¶
func (MediaQualityProfile) TableName() string
type MediaReplaceJournal ¶
type MediaReplaceJournal struct {
ID uint `gorm:"primaryKey"`
// OldID 是被换掉的整理记录
OldID uint `gorm:"not null;default:0"`
// Source 与 Mode 是新文件的源文件与整理方式
Source string `gorm:"size:2048;not null;default:''"`
Mode string `gorm:"size:16;not null;default:''"`
Target string `gorm:"size:2048;not null;default:''"`
Temp string `gorm:"size:2048;not null;default:''"`
// TempID 是放好的临时文件的文件编号(新文件放到 Target 以后还是它)
TempID string `gorm:"size:64;not null;default:''"`
Backup string `gorm:"size:2048;not null;default:''"`
// BackupID 是挪到 Backup 的旧文件的文件编号(确认过是旧记录放的那个以后记下),收尾时只删编号还对得上的
BackupID string `gorm:"size:64;not null;default:''"`
// Subs 是新文件的字幕(JSON 数组,每项 source、target):旧字幕删掉以后才放,收尾时放好并记进新记录
Subs string `gorm:"type:text;not null;default:''"`
Committed bool `gorm:"not null;default:false"`
CreatedAt time.Time `json:"created_at"`
}
MediaReplaceJournal 是一次进行中的「同名文件替换」(覆盖策略):新文件先放在 Temp,旧文件挪到 Backup, 新文件放到 Target 以后与两条整理记录在同一个事务里写好并标成 Committed,收尾删掉 Backup 后删掉这一行。 中途 pt-tools 退出了,下次启动时按它恢复:没写好记录的撤回(旧文件放回原处),写好了的收尾。
func (MediaReplaceJournal) TableName ¶
func (MediaReplaceJournal) TableName() string
type MediaServer ¶
type MediaServer struct {
ID uint `gorm:"primaryKey" json:"id"`
Name string `gorm:"size:64;not null;default:'';uniqueIndex" json:"name"`
Kind string `gorm:"size:16;not null;default:''" json:"kind"`
URL string `gorm:"size:512;not null;default:''" json:"url"`
TokenEncrypted string `gorm:"type:text;not null;default:''" json:"-"`
Enabled bool `gorm:"not null;default:false" json:"enabled"`
RefreshMode string `gorm:"size:16;not null;default:''" json:"refresh_mode"`
LocalPrefix string `gorm:"size:512;not null;default:''" json:"local_prefix"`
ServerPrefix string `gorm:"size:512;not null;default:''" json:"server_prefix"`
LastError string `gorm:"size:1024;not null;default:''" json:"last_error"`
LastRefreshAt *time.Time `json:"last_refresh_at,omitempty"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
}
MediaServer 是整理完后要通知的媒体服务器。Token(Emby、Jellyfin 的 API Key 或 Plex 的 Token)加密保存、只写不读。 LocalPrefix → ServerPrefix 把 pt-tools 里的路径换成媒体服务器里看到的路径,两边一样时都留空。
func (MediaServer) TableName ¶
func (MediaServer) TableName() string
type MediaSetting ¶
type MediaSetting struct {
ID uint `gorm:"primaryKey" json:"id"`
TMDBKeyEncrypted string `gorm:"type:text;default:''" json:"-"`
Language string `gorm:"size:16;default:''" json:"language"`
ProxyEncrypted string `gorm:"type:text;default:''" json:"-"`
// APIBaseURL、ImageBaseURL 是换掉的 TMDB 接口地址与图片地址(镜像或自建中转),空 = 官方地址
APIBaseURL string `gorm:"size:512;default:''" json:"api_base_url"`
ImageBaseURL string `gorm:"size:512;default:''" json:"image_base_url"`
UpdatedAt time.Time `json:"updated_at"`
}
MediaSetting 是媒体识别的设置(只有一行,ID 为 1)。TMDB 的 API Key 加密保存、只写不读; 代理地址可能带用户名密码,也加密保存,为空时用环境变量里的代理(与站点请求相同)。
func (MediaSetting) TableName ¶
func (MediaSetting) TableName() string
type MediaSubscribeSetting ¶
type MediaSubscribeSetting struct {
ID uint `gorm:"primaryKey" json:"-"`
// Enabled 是总开关:关掉时不搜索、不接 RSS、不拉豆瓣
Enabled bool `gorm:"not null;default:false" json:"enabled"`
// SearchIntervalHours 是每个订阅主动搜索的间隔(最少 6 小时),每次另加最多 30 分钟的随机偏移
SearchIntervalHours int `gorm:"not null;default:0" json:"search_interval_hours"`
// SearchSkipSites 是不参与主动搜索的站点(JSON 数组;RSS 里的种子照样对)
SearchSkipSites string `gorm:"type:text;not null;default:''" json:"-"`
DefaultProfileID uint `gorm:"not null;default:0" json:"default_profile_id"`
DefaultDownloaderID uint `gorm:"not null;default:0" json:"default_downloader_id"`
// NotifyChannels 是下载了订阅的资源时发通知的通道(JSON 数组)
NotifyChannels string `gorm:"type:text;not null;default:''" json:"-"`
// UpgradeOld 是洗版以后旧种子怎么办:keep(空串也是)继续做种,delete 连数据删掉
UpgradeOld string `gorm:"size:16;not null;default:''" json:"upgrade_old"`
UpdatedAt time.Time `json:"updated_at"`
}
MediaSubscribeSetting 是订阅的设置,只有一行(ID 为 1)。
func (MediaSubscribeSetting) TableName ¶
func (MediaSubscribeSetting) TableName() string
type MediaSubscription ¶
type MediaSubscription struct {
ID uint `gorm:"primaryKey" json:"id"`
MediaType string `gorm:"size:8;not null;default:'';uniqueIndex:idx_media_sub" json:"media_type"`
TMDBID int `gorm:"column:tmdb_id;not null;default:0;uniqueIndex:idx_media_sub" json:"tmdb_id"`
Season int `gorm:"not null;default:0;uniqueIndex:idx_media_sub" json:"season"`
Title string `gorm:"size:255;not null;default:''" json:"title"`
OriginalTitle string `gorm:"size:255;not null;default:''" json:"original_title"`
Year int `gorm:"not null;default:0" json:"year"`
// Aliases 是对种子标题时用的其他名字(JSON 数组:英文名与 TMDB 别名)
Aliases string `gorm:"type:text;not null;default:''" json:"-"`
IMDbID string `gorm:"column:imdb_id;size:16;not null;default:''" json:"imdb_id"`
PosterPath string `gorm:"size:255;not null;default:''" json:"poster_path"`
// ProfileID 为 0 时用设置里的默认档案
ProfileID uint `gorm:"not null;default:0" json:"profile_id"`
// Sites 是只在这些站点找(JSON 数组,空 = 所有启用的站点)
Sites string `gorm:"type:text;not null;default:''" json:"-"`
// DownloaderID 为 0 时用设置里的默认下载器,再没有时用 pt-tools 的默认下载器
DownloaderID uint `gorm:"not null;default:0" json:"downloader_id"`
Category string `gorm:"size:128;not null;default:''" json:"category"`
Tags string `gorm:"size:255;not null;default:''" json:"tags"`
SavePath string `gorm:"size:1024;not null;default:''" json:"save_path"`
Status string `gorm:"size:16;not null;default:'';index" json:"status"`
// Upgrade 是洗版:下载过以后还接着找分数更高的,档案里排第一的分辨率与来源都达到才停
Upgrade bool `gorm:"not null;default:false" json:"upgrade"`
Source string `gorm:"size:16;not null;default:''" json:"source"`
DoubanID string `gorm:"column:douban_id;size:16;not null;default:''" json:"douban_id"`
// TotalEpisodes 是这一季的集数(来自 TMDB),电影为 0
TotalEpisodes int `gorm:"not null;default:0" json:"total_episodes"`
LastSearchAt *time.Time `json:"last_search_at,omitempty"`
NextSearchAt *time.Time `gorm:"index" json:"next_search_at,omitempty"`
// Message 是最近一次搜索或下载的结果说明
Message string `gorm:"size:1024;not null;default:''" json:"message"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
}
MediaSubscription 是一个订阅:一部电影,或剧集的一季。同一个条目的同一季只有一个订阅。
func (MediaSubscription) TableName ¶
func (MediaSubscription) TableName() string
type MediaSubscriptionTorrent ¶
type MediaSubscriptionTorrent struct {
ID uint `gorm:"primaryKey" json:"id"`
SubscriptionID uint `gorm:"not null;uniqueIndex:idx_media_sub_torrent" json:"subscription_id"`
SiteName string `gorm:"size:64;not null;uniqueIndex:idx_media_sub_torrent" json:"site_name"`
TorrentID string `gorm:"size:128;not null;uniqueIndex:idx_media_sub_torrent" json:"torrent_id"`
InfoHash string `gorm:"size:64;not null;default:'';index" json:"info_hash"`
Title string `gorm:"size:512;not null;default:''" json:"title"`
// Subtitle 是站点上的副标题:洗版时按现在的档案重算分数要用(中字写在副标题里)
Subtitle string `gorm:"size:512;not null;default:''" json:"subtitle"`
// Score 是推送时按当时的档案打的分(档案改过以后比较版本时重算,不用这个)
Score int `gorm:"not null;default:0" json:"score"`
// Episode、EpisodeEnd 是种子里的集(剧集,单集时 EpisodeEnd 为 0);整季包 Complete 为真
Episode int `gorm:"not null;default:0" json:"episode"`
EpisodeEnd int `gorm:"not null;default:0" json:"episode_end"`
Complete bool `gorm:"not null;default:false" json:"complete"`
SizeBytes int64 `gorm:"not null;default:0" json:"size_bytes"`
DownloaderID uint `gorm:"not null;default:0" json:"downloader_id"`
// HasHR 是推送时知道的 H&R 要求(站点整站有,或者这个种子有):洗版删旧种子时留着做种
HasHR bool `gorm:"not null;default:false" json:"has_hr"`
// Adopted 是推送时下载器里已经有这个种子(不是订阅加进去的):洗版时不删
Adopted bool `gorm:"not null;default:false" json:"adopted"`
Status string `gorm:"size:16;not null;default:'';index" json:"status"`
Message string `gorm:"size:1024;not null;default:''" json:"message"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
}
MediaSubscriptionTorrent 是订阅下载的一个种子:同一个订阅里同一个站点的同一个种子只记一次。
func (MediaSubscriptionTorrent) TableName ¶
func (MediaSubscriptionTorrent) TableName() string
type MediaTransferHistory ¶
type MediaTransferHistory struct {
ID uint `gorm:"primaryKey" json:"id"`
DownloaderID uint `gorm:"not null;default:0;index" json:"downloader_id"`
DownloaderName string `gorm:"size:64;not null;default:''" json:"downloader_name"`
// WatchDirID 是目录监控的目录(MediaWatchDir):不为 0 时这条不是下载器里的种子,DownloaderID 为 0,TorrentName 是目录下那一项的名字
WatchDirID uint `gorm:"not null;default:0;index" json:"watch_dir_id"`
InfoHash string `gorm:"size:64;not null;default:'';index" json:"info_hash"`
TaskID string `gorm:"size:128;not null;default:''" json:"task_id"`
TorrentName string `gorm:"size:512;not null;default:''" json:"torrent_name"`
LibraryID uint `gorm:"not null;default:0;index" json:"library_id"`
SourcePath string `gorm:"size:2048;not null;uniqueIndex" json:"source_path"`
// SaveRoot 是整理时种子保存目录在 pt-tools 里的路径:清理入库链接前确认它还在(下载目录没挂载时不清理)
SaveRoot string `gorm:"size:2048;not null;default:''" json:"-"`
TargetPath string `gorm:"size:2048;not null;default:''" json:"target_path"`
// Extras 是一起整理的字幕与刮削写的文件(JSON 数组,带文件编号):删除库里的文件时只删这些
Extras string `gorm:"type:text;not null;default:''" json:"-"`
Mode string `gorm:"size:16;not null;default:''" json:"mode"`
MediaType string `gorm:"size:8;not null;default:''" json:"media_type"`
TMDBID int `gorm:"column:tmdb_id;not null;default:0" json:"tmdb_id"`
Title string `gorm:"size:255;not null;default:''" json:"title"`
Year int `gorm:"not null;default:0" json:"year"`
Season int `gorm:"not null;default:0" json:"season"`
Episode int `gorm:"not null;default:0" json:"episode"`
EpisodeEnd int `gorm:"not null;default:0" json:"episode_end"`
Size int64 `gorm:"not null;default:0" json:"size"`
Status string `gorm:"size:16;not null;default:'';index" json:"status"`
Message string `gorm:"size:1024;not null;default:''" json:"message"`
Attempts int `gorm:"not null;default:0" json:"attempts"`
// NextRetryAt 是失败后下次自动重试的时间;为空的不自动重试(例如没识别出来,要先纠正)
NextRetryAt *time.Time `gorm:"index" json:"next_retry_at,omitempty"`
// TargetFileID 是整理出的文件的设备号与 inode(Windows 是卷序列号与文件索引),删除库里的文件前用它确认还是这个文件
TargetFileID string `gorm:"size:64;not null;default:''" json:"-"`
// SourceFileID 是整理时源文件的编号(同 TargetFileID 的格式):目录监控按它认同一个位置上是不是换成了另一个文件。
// 下载器的种子不记(种子按 info hash 认)
SourceFileID string `gorm:"size:64;not null;default:''" json:"-"`
Trigger string `gorm:"size:16;not null;default:''" json:"trigger"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
}
MediaTransferHistory 是一个视频文件的整理记录。源文件(pt-tools 里的路径)唯一:同一个文件只整理一次, 同一事件重复到达或几种触发方式碰到一起都不会重复整理。字幕跟着视频一起整理,目标路径记在 Extras 里。
func (MediaTransferHistory) TableName ¶
func (MediaTransferHistory) TableName() string
type MediaWatchDir ¶
type MediaWatchDir struct {
ID uint `gorm:"primaryKey" json:"id"`
// Path 是 pt-tools 里看到的目录(绝对路径)
Path string `gorm:"size:1024;not null;uniqueIndex" json:"path"`
Enabled bool `gorm:"not null;default:false" json:"enabled"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
}
MediaWatchDir 是监控的目录:放进来的视频(不是下载器里的种子,例如手动拷进来、别的工具下载的)按媒体库整理。 目录下的每一项(一个文件,或一个文件夹)当作一个种子:名字用来识别,里面的视频按媒体库的方式整理。
func (MediaWatchDir) TableName ¶
func (MediaWatchDir) TableName() string
type MediaWordRule ¶
type MediaWordRule struct {
ID uint `gorm:"primaryKey" json:"id"`
Kind string `gorm:"size:16;not null;default:''" json:"kind"`
Pattern string `gorm:"size:256;not null;default:''" json:"pattern"`
Replacement string `gorm:"size:256;not null;default:''" json:"replacement"`
Offset int `gorm:"not null;default:0" json:"offset"`
IsRegex bool `gorm:"not null;default:false" json:"is_regex"`
Enabled bool `gorm:"not null;default:false" json:"enabled"`
Note string `gorm:"size:256;not null;default:''" json:"note"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
}
MediaWordRule 是识别词:解析标题之前按顺序套用(集数偏移在解析之后加上)。列的默认值一律是零值。
func (MediaWordRule) TableName ¶
func (MediaWordRule) TableName() string
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 NotificationTemplate ¶
type NotificationTemplate struct {
EventType string `gorm:"primaryKey;size:64" json:"event_type"`
Title string `gorm:"type:text;not null;default:''" json:"title"`
Text string `gorm:"type:text;not null;default:''" json:"text"`
UpdatedAt time.Time `json:"updated_at"`
}
NotificationTemplate 是一种事件的全局消息模板(Go 模板,所有通知通道共用)。 Title、Text 空着的一项用内置文字;某种事件没有这一行就全用内置文字。
func (NotificationTemplate) TableName ¶
func (NotificationTemplate) TableName() string
TableName 指定表名。
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 QbitCompatSetting ¶
type QbitCompatSetting struct {
ID uint `gorm:"primaryKey" json:"-"`
// DownloaderID 是兼容入口背后的下载器;0 表示默认下载器
DownloaderID uint `gorm:"not null;default:0" json:"downloader_id"`
// FullControl 打开后,写接口能动下载器里的全部种子;关着时只动经兼容入口加的
FullControl bool `gorm:"not null;default:false" json:"full_control"`
// ListenAddr 是在网页上设的监听地址(host:port);空串是不开。启动参数 --qbit-compat-addr 或环境变量
// PT_QBIT_COMPAT_ADDR 给了地址时用那个,这里的不管用
ListenAddr string `gorm:"size:128;not null;default:''" json:"listen_addr"`
// Categories 是客户端用 createCategory 建的分类(JSON:名字 → 保存目录);加种子时没给目录就用它
Categories string `gorm:"type:text;not null;default:''" json:"-"`
// Tags 是客户端用 createTags 建的标签(JSON 数组)
Tags string `gorm:"type:text;not null;default:''" json:"-"`
UpdatedAt time.Time `json:"updated_at"`
}
QbitCompatSetting 是 qB 兼容入口的设置(只有 ID 1 一行,路线图 M13)。监听地址不在这里:它是启动参数。
func (QbitCompatSetting) TableName ¶
func (QbitCompatSetting) TableName() string
type QbitCompatTorrent ¶
type QbitCompatTorrent struct {
ID uint `gorm:"primaryKey"`
DownloaderID uint `gorm:"not null;uniqueIndex:idx_qbit_compat_owner"`
InfoHash string `gorm:"size:64;not null;uniqueIndex:idx_qbit_compat_owner"`
AddedAt int64 `gorm:"not null;default:0"`
CreatedAt time.Time `gorm:"not null"`
}
QbitCompatTorrent 记下经 qB 兼容入口加进下载器的种子:没打开完全控制时,写接口只动这些。 只在种子确实加进下载器(不是原来就在)以后才记,经兼容入口删掉时一起删。 AddedAt 是加完以后在下载器里看到它时、下载器给的添加时间:只认添加时间一样的那一个(删掉以后从别处加回来的时间不一样)。 加完以后看不到它、或者下载器不给添加时间时不记这一条。
func (QbitCompatTorrent) TableName ¶
func (QbitCompatTorrent) TableName() string
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 RemoteDevice ¶
type RemoteDevice struct {
ID uint `gorm:"primaryKey"`
Name string `gorm:"size:64;not null;default:''"`
// PublicKey 是设备的 X25519 公钥(base64url);同一把公钥同时只能有一台没撤销的设备
PublicKey string `gorm:"size:64;not null;default:'';index"`
// Scopes 是空格分隔的权限范围(app:read,或 app:read app:write)
Scopes string `gorm:"size:64;not null;default:''"`
CreatedAt time.Time
LastSeenAt *time.Time
LastSeenVia string `gorm:"size:16;not null;default:''"`
RevokedAt *time.Time `gorm:"index"`
}
RemoteDevice 是配对过的设备。撤销只写 RevokedAt,记录留着(审计里的设备编号还对得上),撤销以后才能删掉记录。
type RemoteSetting ¶
type RemoteSetting struct {
ID uint `gorm:"primaryKey"`
Enabled bool `gorm:"not null;default:false"`
// RelaysJSON 是 relay 地址(ws:// 或 wss://)的 JSON 数组
RelaysJSON string `gorm:"type:text;default:''"`
// DirectURL 是 App 直连这台 pt-tools 用的地址(http:// 或 https://,可以带反向代理的子路径),空 = 配对链接里不带
DirectURL string `gorm:"size:512;default:''"`
// RelayDisabled 为真时不用任何 relay(只直连)。为假而 RelaysJSON 为空时用构建时内置的托管 relay
RelayDisabled bool `gorm:"not null;default:false"`
// HostKeysEncrypted 是加密后的主机密钥(Ed25519 与 X25519 的私钥)。第一次打开远程访问时生成,轮换时整个换掉
HostKeysEncrypted string `gorm:"type:text;default:''"`
UpdatedAt time.Time
}
RemoteSetting 是远程访问(路线图 M15)的设置,只有一行(ID 为 1)。默认关闭;列的默认值一律是零值。
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"`
HRSeedTimeH int `json:"hr_seed_time_h"`
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)
// HRSeedTimeH 是用户填的 H&R 做种要求(小时):站点定义里没有 H&R 做种时长时用它(#727),0=未填
HRSeedTimeH int `gorm:"default:0" json:"hr_seed_time_h"`
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
// PushedFilterRuleID 是把这个种子推进下载器的 RSS 过滤规则(推送时记下,之后不改)。FilterRuleID 是 RSS 最近一次判断命中的
// 规则,每轮刷新;规则命中数按它统计已推送的种子(「这条规则真的下过几个」)
PushedFilterRuleID *uint `gorm:"default:null" json:"pushedFilterRuleId"`
// 免费结束管理相关字段
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"`
// IMDbID、DoubanID 是站点给的外部编号(详情页或接口里有时才有),媒体识别优先用它们
IMDbID string `gorm:"column:imdb_id;size:16;default:''" json:"imdbId"`
DoubanID string `gorm:"column:douban_id;size:16;default:''" json:"doubanId"`
// 免费资格(docs/design/free-expiry-safety.md):每次读到站点详情都按规范快照整套写入。
// FreeValidity 是 not_free / free_until / free_permanent / unknown;空串是还没按新规则验证过的旧记录。
FreeValidity string `gorm:"size:16;default:''" json:"freeValidity"`
FreeVerifiedAt *time.Time `gorm:"default:null" json:"freeVerifiedAt"` // 最近一次成功读到资格的时间
FreeStatusSource string `gorm:"size:32;default:''" json:"freeStatusSource"` // base / promotion_rule / mall_single_free / adapter / legacy
FreeStatusError string `gorm:"size:256;default:''" json:"freeStatusError"` // 读取资格时的问题(结束时间无法解析等),不含原始响应
// DetailID 是取站点详情用的种子编号(从 RSS 条目链接里取,不含密钥);推送前重新验证资格时用
DetailID string `gorm:"size:64;default:''" json:"detailId"`
// SourceRSSID 是这个种子的所有者 RSS:第一次决定下载(进入暂存)的那条。其他 RSS 不改它的策略字段,也不处理它的暂存文件
SourceRSSID *uint `gorm:"column:source_rss_id;index" json:"sourceRssId"`
// RequireFree 是入场是否以免费为前提(免费通道、要求免费的过滤规则、要求免费的订阅与刷流)
RequireFree bool `gorm:"default:false" json:"requireFree"`
// 免费结束暂停的执行记录:计划时间(结束时间减提前量)、实际发出请求的时间;确认暂停的时间是 PausedAt。
PausePlannedAt *time.Time `gorm:"default:null" json:"pausePlannedAt"`
PauseRequestedAt *time.Time `gorm:"default:null" json:"pauseRequestedAt"`
// FreeEndFailures 是到期处理连续失败的次数(与推送重试的 RetryCount 分开);FreeEndAlertedAt 是已经告警的时间
FreeEndFailures int `gorm:"default:0" json:"freeEndFailures"`
FreeEndAlertedAt *time.Time `gorm:"default:null" json:"freeEndAlertedAt"`
// PushPendingAt 是承诺到期暂停的推送在加入下载器之前写下的标记:加入后补记账成功才清掉。
// 还留着标记说明加入后记账失败了,对账时按下载器与哈希找回任务、补记账(任务保持暂停,不自动开始)
PushPendingAt *time.Time `gorm:"default:null" json:"pushPendingAt"`
// FreeEndedAt 是已推送、原来免费的种子后来读到「不免费」时记下的免费结束时间(不晚于读到的时间)。
// 刷新资格会把 is_free、free_end_time 改成当前事实;自动删种的「免费到期未完成删除」靠它认出免费已经结束
FreeEndedAt *time.Time `gorm:"default:null" json:"freeEndedAt"`
}
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"`
PushedFilterRuleID *uint `json:"pushedFilterRuleId"`
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"`
IMDbID string `gorm:"column:imdb_id;size:16;default:''" json:"imdbId"`
DoubanID string `gorm:"column:douban_id;size:16;default:''" json:"doubanId"`
// 免费资格、归属与暂停记录:与 TorrentInfo 同名的列,归档时原样复制
FreeValidity string `gorm:"size:16;default:''" json:"freeValidity"`
FreeVerifiedAt *time.Time `json:"freeVerifiedAt"`
FreeStatusSource string `gorm:"size:32;default:''" json:"freeStatusSource"`
FreeStatusError string `gorm:"size:256;default:''" json:"freeStatusError"`
SourceRSSID *uint `gorm:"column:source_rss_id" json:"sourceRssId"`
RequireFree bool `json:"requireFree"`
PausePlannedAt *time.Time `json:"pausePlannedAt"`
PauseRequestedAt *time.Time `json:"pauseRequestedAt"`
FreeEndFailures int `json:"freeEndFailures"`
FreeEndAlertedAt *time.Time `json:"freeEndAlertedAt"`
DetailID string `gorm:"size:64;default:''" json:"detailId"`
PushPendingAt *time.Time `json:"pushPendingAt"`
FreeEndedAt *time.Time `json:"freeEndedAt"`
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
¶
- api_token.go
- assistant.go
- brush.go
- chatops_models.go
- config_models.go
- cookiecloud.go
- enter.go
- filter_rule.go
- free_level.go
- init.go
- media.go
- media_library.go
- media_subscribe.go
- migration_state.go
- monitor_notification_log.go
- notification_template.go
- php_torrent.go
- presets.go
- qbit_compat.go
- rate_limit.go
- remote.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