core

package
v0.40.0 Latest Latest
Warning

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

Go to latest
Published: Jun 28, 2026 License: MIT Imports: 25 Imported by: 0

Documentation

Index

Constants

View Source
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).

View Source
const V2BroadcastSchemaVersion = 10

V2BroadcastSchemaVersion is the schema version that triggers the v2 upgrade broadcast. Centralized here so tests reference the same constant.

Variables

View Source
var ErrKeyMissing = errors.New("AES secret key missing or corrupt")
View Source
var ErrNoBroadcaster = errors.New("v2 broadcaster not configured")

ErrNoBroadcaster is returned by tests that intentionally exercise the "broadcaster missing" branch.

Functions

func GetLogger

func GetLogger() *zap.Logger

func InitRuntime added in v0.1.0

func InitRuntime() (*zap.Logger, error)

取消 viper 文件读取,统一改为 DB 初始化与迁移(保留 once 初始化) InitViper 改造为:初始化日志、数据库,然后优先从 DB 加载全局配置;若 DB 为空且提供了文件,则允许后续迁移命令将文件写入 DB

func NewTempDBDir added in v0.1.0

func NewTempDBDir(dir string) (*models.TorrentDB, error)

NewTempDBDir creates a temporary sqlite db under the given directory and migrates schema

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.

Types

type CloakConfigSnapshot added in v0.35.0

type CloakConfigSnapshot struct {
	Endpoint string
	HasToken bool
}

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 (s *ConfigStore) AppendRSSToSite(siteName string, entry models.RSSConfig) (models.RSSConfig, error)

func (*ConfigStore) DecryptCookie added in v0.35.0

func (s *ConfigStore) DecryptCookie(cipherText string) (string, error)

func (*ConfigStore) DeleteRSSFromSite added in v0.35.0

func (s *ConfigStore) DeleteRSSFromSite(siteName string, rssID uint) (models.RSSConfig, error)

DeleteRSSFromSite 原子删除指定站点下的单条 RSS 订阅,并清理其过滤规则关联。

func (*ConfigStore) DeleteSite added in v0.1.0

func (s *ConfigStore) DeleteSite(name string) error

DeleteSite 删除站点(预置站点禁止删除)

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)

GetSiteConf 获取指定站点配置

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)

ReloadGlobal 从 DB 加载并刷新全局配置与目录缓存 已弃用:由各业务按需读取 DB 并更新目录缓存 ListSites 从 DB 读取站点与 RSS 配置(不依赖 global.GlobalCfg)

func (*ConfigStore) Load added in v0.1.0

func (s *ConfigStore) Load() (*models.Config, error)

Load 将 SQLite 中的配置组装为运行时 Config

func (*ConfigStore) ReplaceSiteRSS added in v0.1.0

func (s *ConfigStore) ReplaceSiteRSS(siteID uint, rss []models.RSSConfig) error

func (*ConfigStore) SaveCloakConfig added in v0.35.0

func (s *ConfigStore) SaveCloakConfig(endpoint, plaintextToken string, clearToken bool) error

SaveCloakConfig 在单次事务里同时更新 endpoint + token; emptyToken=true 时显式清空 token,否则 plaintextToken=="" 表示保持不变(部分更新)。

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) 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) 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) 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) UpsertSite added in v0.1.0

func (s *ConfigStore) UpsertSite(site models.SiteGroup, sc models.SiteConfig) (uint, error)

func (*ConfigStore) UpsertSiteWithRSS added in v0.1.0

func (s *ConfigStore) UpsertSiteWithRSS(site models.SiteGroup, sc models.SiteConfig) error

UpsertSiteWithRSS 原子性保存站点与 RSS,并进行严格校验

type V2BroadcastResult added in v0.35.0

type V2BroadcastResult struct {
	Sent     bool
	Reason   string
	BcastErr error
}

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

type V2Broadcaster interface {
	BroadcastV2Upgrade(ctx context.Context) error
}

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

type V2BroadcasterFunc func(ctx context.Context) error

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.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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