Documentation
¶
Index ¶
- Constants
- Variables
- func ActiveBackupKey() backup.ActiveKey
- func BackupDataDir(ctx context.Context, output string, includeSecret *bool) (backup.Info, error)
- func CancelRestore() error
- func CloseDB(db *models.TorrentDB)
- func CurrentBackupKey() (backup.Key, error)
- func DataDir() (string, error)
- func EnablePendingRestore()
- func GetLogger() *zap.Logger
- func InitRuntime() (*zap.Logger, error)
- func MissingCredential(authMethod, cookie, apiKey, passkey string) string
- func NewTempDBDir(dir string) (*models.TorrentDB, error)
- func NormalizeDailyReportScope(v string) string
- func OpenTestDB(t TB) (*models.TorrentDB, error)
- func OpenTestDBIn(t TB, dir string) (*models.TorrentDB, error)
- func PendingRestore() (*backup.Pending, error)
- func SetV2Broadcaster(b V2Broadcaster)
- func StageRestore(src, name string) (backup.Pending, error)
- func ValidateAttendanceWindow(start, end string) error
- func ValidateDailyReportTime(v string) error
- func ValidateVisionModel(model string) error
- type BackupResult
- type BackupSettings
- type BackupSettingsInput
- type CloakConfigSnapshot
- type ConfigStore
- func (s *ConfigStore) AdminCount() (int64, error)
- func (s *ConfigStore) AppendRSSToSite(siteName string, entry models.RSSConfig) (models.RSSConfig, error)
- func (s *ConfigStore) AttendanceAI() (bool, string, error)
- func (s *ConfigStore) AttendanceNotify() (bool, []uint, error)
- func (s *ConfigStore) AttendanceWindow() (string, string, error)
- func (s *ConfigStore) BackupFile(name string) (string, error)
- func (s *ConfigStore) BackupSettings() (BackupSettings, error)
- func (s *ConfigStore) DailyReportOffset(randN func(n int64) int64) (time.Duration, error)
- func (s *ConfigStore) DailyReportSettings() (DailyReportSettings, error)
- func (s *ConfigStore) DeadTorrentScanSettings() (DeadTorrentScanSettings, error)
- func (s *ConfigStore) DecryptCookie(cipherText string) (string, error)
- func (s *ConfigStore) DeleteBackup(name string) error
- func (s *ConfigStore) DeleteRSSFromSite(siteName string, rssID uint) (models.RSSConfig, error)
- func (s *ConfigStore) DeleteSite(name string) error
- func (s *ConfigStore) EnabledRSS() ([]models.RSSConfig, error)
- func (s *ConfigStore) EnabledSiteNames() (map[string]bool, error)
- func (s *ConfigStore) EncryptCookie(plain string) (string, error)
- func (s *ConfigStore) EnsureAdmin(username, passwordHash string) error
- func (s *ConfigStore) GetAdmin(username string) (*models.AdminUser, error)
- func (s *ConfigStore) GetCloakConfig() (CloakConfigSnapshot, error)
- func (s *ConfigStore) GetCloakEndpoint() (string, error)
- func (s *ConfigStore) GetCloakToken() (string, error)
- func (s *ConfigStore) GetGlobalOnly() (models.SettingsGlobal, error)
- func (s *ConfigStore) GetGlobalSettings() (models.SettingsGlobal, error)
- func (s *ConfigStore) GetQbitOnly() (models.QbitSettings, error)
- func (s *ConfigStore) GetQbitSettings() (models.QbitSettings, error)
- func (s *ConfigStore) GetSiteConf(name models.SiteGroup) (models.SiteConfig, error)
- func (s *ConfigStore) ListBackups() ([]backup.Info, string, error)
- func (s *ConfigStore) ListRSSForSite(siteName string) ([]models.RSSConfig, error)
- func (s *ConfigStore) ListSites() (map[models.SiteGroup]models.SiteConfig, error)
- func (s *ConfigStore) Load() (*models.Config, error)
- func (s *ConfigStore) LoadSiteProxyPolicy() error
- func (s *ConfigStore) RecordBackupResult(reason backup.Reason, name string, runErr error, at time.Time) error
- func (s *ConfigStore) RecordRestoreResult(name, dir string, restoreErr error, at time.Time) error
- func (s *ConfigStore) ReplaceSiteRSS(siteID uint, rss []models.RSSConfig) error
- func (s *ConfigStore) RunBackup(ctx context.Context, reason backup.Reason) (backup.Info, error)
- func (s *ConfigStore) SaveAttendanceAI(enabled bool, visionModel string) error
- func (s *ConfigStore) SaveAttendanceNotify(enabled bool, channelIDs []uint) error
- func (s *ConfigStore) SaveAttendanceWindow(start, end string) error
- func (s *ConfigStore) SaveBackupSettings(in BackupSettingsInput) (BackupSettings, error)
- func (s *ConfigStore) SaveCloakConfig(endpoint, plaintextToken string, clearToken bool, profileID *string) error
- func (s *ConfigStore) SaveDailyReportSettings(in DailyReportSettings) error
- func (s *ConfigStore) SaveDeadTorrentScanSettings(in DeadTorrentScanSettings) error
- func (s *ConfigStore) SaveGlobal(gl models.SettingsGlobal) error
- func (s *ConfigStore) SaveGlobalSettings(gs models.SettingsGlobal) error
- func (s *ConfigStore) SaveGlobalSettingsWithPatch(gs models.SettingsGlobal, patch *GlobalSettingsPatch) error
- func (s *ConfigStore) SaveQbit(qb models.QbitSettings) error
- func (s *ConfigStore) SaveQbitSettings(q models.QbitSettings) error
- func (s *ConfigStore) SaveRenewedSiteCookie(site string, chain []string, renewed string) (bool, error)
- func (s *ConfigStore) SaveSiteCredentials(site models.SiteGroup, cookie, apiKey, passkey *string) error
- func (s *ConfigStore) SaveSiteProxy(in SiteProxyInput) (SiteProxySettings, error)
- func (s *ConfigStore) SetAutoStart(enabled bool) error
- func (s *ConfigStore) SetCloakEndpoint(endpoint string) error
- func (s *ConfigStore) SetCloakToken(plaintext string) error
- func (s *ConfigStore) SetSiteAttendanceEnabled(siteName string, enabled bool) error
- func (s *ConfigStore) SetSiteCookies(ctx context.Context, cookies map[models.SiteGroup]string) (map[models.SiteGroup]error, error)
- func (s *ConfigStore) SetSiteEnabled(site models.SiteGroup, enabled bool) error
- func (s *ConfigStore) SiteCookiePlaintext(site models.SiteSetting) (string, error)
- func (s *ConfigStore) SiteProxy() (SiteProxySettings, error)
- func (s *ConfigStore) StageRestoreBackup(name string) (backup.Pending, error)
- func (s *ConfigStore) SyncSites(registeredSites []models.RegisteredSite) error
- func (s *ConfigStore) UpdateAdmin(u *models.AdminUser) error
- func (s *ConfigStore) UpdateAdminPassword(username, newHash string) error
- func (s *ConfigStore) UpdateRSSInSite(siteName string, entry models.RSSConfig) (models.RSSConfig, error)
- func (s *ConfigStore) UpdateSiteOptions(site models.SiteGroup, o SiteOptions) error
- func (s *ConfigStore) UpsertSite(site models.SiteGroup, sc models.SiteConfig) (uint, error)
- func (s *ConfigStore) UpsertSiteWithRSS(site models.SiteGroup, sc models.SiteConfig) error
- type DailyReportSettings
- type DeadTorrentScanSettings
- type GlobalSettingsPatch
- type RestoreResult
- type SiteOptions
- type SiteProxyInput
- type SiteProxySettings
- type TB
- type V2BroadcastResult
- type V2Broadcaster
- type V2BroadcasterFunc
Constants ¶
const ( DefaultAttendanceWindowStart = "08:00" DefaultAttendanceWindowEnd = "10:00" )
每日签到时间窗的默认值(进程时区)。
const ( DailyReportScopePreviousDay = "previous_day" DailyReportScopeToday = "today" )
每日战报的统计范围。当天的数据要到 23:59 才完整,所以默认发前一天的。
const DefaultDailyReportTime = "22:00"
DefaultDailyReportTime 是战报默认的发送时刻。
const DefaultDeadTorrentScanIntervalH = 24
DefaultDeadTorrentScanIntervalH 是默认的扫描间隔。
const V2BroadcastFreshnessWindow = 5 * time.Minute
V2BroadcastFreshnessWindow guards against re-broadcasting on stale rows. If MigrationState.CompletedAt is older than this window, the broadcast is suppressed even when BroadcastSent=false (e.g. the row was migrated from a previous v2 release line that did not yet implement the sentinel flag).
const V2BroadcastSchemaVersion = 10
V2BroadcastSchemaVersion is the schema version that triggers the v2 upgrade broadcast. Centralized here so tests reference the same constant.
Variables ¶
var ( // ErrSecretKeyUnusable 表示 secret.key 存在却无法使用(读不出或格式不对)。 ErrSecretKeyUnusable = errors.New("secret.key 无法使用") // ErrSecretKeyRegenerated 表示 secret.key 是本次新生成的,但数据库里已有用原密钥加密的数据。 ErrSecretKeyRegenerated = errors.New("secret.key 是新生成的,数据库里却已有加密数据") )
var ErrBackupSettingsInvalid = errors.New("备份设置有误")
ErrBackupSettingsInvalid 是备份设置不对;错误文本里有给人看的原因。
var ErrDailyReportNoChannel = errors.New("开启每日战报至少要选一个通知通道")
ErrDailyReportNoChannel 表示开启了战报却没有选通道。
var ErrDailyReportScope = errors.New("统计范围应为 previous_day(前一天)或 today(当天截至发送时刻)")
ErrDailyReportScope 表示统计范围不认识。
var ErrDeadTorrentScanInvalid = errors.New("失效种子扫描设置有误")
ErrDeadTorrentScanInvalid 标记用户输入有误(与存储故障区分)。
var ErrDeadTorrentScanNoChannel = errors.New("开启失效种子定时扫描至少要选一个通知通道")
ErrDeadTorrentScanNoChannel 表示开启了定时扫描却没有选通道。
var ErrKeyMissing = errors.New("AES secret key missing or corrupt")
var ErrNoBroadcaster = errors.New("v2 broadcaster not configured")
ErrNoBroadcaster is returned by tests that intentionally exercise the "broadcaster missing" branch.
var ErrSiteProxyInvalid = errors.New("站点代理设置有误")
ErrSiteProxyInvalid 是站点代理设置不对(地址、模式或站点);错误文本里有给人看的原因,不带代理地址。
Functions ¶
func ActiveBackupKey ¶
ActiveBackupKey 是校验恢复时「当前生效的密钥」:环境变量 PT_TOOLS_SECRET_KEY 设了就是它,否则是现在的 secret.key。
func BackupDataDir ¶
BackupDataDir 是命令行 pt-tools db backup:不走 InitRuntime(服务在运行时也能用,不迁移数据库), 只读打开数据目录里的数据库做一份备份(原因 cli)。output 为空时放进备份设置里的目录; includeSecret 为 nil 时按备份设置决定带不带密钥。
func EnablePendingRestore ¶
func EnablePendingRestore()
EnablePendingRestore 让这个进程在 InitRuntime 里换上待恢复的备份(Web 服务启动时调用)。
func InitRuntime ¶ added in v0.1.0
取消 viper 文件读取,统一改为 DB 初始化与迁移(保留 once 初始化) InitViper 改造为:初始化日志、数据库,然后优先从 DB 加载全局配置;若 DB 为空且提供了文件,则允许后续迁移命令将文件写入 DB
func MissingCredential ¶
MissingCredential 按认证方式返回站点还缺的那项凭据:cookie、api_key 或 passkey;齐了返回空串。 cookie_and_api_key 只要 API Key:Cookie 可选(HDDolby 搜索、用户数据与带 downhash 的下载走 API,时魔、签到与只知道种子编号的下载用 Cookie)。
func NewTempDBDir ¶ added in v0.1.0
NewTempDBDir creates a temporary sqlite db under the given directory and migrates schema. 测试库不像正式库那样只开一个连接:几个连接同时写时等锁(最多 10 秒),事务和正式库一样一开始就拿写锁 (先读后写的事务不会因为升级写锁撞上别的连接而立刻报 database is locked)。 测试不需要掉电保护:日志放内存、不 fsync。Windows 上每次建表都落盘、刷盘,整套测试慢好几倍。
func NormalizeDailyReportScope ¶
NormalizeDailyReportScope 把统计范围规范化:today 以外(包括空值、不认识的旧值)都按前一天。
func OpenTestDB ¶
OpenTestDB 在 t.TempDir() 下建临时库,测试结束时关掉。Windows 上打开着的文件删不掉, 不关的话 t.TempDir() 的清理会失败,测试被判为 FAIL。
func OpenTestDBIn ¶
OpenTestDBIn 在 dir 下建临时库(dir 一般也是 t.TempDir()),测试结束时关掉。
func PendingRestore ¶
PendingRestore 读已经放好、下次启动生效的恢复;没有时返回 nil。
func SetV2Broadcaster ¶ added in v0.35.0
func SetV2Broadcaster(b V2Broadcaster)
SetV2Broadcaster registers the broadcaster used by InitRuntime. Production wiring (e.g. cmd/web.go) installs a concrete implementation after the notify.Router is constructed; if no broadcaster is registered, InitRuntime skips the dispatch step silently.
func StageRestore ¶
StageRestore 校验 src 这份备份(name 是给人看的名字),通过后放进待恢复,下次启动时生效。
func ValidateAttendanceWindow ¶
ValidateAttendanceWindow 校验签到时间窗:HH:MM,开始早于结束,不跨午夜。
func ValidateDailyReportTime ¶
ValidateDailyReportTime 校验 HH:MM。
func ValidateVisionModel ¶
ValidateVisionModel 校验识别验证码用的模型名:可以为空(用 AI 助手的模型),不能有空白,不超过 128 字。
Types ¶
type BackupResult ¶
type BackupResult struct {
At time.Time
Reason backup.Reason
Name string
Error string
// LastOKAt 是最近一次成功备份的时间(不一定是这一次)
LastOKAt *time.Time
}
BackupResult 是一次备份的结果:Error 为空表示成功。
type BackupSettings ¶
type BackupSettings struct {
Enabled bool
// Time 是每天定时备份的时刻(HH:MM)
Time string
// Keep 是定时备份保留几份
Keep int
// Dir 是用户填的备份目录,空串表示默认目录
Dir string
// DefaultDir 是默认目录(<数据目录>/backups)
DefaultDir string
IncludeSecret bool
// ScheduledDay 是最近一次做过定时备份(不论成败)的日期
ScheduledDay string
// Last 是最近一次备份的结果,没做过时为 nil
Last *BackupResult
// Restore 是最近一次启动时恢复的结果,没恢复过时为 nil
Restore *RestoreResult
}
BackupSettings 是备份设置与最近一次备份、恢复的结果。
type BackupSettingsInput ¶
BackupSettingsInput 是保存备份设置的参数。
type CloakConfigSnapshot ¶ added in v0.35.0
CloakConfigSnapshot is the in-memory view of CloakBrowser-Manager接入配置。 仅在 ConfigStore 内部及调用方使用;HTTP 层通过 web.api_cloak.go 暴露的响应类型 控制对外字段,token 永远不会以明文出现在 API 响应里。
type ConfigStore ¶ added in v0.1.0
type ConfigStore struct {
// contains filtered or unexported fields
}
func NewConfigStore ¶ added in v0.1.0
func NewConfigStore(db *models.TorrentDB) *ConfigStore
func (*ConfigStore) AdminCount ¶ added in v0.1.0
func (s *ConfigStore) AdminCount() (int64, error)
func (*ConfigStore) AppendRSSToSite ¶ added in v0.35.0
func (*ConfigStore) AttendanceAI ¶
func (s *ConfigStore) AttendanceAI() (bool, string, error)
AttendanceAI 返回 AI 签到的开关和识别验证码用的模型;还没有全局设置时是关闭。
func (*ConfigStore) AttendanceNotify ¶
func (s *ConfigStore) AttendanceNotify() (bool, []uint, error)
AttendanceNotify 返回签到结果推送:开没开、推到哪些通道(空表示所有启用的通道)。还没有全局设置时是开、所有通道。
func (*ConfigStore) AttendanceWindow ¶
func (s *ConfigStore) AttendanceWindow() (string, string, error)
AttendanceWindow 返回签到时间窗;还没有全局设置或存的值不合法时返回默认的 08:00–10:00。
func (*ConfigStore) BackupFile ¶
func (s *ConfigStore) BackupFile(name string) (string, error)
BackupFile 是备份目录里一份备份的路径(下载用);只认这里起的文件名。
func (*ConfigStore) BackupSettings ¶
func (s *ConfigStore) BackupSettings() (BackupSettings, error)
BackupSettings 读备份设置;没有这一行时返回默认值(开着、04:30、7 份、默认目录、带上密钥)。
func (*ConfigStore) DailyReportOffset ¶
DailyReportOffset 返回本安装固定的发送偏移(1–600 秒)。还没分配时用 randN(返回 [0, n))分配一个并保存; 全局设置行还不存在时返回 0,不分配。
func (*ConfigStore) DailyReportSettings ¶
func (s *ConfigStore) DailyReportSettings() (DailyReportSettings, error)
DailyReportSettings 读出战报配置;全局设置行还不存在时返回默认值(关闭、22:00、无通道、前一天)。
func (*ConfigStore) DeadTorrentScanSettings ¶
func (s *ConfigStore) DeadTorrentScanSettings() (DeadTorrentScanSettings, error)
DeadTorrentScanSettings 读出定时扫描配置;全局设置行还不存在时返回默认值(关闭、24 小时、无通道)。
func (*ConfigStore) DecryptCookie ¶ added in v0.35.0
func (s *ConfigStore) DecryptCookie(cipherText string) (string, error)
func (*ConfigStore) DeleteBackup ¶
func (s *ConfigStore) DeleteBackup(name string) error
DeleteBackup 删掉备份目录里的一份备份。
func (*ConfigStore) DeleteRSSFromSite ¶ added in v0.35.0
DeleteRSSFromSite 原子删除指定站点下的单条 RSS 订阅,并清理其过滤规则关联。
func (*ConfigStore) DeleteSite ¶ added in v0.1.0
func (s *ConfigStore) DeleteSite(name string) error
DeleteSite 删除站点(预置站点禁止删除)。
判定看的是这一行的 IsBuiltin —— SyncSites 会把站点定义注册表里的每个站点都标上它 (models/presets.go),所以这一条覆盖全部内置站点。原来只硬编码了三个名字 (springsunday / hdsky / mteam),别的内置站点从任何入口调进来都会被真删掉, 连带它的 RSS 订阅一起没。前端各页的 is_builtin 拦截只是提示,服务端必须自己挡住。
func (*ConfigStore) EnabledRSS ¶
func (s *ConfigStore) EnabledRSS() ([]models.RSSConfig, error)
EnabledRSS 返回已启用站点下的全部 RSS 订阅(含示例订阅,由调用方按 ShouldSkip 剔除)。 只读站点的 id、enabled 与订阅表,不经过 Load:不解密 Cookie,密钥缺失时 RSS 任务的状态查询照样能用。
func (*ConfigStore) EnabledSiteNames ¶
func (s *ConfigStore) EnabledSiteNames() (map[string]bool, error)
ReloadGlobal 从 DB 加载并刷新全局配置与目录缓存 已弃用:由各业务按需读取 DB 并更新目录缓存 ListSites 从 DB 读取站点与 RSS 配置(不依赖 global.GlobalCfg) EnabledSiteNames 返回已启用站点名(小写)的集合。用户数据的增量、走势与每日战报只算这些站点, 与 /api/v2/userinfo/aggregated 口径一致。只读 name 与 enabled 两列:不经过 ListSites, 密钥缺失或 Cookie 解不开时照样能用。
func (*ConfigStore) EncryptCookie ¶ added in v0.35.0
func (s *ConfigStore) EncryptCookie(plain string) (string, error)
func (*ConfigStore) EnsureAdmin ¶ added in v0.1.0
func (s *ConfigStore) EnsureAdmin(username, passwordHash string) error
func (*ConfigStore) GetAdmin ¶ added in v0.1.0
func (s *ConfigStore) GetAdmin(username string) (*models.AdminUser, error)
func (*ConfigStore) GetCloakConfig ¶ added in v0.35.0
func (s *ConfigStore) GetCloakConfig() (CloakConfigSnapshot, error)
GetCloakConfig 返回 endpoint + 是否已设置 token。永远不返回 token 明文。
func (*ConfigStore) GetCloakEndpoint ¶ added in v0.35.0
func (s *ConfigStore) GetCloakEndpoint() (string, error)
GetCloakEndpoint 返回当前持久化的 endpoint,记录不存在时返回空字符串。
func (*ConfigStore) GetCloakToken ¶ added in v0.35.0
func (s *ConfigStore) GetCloakToken() (string, error)
GetCloakToken 解密并返回 token 明文。 仅 test-connection / driver 内部调用,绝不能写到任何 HTTP 响应或日志。
func (*ConfigStore) GetGlobalOnly ¶ added in v0.1.0
func (s *ConfigStore) GetGlobalOnly() (models.SettingsGlobal, error)
func (*ConfigStore) GetGlobalSettings ¶ added in v0.1.0
func (s *ConfigStore) GetGlobalSettings() (models.SettingsGlobal, error)
Unified API structures: use models.SettingsGlobal for external I/O
func (*ConfigStore) GetQbitOnly ¶ added in v0.1.0
func (s *ConfigStore) GetQbitOnly() (models.QbitSettings, error)
func (*ConfigStore) GetQbitSettings ¶ added in v0.1.0
func (s *ConfigStore) GetQbitSettings() (models.QbitSettings, error)
func (*ConfigStore) GetSiteConf ¶ added in v0.1.0
func (s *ConfigStore) GetSiteConf(name models.SiteGroup) (models.SiteConfig, error)
func (*ConfigStore) ListBackups ¶
func (s *ConfigStore) ListBackups() ([]backup.Info, string, error)
ListBackups 列出备份目录里的备份(最新的在前)与这个目录。
func (*ConfigStore) ListRSSForSite ¶ added in v0.35.0
func (s *ConfigStore) ListRSSForSite(siteName string) ([]models.RSSConfig, error)
ListRSSForSite 返回指定站点的所有 RSS 订阅。
func (*ConfigStore) ListSites ¶ added in v0.1.0
func (s *ConfigStore) ListSites() (map[models.SiteGroup]models.SiteConfig, error)
func (*ConfigStore) Load ¶ added in v0.1.0
func (s *ConfigStore) Load() (*models.Config, error)
Load 将 SQLite 中的配置组装为运行时 Config
func (*ConfigStore) LoadSiteProxyPolicy ¶
func (s *ConfigStore) LoadSiteProxyPolicy() error
LoadSiteProxyPolicy 读站点代理设置并换上判定快照(启动时调)。读不出、或者开着却解不开代理地址时, 按关闭处理(站点请求照旧按环境变量)并返回错误,由调用方记日志;错误里没有代理地址。
func (*ConfigStore) RecordBackupResult ¶
func (s *ConfigStore) RecordBackupResult(reason backup.Reason, name string, runErr error, at time.Time) error
RecordBackupResult 记下一次备份的结果(失败时 err 非空)。定时备份同时记下做过的日期,同一天不再做。
func (*ConfigStore) RecordRestoreResult ¶
RecordRestoreResult 记下一次启动时恢复的结果:换上了时 dir 是换下来的原文件放在哪,没换上时 dir 不记。
func (*ConfigStore) ReplaceSiteRSS ¶ added in v0.1.0
func (s *ConfigStore) ReplaceSiteRSS(siteID uint, rss []models.RSSConfig) error
func (*ConfigStore) SaveAttendanceAI ¶
func (s *ConfigStore) SaveAttendanceAI(enabled bool, visionModel string) error
SaveAttendanceAI 保存 AI 签到的开关与识别验证码用的模型,只写这两列。
func (*ConfigStore) SaveAttendanceNotify ¶
func (s *ConfigStore) SaveAttendanceNotify(enabled bool, channelIDs []uint) error
SaveAttendanceNotify 保存签到结果推送,只写这两列。选了通道时通道都要存在;不选表示所有启用的通道。
func (*ConfigStore) SaveAttendanceWindow ¶
func (s *ConfigStore) SaveAttendanceWindow(start, end string) error
SaveAttendanceWindow 保存签到时间窗,只写这两列。全局设置行要先存在(首次启动时保存全局设置建行)。
func (*ConfigStore) SaveBackupSettings ¶
func (s *ConfigStore) SaveBackupSettings(in BackupSettingsInput) (BackupSettings, error)
SaveBackupSettings 校验并保存备份设置,只改设置这几列,不动最近一次备份与恢复的结果。 目录要是绝对路径;不存在时建出来,并试着写一个文件确认能写。
func (*ConfigStore) SaveCloakConfig ¶ added in v0.35.0
func (s *ConfigStore) SaveCloakConfig(endpoint, plaintextToken string, clearToken bool, profileID *string) error
SaveCloakConfig 在单次事务里同时更新 endpoint + token + profile ID; emptyToken=true 时显式清空 token,否则 plaintextToken=="" 表示保持不变(部分更新)。 profileID 为 nil 表示保持不变,指向空串表示清除。
func (*ConfigStore) SaveDailyReportSettings ¶
func (s *ConfigStore) SaveDailyReportSettings(in DailyReportSettings) error
SaveDailyReportSettings 保存战报配置,只写战报这几列。开启时必须选了通道,且通道都存在;统计范围空值按前一天。
func (*ConfigStore) SaveDeadTorrentScanSettings ¶
func (s *ConfigStore) SaveDeadTorrentScanSettings(in DeadTorrentScanSettings) error
SaveDeadTorrentScanSettings 保存定时扫描配置,只写这三列。开启时必须选了通道,且通道都存在。
func (*ConfigStore) SaveGlobal ¶ added in v0.1.0
func (s *ConfigStore) SaveGlobal(gl models.SettingsGlobal) error
func (*ConfigStore) SaveGlobalSettings ¶ added in v0.1.0
func (s *ConfigStore) SaveGlobalSettings(gs models.SettingsGlobal) error
func (*ConfigStore) SaveGlobalSettingsWithPatch ¶ added in v0.42.1
func (s *ConfigStore) SaveGlobalSettingsWithPatch(gs models.SettingsGlobal, patch *GlobalSettingsPatch) error
SaveGlobalSettingsWithPatch 在 SaveGlobalSettings 基础上增加部分更新通道。
- patch == nil:与旧 SaveGlobalSettings 完全一致(4 字段从 gs 全量赋值),保持所有既有调用方语义。
- patch != nil:DefaultEnabled/RetainHours/MaxRetry/DefaultConcurrency 仅在对应指针非 nil 时写入, nil 时保留 DB 现值(更新分支)或落合理默认(INSERT 分支)。
func (*ConfigStore) SaveQbit ¶ added in v0.1.0
func (s *ConfigStore) SaveQbit(qb models.QbitSettings) error
func (*ConfigStore) SaveQbitSettings ¶ added in v0.1.0
func (s *ConfigStore) SaveQbitSettings(q models.QbitSettings) error
func (*ConfigStore) SaveRenewedSiteCookie ¶
func (s *ConfigStore) SaveRenewedSiteCookie(site string, chain []string, renewed string) (bool, error)
SaveRenewedSiteCookie 存站点续期换发的 Cookie(BYR,见 site/v2 的 SessionCookies):chain 是这个会话用过的那些 Cookie, 站点设置里存着的是其中一个时换成 renewed;已经是别的(扩展推来了新的、用户改了、验证时的候选会话)就不动、返回 false。 只写 Cookie 密文、不发 ConfigChanged:在用的站点实例已经换上新值,不用重建实例、重载调度;重启以后从这里接着用。
func (*ConfigStore) SaveSiteCredentials ¶
func (s *ConfigStore) SaveSiteCredentials(site models.SiteGroup, cookie, apiKey, passkey *string) error
SaveSiteCredentials 只写传进来的凭据列(Cookie 加密后存),不改启用状态、地址和 RSS。 给凭据还没配齐、站点暂时不能启用的情况用:比如 HDDolby 要 API Key,扩展先同步来了 Cookie。
func (*ConfigStore) SaveSiteProxy ¶
func (s *ConfigStore) SaveSiteProxy(in SiteProxyInput) (SiteProxySettings, error)
SaveSiteProxy 校验并保存站点代理设置,成功以后换上新的判定快照。站点 ID 认不认识由调用方先查(它有站点注册表)。
func (*ConfigStore) SetAutoStart ¶
func (s *ConfigStore) SetAutoStart(enabled bool) error
SetAutoStart 只改全局设置里的「自动启动 RSS 任务」,其余设置不动;值没变时什么也不做。 改了就发布配置变更,和在全局设置页保存一样:RSS 任务没在运行、也没被手动停止时,打开它会马上按配置启动。
func (*ConfigStore) SetCloakEndpoint ¶ added in v0.35.0
func (s *ConfigStore) SetCloakEndpoint(endpoint string) error
SetCloakEndpoint 仅更新 endpoint 字段,不影响已存 token。
func (*ConfigStore) SetCloakToken ¶ added in v0.35.0
func (s *ConfigStore) SetCloakToken(plaintext string) error
SetCloakToken 加密后落库;空字符串表示清除 token。
func (*ConfigStore) SetSiteAttendanceEnabled ¶
func (s *ConfigStore) SetSiteAttendanceEnabled(siteName string, enabled bool) error
SetSiteAttendanceEnabled 打开或关闭站点的每日自动签到,只写这一列,不影响站点的其他配置。
func (*ConfigStore) SetSiteCookies ¶
func (s *ConfigStore) SetSiteCookies(ctx context.Context, cookies map[models.SiteGroup]string) (map[models.SiteGroup]error, error)
GetSiteConf 获取指定站点配置 SetSiteCookies 批量把 Cookie 写进站点并启用(CookieCloud 导入用),只改 Cookie 与启用两列,不动 RSS 等其他设置。 站点必须已经存在、用 Cookie 登录;同时要 API Key 的站点必须已经填了 API Key。在一个事务里写完,写进去了就只发布一次配置变更。 返回写不进去的站点和原因;数据库出错时返回错误,一个都不写。
func (*ConfigStore) SetSiteEnabled ¶
func (s *ConfigStore) SetSiteEnabled(site models.SiteGroup, enabled bool) error
SetSiteEnabled 只改站点的启用开关,认证方式、凭证、地址、限速和 RSS 都不动。
func (*ConfigStore) SiteCookiePlaintext ¶
func (s *ConfigStore) SiteCookiePlaintext(site models.SiteSetting) (string, error)
SiteCookiePlaintext 按 ListSites 的同一规则取站点 Cookie 明文:有密文时解密,否则用旧版明文列。 只给可信边界(CloakBrowser 后备注入浏览器)用,不要写进响应或日志。
func (*ConfigStore) SiteProxy ¶
func (s *ConfigStore) SiteProxy() (SiteProxySettings, error)
SiteProxy 读站点代理设置;没有这一行时返回默认值(关闭、全部站点、没有选站点)。
func (*ConfigStore) StageRestoreBackup ¶
func (s *ConfigStore) StageRestoreBackup(name string) (backup.Pending, error)
StageRestoreBackup 把备份目录里的一份备份放进待恢复。
func (*ConfigStore) SyncSites ¶ added in v0.2.0
func (s *ConfigStore) SyncSites(registeredSites []models.RegisteredSite) error
SyncSites 从注册的站点列表同步到数据库 应在应用启动时调用,确保内存中注册的站点都存在于数据库中
func (*ConfigStore) UpdateAdmin ¶ added in v0.1.0
func (s *ConfigStore) UpdateAdmin(u *models.AdminUser) error
func (*ConfigStore) UpdateAdminPassword ¶ added in v0.1.0
func (s *ConfigStore) UpdateAdminPassword(username, newHash string) error
func (*ConfigStore) UpdateRSSInSite ¶
func (s *ConfigStore) UpdateRSSInSite(siteName string, entry models.RSSConfig) (models.RSSConfig, error)
UpdateRSSInSite 原地改站点下的一条 RSS 订阅(编号不变),按 AppendRSSToSite 的规则校验:名字与地址不能为空, 地址不能与同站点的其他订阅重复,指定的下载器与过滤规则要存在;过滤规则的关联换成 entry.FilterRuleIDs。 示例订阅的标记不变。
func (*ConfigStore) UpdateSiteOptions ¶
func (s *ConfigStore) UpdateSiteOptions(site models.SiteGroup, o SiteOptions) error
UpdateSiteOptions 只改给了的几项,不动认证方式、地址与 RSS(UpsertSiteWithRSS 要带上整份站点配置和全部 RSS)。 改完以后站点是启用的,就要求凭据按认证方式齐全(MissingCredential);站点定义标为不可用的不能启用。 配置网关(AI 与 App API 改配置)用它。
func (*ConfigStore) UpsertSite ¶ added in v0.1.0
func (s *ConfigStore) UpsertSite(site models.SiteGroup, sc models.SiteConfig) (uint, error)
UpsertSite 整体覆盖站点的认证信息:sc 里为空的认证方式、Cookie、API Key、地址和 Passkey 会清掉已存的值。 只想改启用开关时用 SetSiteEnabled。
func (*ConfigStore) UpsertSiteWithRSS ¶ added in v0.1.0
func (s *ConfigStore) UpsertSiteWithRSS(site models.SiteGroup, sc models.SiteConfig) error
UpsertSiteWithRSS 原子性保存站点与 RSS,并进行严格校验。 sc.RSS 是这个站点保存以后的全部 RSS:带着这个站点编号的原地更新(编号不变),编号为 0 或不是这个站点的新建, 库里有、sc.RSS 里没有的连同过滤规则关联一起删掉;同一个编号出现两次时报错,什么都不保存。
type DailyReportSettings ¶
type DailyReportSettings struct {
Enabled bool `json:"enabled"`
// Time 是每天发送的时刻(HH:MM,进程时区)。
Time string `json:"time"`
// ChannelIDs 是接收战报的通知通道。开启时至少一个:不沿用「空列表即全部通道」。
ChannelIDs []uint `json:"channel_ids"`
// Scope 是统计范围:DailyReportScopePreviousDay(前一天整天)或 DailyReportScopeToday(当天截至发送时刻)。
// 保存时空值按前一天。
Scope string `json:"scope"`
}
DailyReportSettings 是每日战报的配置。
type DeadTorrentScanSettings ¶
type DeadTorrentScanSettings struct {
Enabled bool `json:"enabled"`
// IntervalHours 是两次扫描的间隔(6–168 小时)。
IntervalHours int `json:"interval_hours"`
// ChannelIDs 是接收通知的通道;开启时至少一个。
ChannelIDs []uint `json:"channel_ids"`
}
DeadTorrentScanSettings 是下载器助手「失效种子」的定时扫描配置:只发通知,不删种。
type GlobalSettingsPatch ¶ added in v0.42.1
type GlobalSettingsPatch struct {
DefaultEnabled *bool
RetainHours *int
MaxRetry *int
DefaultConcurrency *int32
}
GlobalSettingsPatch 表达全局设置的“部分更新”语义(方式 ii)。 这些字段在 Web API 中通过指针区分“未提供”(nil → 保留 DB 现值)与 “显式提供(含 0)”(非 nil → 写入)。仅用于阻止 apiGlobal 漏传导致的静默清零, 不改变 SaveGlobalSettings 对其余字段的全量赋值语义。
type RestoreResult ¶
RestoreResult 是一次启动时恢复的结果:Error 为空表示换上了,换下来的原文件在 Dir。
type SiteOptions ¶
type SiteOptions struct {
Enabled *bool
UploadLimitKBs *int
DownloadLimitKBs *int
SeedingCapacityGB *float64
HRSeedTimeH *int
HRUploadRatio *float64
Cookie *string
APIKey *string
Passkey *string
}
SiteOptions 是站点能单独改的几项(nil 不改)。Cookie、APIKey、Passkey 给空串时清除。
type SiteProxyInput ¶
SiteProxyInput 是保存站点代理的参数。ProxyURL 与读到的(密码换成 *** 的)地址相同表示不改,空串表示清除。
type SiteProxySettings ¶
type SiteProxySettings struct {
Enabled bool
ProxyURL string
Mode string
// Sites 是选中的站点 ID(规范化后的小写 ID,排好序)
Sites []string
// ProxyUnreadable 是存着的代理地址解不开(加密密钥换过):当作没填,要重新填
ProxyUnreadable bool
// UpdatedAt 是上次保存的时间,没保存过时为 nil
UpdatedAt *time.Time
}
SiteProxySettings 是站点代理的设置。ProxyURL 是明文(可能带密码),只在进程里用;给界面看要先 httpclient.MaskProxyURL。
type TB ¶
type TB interface {
Helper()
TempDir() string
Cleanup(func())
}
TB 是测试里用到的几个方法(*testing.T、*testing.B 都有),这里不引用 testing 包。
type V2BroadcastResult ¶ added in v0.35.0
V2BroadcastResult describes the outcome of MaybeSendV2Broadcast.
func MaybeSendV2Broadcast ¶ added in v0.35.0
func MaybeSendV2Broadcast(ctx context.Context, db *gorm.DB, broadcaster V2Broadcaster, logger *zap.SugaredLogger, now time.Time) V2BroadcastResult
MaybeSendV2Broadcast inspects MigrationState for V2BroadcastSchemaVersion and dispatches the upgrade broadcast at most once. It is safe to call from every startup; subsequent calls become no-ops once BroadcastSent=true. The freshness window prevents broadcasts on databases whose v10 row was written long ago without the sentinel column.
Errors from the broadcaster are logged but never propagated upward — startup must not be blocked by a transient notification failure.
type V2Broadcaster ¶ added in v0.35.0
V2Broadcaster delivers the one-time "v2.0 升级完成" notification. Implementations typically wrap an internal/notify.Router but the interface is kept here to avoid a dependency cycle and to make tests trivial.
type V2BroadcasterFunc ¶ added in v0.35.0
V2BroadcasterFunc adapts a plain function into a V2Broadcaster.
func (V2BroadcasterFunc) BroadcastV2Upgrade ¶ added in v0.35.0
func (f V2BroadcasterFunc) BroadcastV2Upgrade(ctx context.Context) error
BroadcastV2Upgrade satisfies V2Broadcaster.